EA31337 / EA31337-indicators-common

Collection of common indicators used for EA31337 strategies.
6 stars 3 forks source link

RSI Deep Three #15

Open kenorb opened 1 year ago

kenorb commented 1 year ago
//+------------------------------------------------------------------+
//|                                                   RSI Deep Three |
//+------------------------------------------------------------------+
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot RSI
#property indicator_label1  "RSI"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Signal
#property indicator_label2  "Signal"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrBlue
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

input int InpRSIPeriod=14; // RSI Period

double ExtRSIBuffer[];
double ExtSignalBuffer[];

int OnInit()
{
   IndicatorSetInteger(INDICATOR_DIGITS,0);
   SetIndexBuffer(0,ExtRSIBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
   SetIndexArrow(1,159);
   IndicatorSetString(INDICATOR_SHORTNAME,"RSI Deep Three("+string(InpRSIPeriod)+")");
   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[])
{
   if(rates_total<InpRSIPeriod)
      return(0);
   int limit;
   if(prev_calculated==0)
      limit=InpRSIPeriod;
   else limit=prev_calculated-1;

   for(int i=limit;i<rates_total;i++)
     {
      ExtRSIBuffer[i]=iRSI(NULL,0,InpRSIPeriod,PRICE_CLOSE,i);
      if(i>InpRSIPeriod+3)
        {
         if(ExtRSIBuffer[i]<ExtRSIBuffer[i-1] && ExtRSIBuffer[i-1]<ExtRSIBuffer[i-2] && ExtRSIBuffer[i-2]<ExtRSIBuffer[i-3])
            ExtSignalBuffer[i]=low[i]-10*Point;
         else if(ExtRSIBuffer[i]>ExtRSIBuffer[i-1] && ExtRSIBuffer[i-1]>ExtRSIBuffer[i-2] && ExtRSIBuffer[i-2]>ExtRSIBuffer[i-3])
            ExtSignalBuffer[i]=high[i]+10*Point;
         else ExtSignalBuffer[i]=0.0;
        }
     }

   return(rates_total);
}

Refs: