Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
3.2 kB
2
Indexable
Never
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Green
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 2
#property indicator_width4 2

//--- indicator buffers
double ExtRSIBuffer[];
double ExtOpenBuffer[];
double ExtHighBuffer[];
double ExtLowBuffer[];
double ExtPatternBuffer[];

//--- input parameters
input int RSIPeriod = 14;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   //--- indicator buffers mapping
   SetIndexBuffer(0, ExtRSIBuffer);
   SetIndexBuffer(1, ExtOpenBuffer);
   SetIndexBuffer(2, ExtHighBuffer);
   SetIndexBuffer(3, ExtLowBuffer);
   SetIndexBuffer(4, ExtPatternBuffer);
   
   //--- set description for indicators
   IndicatorShortName("RSI Candles (" + IntegerToString(RSIPeriod) + ")");
   SetIndexLabel(0, "RSI");
   SetIndexLabel(1, "RSI Open");
   SetIndexLabel(2, "RSI High");
   SetIndexLabel(3, "RSI Low");
   SetIndexLabel(4, "RSI Pattern");

   //--- draw style
   SetIndexStyle(0, DRAW_NONE);
   SetIndexStyle(1, DRAW_CANDLES);
   SetIndexStyle(2, DRAW_CANDLES);
   SetIndexStyle(3, DRAW_CANDLES);
   SetIndexStyle(4, DRAW_ARROW);
   SetIndexArrow(4, 233); // code for the arrow symbol

   //--- initialization done
   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[])
  {
   int start = MathMax(RSIPeriod, prev_calculated - 1);

   for(int i = start; i < rates_total; i++)
     {
      //--- calculate RSI
      ExtRSIBuffer[i] = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, i);
      
      //--- fill buffers for RSI candles
      ExtOpenBuffer[i] = (i == 0) ? ExtRSIBuffer[i] : ExtRSIBuffer[i-1];
      ExtHighBuffer[i] = MathMax(ExtOpenBuffer[i], ExtRSIBuffer[i]);
      ExtLowBuffer[i] = MathMin(ExtOpenBuffer[i], ExtRSIBuffer[i]);
      
      //--- identify patterns
      if ((ExtRSIBuffer[i] > 30 && ExtRSIBuffer[i-1] <= 30) ||
          (ExtRSIBuffer[i] < 70 && ExtRSIBuffer[i-1] >= 70) ||
          (ExtRSIBuffer[i] > 0 && ExtRSIBuffer[i-1] == 0) ||
          (ExtRSIBuffer[i] < 100 && ExtRSIBuffer[i-1] == 100))
        {
         ExtPatternBuffer[i] = ExtRSIBuffer[i];
        }
      else
        {
         ExtPatternBuffer[i] = EMPTY_VALUE;
        }
     }
   return(rates_total);
  }
Leave a Comment