verification_rsi

Author: Copyright 2020, Dmitriy Kudryashov.
Indicators Used
Relative strength index
0 Views
0 Downloads
0 Favorites
verification_rsi
ÿþ//+------------------------------------------------------------------+

//|                                             verification_rsi.mq4 |

//|                              Copyright 2020, Dmitriy Kudryashov. |

//|                       https://www.mql5.com/ru/users/dlim0n4ik.dk |

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

#property copyright "Copyright 2020, Dmitriy Kudryashov."

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

#property version   "200.225"

#property strict        //#:070=85 :><?8;OB>@C =0 ?@8<5=5=85 >A>1>3> AB@>3>3> @568<0 ?@>25@:8 >H81>:

#property indicator_separate_window

#property indicator_minimum 0

#property indicator_maximum 100

#property indicator_buffers 8

#property indicator_plots   8

#define   chart_ID   0  // ID 3@0D8:0

//#define BAR_CHAR 110

//---

#define  NAME_PROGRAM   "Verification RSI"             // <O ?@>3@0<<K

#define  YEAR_CREATE    2020                    // >4 A>740=85 ?5@2>9 @01>G59 25@A88 ?@>3@0<<K

#define  NAME_COMPANY   "Dmitriy Kudryashov."   // <O :><?0=88 (02B>@0)

//---

bool     debug_mode   = false;                  //  568< >B;04:8.  6C@=0;5 ?@8 B5AB8@>20=88 2K2>4OBAO A>>1I5=8O 87 @07=KE DC=:F89.

bool     demo_version = false;                  // 0==0O 25@A8O ?@>3@0<<K O2;O5BAO 45<>=AB@0B82=>9?

//--- plot main_line

#property indicator_label1  "main_line"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrDodgerBlue

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot overbought_line_3

#property indicator_label2  "overbought_line_3"

#property indicator_type2   DRAW_LINE

#property indicator_color2  clrRed

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- plot overbought_line_2

#property indicator_label3  "overbought_line_2"

#property indicator_type3   DRAW_LINE

#property indicator_color3  clrRed

#property indicator_style3  STYLE_DASH

#property indicator_width3  1

//--- plot overbought_line_1

#property indicator_label4  "overbought_line_1"

#property indicator_type4   DRAW_LINE

#property indicator_color4  clrRed

#property indicator_style4  STYLE_DOT

#property indicator_width4  1

//--- plot threshold_line

#property indicator_label5  "threshold_line"

#property indicator_type5   DRAW_LINE

#property indicator_color5  clrDarkOrange

#property indicator_style5  STYLE_SOLID

#property indicator_width5  1

//--- plot oversold_line_1

#property indicator_label6  "oversold_line_1"

#property indicator_type6   DRAW_LINE

#property indicator_color6  clrGreen

#property indicator_style6  STYLE_DOT

#property indicator_width6  1

//--- plot oversold_line_2

#property indicator_label7  "oversold_line_2"

#property indicator_type7   DRAW_LINE

#property indicator_color7  clrGreen

#property indicator_style7  STYLE_DASH

#property indicator_width7  1

//--- plot oversold_line_3

#property indicator_label8  "oversold_line_3"

#property indicator_type8   DRAW_LINE

#property indicator_color8  clrGreen

#property indicator_style8  STYLE_SOLID

#property indicator_width8  1

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



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

//|   ;>: 22>48<KE ?0@0<5B@>2                                       |

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

//extern   string               delimiter_rsi_0 = "------------------------------------------------------------"; //------------------------------------------------------------

extern   string               delimiter_rsi_1   = "--- Settings Relative Strength Index ----";                                   //------------------------------------------------------------

extern   ENUM_TIMEFRAMES      RSI_TimeFrame     = PERIOD_CURRENT;    //TimeFrame

extern   int                  RSI_Period        = 14;                //Period

extern   ENUM_APPLIED_PRICE   RSI_Applied_Price = PRICE_CLOSE;       //Applied price

extern   int                  RSI_Shift_Bars    = 0;                 //Shift Bars

extern   string               delimiter_rsi_2   = "--- Settings Level for RSI ---------------------";                         //------------------------------------------------------------

//extern   ENUM_RSI_MODE        RSI_MODE          = NONE;  //Definition mode

extern   int                  RSI_OverBought_3    = 90;    //Level overbought 3

extern   int                  RSI_OverBought_2    = 75;    //Level overbought 2

extern   int                  RSI_OverBought_1    = 60;    //Level overbought 1

extern   int                  RSI_ThresHold       = 50;    //Level threshold

extern   int                  RSI_OverSold_1      = 40;    //Level oversold 1

extern   int                  RSI_OverSold_2      = 25;    //Level oversold 2

extern   int                  RSI_OverSold_3      = 10;    //Level oversold 3

//extern   bool                 RSI_Inverse       = false; //Use inverse

extern   string               delimiter_rsi_3 = "------------------------------------------------------------"; //------------------------------------------------------------

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



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

//|   ;>: ?>4:;NG05<KE D09;>2 #include ".mqh"                       |

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

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



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

//|   ;>: 3;>10;L=KE ?5@5<5==KE                                     |

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

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



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

//|   ;>: 8=48:0B>@=KE <0AA82>2                                     |

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

//--- indicator buffers

double         main_line[];

double         overbought_line_3[];

double         overbought_line_2[];

double         overbought_line_1[];

double         threshold_line[];

double         oversold_line_1[];

double         oversold_line_2[];

double         oversold_line_3[];

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



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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- =8F80;870F8O ?5@5<5==KE ---------------------------------------

   string text_name = NAME_PROGRAM; // "5:AB 4;O 8<5=8 ?@>3@0<<K

   string text_timeframe = "";      // "5:AB 4;O B09<D@59<0

   string text_copyright = "";      // "5:AB 4;O Copyright

//--------------------------------------------------------------------

   switch(RSI_Applied_Price)

     {

      case 0 :

         text_name = text_name +" - CLOSE ";

         break;

      case 1 :

         text_name = text_name +" - OPEN ";

         break;

      case 2 :

         text_name = text_name +" - HIGH ";

         break;

      case 3 :

         text_name = text_name +" - LOW ";

         break;

      case 4 :

         text_name = text_name +" - MEDIAN ";

         break;

      case 5 :

         text_name = text_name +" - TYPICAL ";

         break;

      case 6 :

         text_name = text_name +" - WEIGHTED ";

         break;

      default :

         break;

     }

//--------------------------------------------------------------------

   if(RSI_TimeFrame < Period())

      RSI_TimeFrame=PERIOD_CURRENT;

   switch(RSI_TimeFrame)

     {

      case 0 :

         RSI_TimeFrame=PERIOD_CURRENT;

         break;

      case 1 :

         text_timeframe = "M1";

         break;

      case 5 :

         text_timeframe = "M5";

         break;

      case 15 :

         text_timeframe = "M15";

         break;

      case 30 :

         text_timeframe = "M30";

         break;

      case 60 :

         text_timeframe = "H1";

         break;

      case 240 :

         text_timeframe = "H4";

         break;

      case 1440 :

         text_timeframe = "D1";

         break;

      case 10080 :

         text_timeframe = "W1";

         break;

      case 43200 :

         text_timeframe = "MN1";

         break;

      default :

         break;

     }

   text_name = StringConcatenate(text_name," (TimeFrame: "+text_timeframe+", Period: "+DoubleToStr(RSI_Period,0)+")");

   IndicatorShortName(text_name);

//--------------------------------------------------------------------

//--------------------------------------------------------------------

   if(Year() > YEAR_CREATE)

      text_copyright = "Copyright © " + StringConcatenate(YEAR_CREATE) + " - " + StringConcatenate(Year()) + ", " + NAME_COMPANY;

   else

      text_copyright = "Copyright © " + StringConcatenate(YEAR_CREATE) + ", " + NAME_COMPANY;

//--------------------------------------------------------------------

   ObjectCreate(chart_ID,"info_copyright",OBJ_LABEL,0,0,0);

   ObjectSetInteger(chart_ID,"info_copyright",OBJPROP_XDISTANCE,270);               // #AB0=>28< :>>@48=0BK <5B:8 ?> >A5 X

   ObjectSetInteger(chart_ID,"info_copyright",OBJPROP_YDISTANCE,20);                // #AB0=>28< :>>@48=0BK <5B:8 ?> >A5 Y

   ObjectSetInteger(chart_ID,"info_copyright",OBJPROP_CORNER,CORNER_RIGHT_LOWER);   // #AB0=>28< C3>; ?@82O7:8

   ObjectSetString(chart_ID,"info_copyright",OBJPROP_TEXT,text_copyright);          // #AB0=>28< B5:AB

   ObjectSetString(chart_ID,"info_copyright",OBJPROP_FONT,"Arial");                 // #AB0=>28< H@8DB

   ObjectSetInteger(chart_ID,"info_copyright",OBJPROP_FONTSIZE,10);                 // #AB0=>28< @07<5@ H@8DB0

   ObjectSetInteger(chart_ID,"info_copyright",OBJPROP_COLOR,clrGold);               // #AB0=>28< F25B

//--------------------------------------------------------------------

//--- indicator buffers mapping

   SetIndexBuffer(0,main_line);

   SetIndexLabel(0,"Main");      // 07=0G8BL 8<O 7=0G5=8O< 87 <0AA820 main_line[]

   SetIndexBuffer(1,overbought_line_3);

   SetIndexLabel(1,"Overbought");   // 07=0G8BL 8<O 7=0G5=8O< 87 <0AA820 overbought_line_3[]

   SetIndexBuffer(2,overbought_line_2);

   SetIndexLabel(2,"Overbought");   // 07=0G8BL 8<O 7=0G5=8O< 87 <0AA820 overbought_line_2[]

   SetIndexBuffer(3,overbought_line_1);

   SetIndexLabel(3,"Overbought");   // 07=0G8BL 8<O 7=0G5=8O< 87 <0AA820 overbought_line_1[]

   SetIndexBuffer(4,threshold_line);

   SetIndexLabel(4,"Threshold"); // 07=0G8BL 8<O 7=0G5=8O< 87 <0AA820 threshold_line[]

   SetIndexBuffer(5,oversold_line_1);

   SetIndexLabel(5,"Oversold");  // 07=0G8BL 8<O 7=0G5=8O< 87 <0AA820 oversold_line_1[]

   SetIndexBuffer(6,oversold_line_2);

   SetIndexLabel(6,"Oversold");  // 07=0G8BL 8<O 7=0G5=8O< 87 <0AA820 oversold_line_2[]

   SetIndexBuffer(7,oversold_line_3);

   SetIndexLabel(7,"Oversold");  // 07=0G8BL 8<O 7=0G5=8O< 87 <0AA820 oversold_line_3[]

//--------------------------------------------------------------------

   return(INIT_SUCCEEDED);

  }

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



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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

{

//--------------------------------------------------------------------

ObjectDelete("info_copyright");

//--------------------------------------------------------------------

}

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



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

//| Custom indicator iteration function                              |

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

int OnCalculate(const int rates_total,    //  07<5@ 2E>4=KE B09<A5@89

                const int prev_calculated,// 1@01>B0=> 10@>2 =0 ?@54K4CI5< 2K7>25

                const datetime &time[],   // Time

                const double &open[],     // Open

                const double &high[],     // High

                const double &low[],      // Low

                const double &close[],    // Close

                const long &tick_volume[],// Tick volume

                const long &volume[],     // Real volume

                const int &spread[]       // Spread

               )

{

//--------------------------------------------------------------------

string symbol = Symbol();

//--- ?@545;8< A>>B25BAB2CNI55 A2>9AB20 4;O A8<2>;0 -----------------

int      digits   = (int) SymbolInfoInteger(symbol,SYMBOL_DIGITS);   // >;8G5AB2> 7=0:>2 ?>A;5 70?OB>9

//--------------------------------------------------------------------

//--- =8F80;870F8O ?5@5<5==KE ---------------------------------------

int      limit       = 0;

int      bar         = RSI_Shift_Bars;

//--- =8F80;870F8O =0AB@08205<KE ?5@5<5=KE 8=48:0B>@0  ------------

ENUM_TIMEFRAMES      timeframe     = RSI_TimeFrame;      // "09<D@59<

int                  period        = RSI_Period;         // 5@8>4

ENUM_APPLIED_PRICE   applied_price = RSI_Applied_Price;  // "8? F5=K

//--------------------------------------------------------------------

//--------------------------------------------------------------------

if(Bars <= 100) return (rates_total);    // @>25@8< :>;8G5AB20 10@>2 4;O @0AGQB>2

int ExtCountedBars = IndicatorCounted();  // >;CG8< :>;8G5AB20 C65 ?>AG8B0==KE 10@>2

if(ExtCountedBars < 0) return (-1);      // @>25@8< =0 2>7<>6=K5 >H81:8 2 ?>4AG5B0E

if(ExtCountedBars > 0) ExtCountedBars--; // >A;54=89 ?>AG8B0==K9 10@ 4>;65= 1KBL ?5@5AG8B0=

if(ExtCountedBars == 0)limit-=1+9;      // A;8 10@>2 =54>AB0B>G=> 4;O >B@8A>2:8 ?@8A2>8< C25;8G5==>5 7=0G5=85

   limit = Bars - IndicatorCounted() - 1;    //  0AG8B05< <0:A8<0;L=>5 :>;;8G5AB2> 10@>2 4;O >B@8A>2:8

//--------------------------------------------------------------------

   int shift_index = 0;

   int htf_index = -1;

   double rsi = 0.0;

   for(int index = limit; index >  0; index--)

      //for(int index = 0; index <  limit; index++)

     {

      if(timeframe != Period())

         shift_index = iBarShift(symbol,timeframe,iTime(symbol,PERIOD_CURRENT,index));

      else

         shift_index = index;

      if(htf_index != shift_index)

        {

         htf_index = shift_index;

         rsi = iRSI(symbol,timeframe,period,applied_price,shift_index + bar);

        }

      ///--- G8AB8< <0AA82K >B 40==KE

      main_line[index] = EMPTY_VALUE;

      overbought_line_3[index] = EMPTY_VALUE;

      overbought_line_2[index] = EMPTY_VALUE;

      overbought_line_1[index] = EMPTY_VALUE;

      threshold_line[index] = EMPTY_VALUE;

      oversold_line_1[index] = EMPTY_VALUE;

      oversold_line_2[index] = EMPTY_VALUE;

      oversold_line_3[index] = EMPTY_VALUE;

      ///--- @8A2>8< <0AA820< 7=0G5=85

      main_line[index] = NormalizeDouble(rsi,digits);

      overbought_line_3[index] = NormalizeDouble(RSI_OverBought_3,0);

      overbought_line_2[index] = NormalizeDouble(RSI_OverBought_2,0);

      overbought_line_1[index] = NormalizeDouble(RSI_OverBought_1,0);

      threshold_line[index] = NormalizeDouble(RSI_ThresHold,2);

      oversold_line_1[index] = NormalizeDouble(RSI_OverSold_1,0);

      oversold_line_2[index] = NormalizeDouble(RSI_OverSold_2,0);

      oversold_line_3[index] = NormalizeDouble(RSI_OverSold_3,0);

     }

//--------------------------------------------------------------------

   ChartRedraw(chart_ID);// K7K28< ?@8=C48B5;L=CN ?5@5@8A>2:C 3@0D8:0

   return(rates_total);//return value of prev_calculated for next call

  }

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

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 ---