Envelopes for RSI

Author: Copyright 2018, Tor
Indicators Used
Relative strength indexEnvelopes indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
Envelopes for RSI
ÿþ//+------------------------------------------------------------------+

//|                                            Envelopes for RSI.mq4 |

//|                                              Copyright 2018, Tor |

//|                          https://www.mql5.com/ru/users/tormovies |

//+------------------------------------------------------------------+

#property copyright "Copyright 2018, Tor"

#property link      "https://www.mql5.com/ru/users/tormovies"

#property version   "1.0"

#property description "This indicator is based on standard indicator Relative Strength Index"

#property description "and draws a Envelopes channel for him"

#property strict

#property indicator_separate_window

#property indicator_buffers 5

#property indicator_plots   5

#property indicator_minimum 0

#property indicator_maximum 100



input string t1="--- Input RSI parameters ---";

input int RSIPeriod = 14; // RSI Period

input int MaxLevel = 70;  // Max signal level

input int MinLevel = 30;  // Min signal level

input color rsicolor=clrDodgerBlue;// RSI color

input int rsiwidth=1;   // RSI width



input string t2="--- Input Envelopes parameters ---";

input int EnvPeriod=80; // Envelopes Period

input ENUM_MA_METHOD EnvMethod=MODE_EMA;//Envelopes method

input double EnvDeviation= 35;// Envelopes Deviation

input color Envcolor=clrGreen;// Envelopes Color

input int EnvWidth=1;// Envelopes Width

input ENUM_LINE_STYLE EnvStyle=STYLE_DOT;// Envelopes line style



input string t3="--- Other parameters ---";

input int alertShift=1; // Candle which look for the signal (0 = current candle)

input bool showLine=false; // Show vertical lines

input bool showArrows=true; // Show arrows



double RSIx[],bbup[],bbdn[],buy[],sell[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   IndicatorShortName("Env for RSI");

   SetIndexBuffer(0,RSIx);

   SetIndexBuffer(1,bbup);

   SetIndexBuffer(2,bbdn);

   SetIndexBuffer(3,buy);

   SetIndexBuffer(4,sell);

   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,rsiwidth,rsicolor);

   SetIndexStyle(1,DRAW_LINE,EnvStyle,EnvWidth,Envcolor);

   SetIndexStyle(2,DRAW_LINE,EnvStyle,EnvWidth,Envcolor);

   SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,1,clrBlue);

   SetIndexStyle(4,DRAW_ARROW,STYLE_SOLID,1,clrRed);

   SetIndexArrow(3,233);

   SetIndexArrow(4,234);

   SetIndexLabel(0,"RSI");

   SetIndexLabel(1,"Envelopes Up");

   SetIndexLabel(2,"Envelopes Down");

   SetLevelValue(1,MinLevel);

   SetLevelValue(2,MaxLevel);

   SetLevelValue(3,50);



//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

int deinit()

  {

   del("Envfrs_");

   return(0);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---



   int limit; int xxx=0;

   static datetime altime=0;

//---

   if(rates_total<=1)

      return(0);

//--- last counted bar will be recounted

   limit=rates_total-prev_calculated;

   if(prev_calculated>0)

      limit=limit+2;



   for(int x=limit-2; x>=0; x--)

     {

      RSIx[x]=iRSI(Symbol(),0,RSIPeriod,PRICE_CLOSE,x);

     }

   for(int x2=limit-2; x2>=0; x2--)

     {

      bbup[x2]=iEnvelopesOnArray(RSIx,0,EnvPeriod,EnvMethod,0,EnvDeviation,MODE_UPPER,x2);

      bbdn[x2]=iEnvelopesOnArray(RSIx,0,EnvPeriod,EnvMethod,0,EnvDeviation,MODE_LOWER,x2);

     }

   for(int x3=limit-2; x3>=0; x3--)

     {

      if(RSIx[x3+alertShift]<bbup[x3+alertShift] && RSIx[x3+alertShift+1]>bbup[x3+alertShift+1])

        {

         if(showArrows){ sell[x3]=RSIx[x3]; }

         if(showLine){ Lines(x3,"Sell",clrRed); }

        }

      if(RSIx[x3+alertShift]>bbdn[x3+alertShift] && RSIx[x3+alertShift+1]<bbdn[x3+alertShift+1])

        {

         if(showArrows){ buy[x3]=RSIx[x3]; }

         if(showLine){ Lines(x3,"Buy",clrBlue); }

        }

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

void Lines(int shift,string txt,color clr=clrRed)

  {

   datetime time=iTime(Symbol(),0,shift);

   ObjectCreate(0,"Envfrs_"+txt+"_"+(string)time,OBJ_VLINE,0,time,0);

   ObjectSetInteger(0,"Envfrs_"+txt+"_"+(string)time,OBJPROP_COLOR,clr);

   ObjectSetInteger(0,"Envfrs_"+txt+"_"+(string)time,OBJPROP_STYLE,STYLE_DOT);

   ObjectSetString(0,"Envfrs_"+txt+"_"+(string)time,OBJPROP_TOOLTIP,txt);

   ObjectSetInteger(0,"Envfrs_"+txt+"_"+(string)time,OBJPROP_BACK,true);

   return;

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int del(string name)

  {

   for(int n=ObjectsTotal()-1; n>=0; n--)

     {

      string Obj_Name=ObjectName(n);

      if(StringFind(Obj_Name,name,0)!=-1)

        {

         ObjectDelete(Obj_Name);

        }

     }

   return 0;

  }

//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---