Dynamic RSI Light MTF

Author: Copyright 2023, Inquiring
Price Data Components
Series array that contains open time of each bar
Indicators Used
Relative strength indexMoving average indicator
0 Views
0 Downloads
0 Favorites
Dynamic RSI Light MTF
ÿþ//+------------------------------------------------------------------+

//|                                        Dynamic RSI Light MTF.mq4 |

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

#property version     "1.0"

#property copyright   "Copyright 2023, Inquiring"

#property strict



#property description "Dynamic RSI Light MTF\n ?> <>B820< Dynamic RSI RomanKiverin"

#property indicator_separate_window

#property indicator_buffers 11

// --- settings

extern ENUM_TIMEFRAMES TimeFrame  = PERIOD_CURRENT;

extern int DZbuy             =  20;                 // Buyers Dynamic Zone Probability

extern int DZsell            =  20;                 // Sellers Dynamic Zone Probability

extern int PeriodRSI         =  14;                 // Period RSI

extern int LookBack          =  34;                 // Look Back PeriodRSI



#property indicator_color1  clrGray

#property indicator_color2  clrDarkOrange

#property indicator_color3  clrYellow

#property indicator_color4  clrLime

#property indicator_color5  clrOrange

#property indicator_color6  clrMagenta

#property indicator_color7  clrRed

#property indicator_color8  clrNONE



#property indicator_width1  0

#property indicator_width2  0

#property indicator_width3  0

#property indicator_width4  3

#property indicator_width5  3

#property indicator_width6  3

#property indicator_width7  2

#property indicator_width8  2





//--- indicator buffers

double         RSIBuffer[];

double         RSIValueBuffer[];



double         TopLineBuffer[];

double         BottomLineBuffer[];



double         MaxLineBuffer[];

double         MinLineBuffer[];



double         UpTrend[];

double         DnTrend[];



double         UpBuffer[];

double         DnBuffer[];

double         MediumBuffer[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0, TopLineBuffer);

   SetIndexStyle (0, DRAW_LINE);

   SetIndexLabel (0, "UpLine");



   SetIndexBuffer(1,BottomLineBuffer);

   SetIndexStyle (1,DRAW_LINE);

   SetIndexLabel (1, "DnLine");



   SetIndexBuffer(2,RSIValueBuffer);

   SetIndexStyle (2, DRAW_LINE);

   SetIndexLabel (2, "RSIValue");



   SetIndexBuffer(3, UpTrend);

   SetIndexStyle (3, DRAW_LINE);

   SetIndexLabel (3, "UpTrend");

   SetIndexEmptyValue(3,0);



   SetIndexBuffer(4, DnTrend);

   SetIndexStyle (4, DRAW_LINE);

   SetIndexLabel (4, "DnTrend");

   SetIndexEmptyValue(4,0);



   SetIndexBuffer(5, MaxLineBuffer);

   SetIndexStyle (5, DRAW_LINE);

   SetIndexLabel (5, "MaxLineBuffer");

   SetIndexEmptyValue(5, 0);



   SetIndexBuffer(6, MinLineBuffer);

   SetIndexStyle (6, DRAW_LINE);

   SetIndexLabel (6, "MinLineBuffer");

   SetIndexEmptyValue(6, 0);



   SetIndexBuffer(7, MediumBuffer);

   SetIndexStyle (7, DRAW_LINE);

   SetIndexLabel (7, "MediumBuffer");



   SetIndexBuffer(8, RSIBuffer);

   SetIndexStyle (8, DRAW_NONE);



   SetIndexBuffer(9, UpBuffer);

   SetIndexStyle (9, DRAW_NONE);



   SetIndexBuffer(10,DnBuffer);

   SetIndexStyle (10,DRAW_NONE);



   IndicatorShortName("Dynamic(" + (string)TimeFrame + "," + (string)DZbuy + "," + (string)DZsell + "," + (string)PeriodRSI + "," + (string)LookBack + ")");

//---

   return(INIT_SUCCEEDED);

  }

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

//| 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[])

  {

//---

   for(int i = MathMin(rates_total - prev_calculated, Bars - LookBack - 1); i >= 0; i --)

     {

      int y = iBarShift(_Symbol,TimeFrame,iTime(_Symbol, 0, i));

      RSIBuffer[i] = iRSI(NULL, TimeFrame, PeriodRSI, PRICE_MEDIAN, y);

     }



   for(int i = MathMin(rates_total - prev_calculated, Bars - LookBack - 1); i >= 0; i --)

     {

      int coefficient = 0;

      if(TimeFrame == PERIOD_CURRENT)

         coefficient = _Period;

      else

         coefficient = TimeFrame;

      RSIValueBuffer[i] = iMAOnArray(RSIBuffer, 0, PeriodRSI * coefficient / Period() / 2, 0, MODE_LWMA, i);



      UpBuffer[i] = RSIValueBuffer[ArrayMaximum(RSIValueBuffer, LookBack * coefficient / Period(), i)];

      DnBuffer[i] = RSIValueBuffer[ArrayMinimum(RSIValueBuffer, LookBack * coefficient / Period(), i)];



      MediumBuffer[i] = (UpBuffer[i] + DnBuffer[i])/ 2.0;



      TopLineBuffer[i] = DZbuy > 0 ? UpBuffer[i] - MediumBuffer[i] / DZbuy : UpBuffer[i] - MediumBuffer[i];

      BottomLineBuffer[i] = DZsell > 0 ? DnBuffer[i] + MediumBuffer[i] / DZsell : DnBuffer[i] + MediumBuffer[i];





      if(RSIValueBuffer[i] > TopLineBuffer[i])

         MaxLineBuffer[i] = RSIValueBuffer[i];

      else

         if(RSIValueBuffer[i] < TopLineBuffer[i] && RSIValueBuffer[i] > BottomLineBuffer[i] && RSIValueBuffer[i] < RSIValueBuffer[i + 1])

            DnTrend[i] = RSIValueBuffer[i];

         else

            if(RSIValueBuffer[i] < TopLineBuffer[i] && RSIValueBuffer[i] > BottomLineBuffer[i] && RSIValueBuffer[i] > RSIValueBuffer[i + 1])

               UpTrend[i] = RSIValueBuffer[i];

            else

               if(RSIValueBuffer[i] < BottomLineBuffer[i])

                  MinLineBuffer[i] = RSIValueBuffer[i];

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

     }

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

   return(rates_total);

  }

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

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