RelativeStrengthLevy

Author: Copyright © 2021 por Gustavo de Souza Lima
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
RelativeStrengthLevy
ÿþ//+------------------------------------------------------------------+

//|                                         RelativeStrengthLevy.mq5 |

//|                  Copyright © 2022, Gustavo de Souza Lima Pereira |

//|                                    https://www.mw4profit.com.br/ |

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

#property copyright "Copyright © 2021 por Gustavo de Souza Lima"

#property link      "https://www.mw4profit.com.br/"

#property version   "1.00"

#property description "Relative Strength Levy"

#property description "E-mail - gudesouzalima@gmail.com"

//--- indicator settings

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_plots   1



#property indicator_label1  "RSL"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrDodgerBlue

#property indicator_style1  STYLE_SOLID

#property indicator_width1  2



// --- Input Variable ------------------------------------------------------------------

input int            InpMAPeriod    = 15;          // MA Period

input ENUM_MA_METHOD InpMAMethod    = MODE_SMA;    // MA Method

input int            InpMAShift     = 0;           // MA Shift

input ENUM_APPLIED_PRICE InpMAPrice = PRICE_CLOSE; // MA Applied Price



// --- Indicator Buffer ----------------------------------------------------------------

double Buffer[], calculationsBuffer[];

int handleMA;



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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,Buffer,INDICATOR_DATA);

   SetIndexBuffer(1,calculationsBuffer,INDICATOR_CALCULATIONS);

   handleMA = iMA(_Symbol,PERIOD_CURRENT, InpMAPeriod, InpMAShift, InpMAMethod, InpMAPrice);

   if(handleMA==INVALID_HANDLE)

     {

      PrintFormat("Falha handleMA %s/%s, error code %d",_Symbol,EnumToString(PERIOD_CURRENT),GetLastError());

     }



   IndicatorSetInteger(INDICATOR_LEVELS,1);

   IndicatorSetDouble(INDICATOR_LEVELVALUE,0,1);

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,0, clrGray);

   IndicatorSetInteger(INDICATOR_LEVELSTYLE,0, STYLE_DASHDOTDOT);



   string short_name=StringFormat("Relative Strength Levy (%d)",InpMAPeriod);

   IndicatorSetString(INDICATOR_SHORTNAME,short_name);

   IndicatorSetInteger(INDICATOR_DIGITS,5);



   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod);

//--- line shifts when drawing

   PlotIndexSetInteger(0,PLOT_SHIFT,InpMAShift);



   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);



   return(INIT_SUCCEEDED);

  }



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

//|                                                                  |

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

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

//--- determine the number of values calculated in the indicator

   int calculated=BarsCalculated(handleMA);

   if(calculated<=0)

     {

      PrintFormat("BarsCalculated() returning %d, error code %d",calculated,GetLastError());

      return(0);

     }

//--- if it is the indicator calculation principle, or if the number of values is modified in the iMA indicator

//--- or if indicator calculation is needed for two or more bars (this means that something has changed in the price history)

   if(prev_calculated==0 || rates_total>prev_calculated+1)

     {

//--- if the iMABuffer array is greater than the number of values in the iMA indicator for the symbol/period, then we don't copy everything

//--- otherwise we copy smaller than the size of the indicator buffers

      if(calculated>rates_total)

         values_to_copy=rates_total;

      else

         values_to_copy=calculated;

     }

   else

     {

//--- this means that it is not the first time the indicator has been calculated, it is since the last call of OnCalculate())

//--- for the calculation no more than one bar is added

      values_to_copy=(rates_total-prev_calculated)+1;

     }



   if(CopyBuffer(handleMA,0,0,values_to_copy,calculationsBuffer) < values_to_copy)

      return(0);



   for(int i=0; i<rates_total; i++)

      Buffer[i] = close[i]/calculationsBuffer[i];



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

   return(rates_total);

  }

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

Comments