Custom indicator not calculating / showing up on chart

 

Hello.  I have tried to adapt an RSI indicator to plot the RSI of two symbols on the one chart, and plot a histogram with the delta.  I can compile the code with no errors, however when I attach to a chart I don't get anything (not even a new window).  Any assistance would be appreciated - below is the code:

extern string Symbol1 = "EURUSD";

extern string Symbol2 = "GBPUSD";

extern int InpRSIPeriod = 14;


double RSI_Buffer1[];

double RSI_Buffer2[];

double Delta_Buffer[];


double ExtRSIBuffer[];

double ExtPosBuffer[];

double ExtNegBuffer[];


int OnInit()

{

   ArrayResize(RSI_Buffer1, Bars);

   ArrayResize(RSI_Buffer2, Bars);

   ArrayResize(Delta_Buffer, Bars);

   ArrayResize(ExtRSIBuffer, Bars);

   ArrayResize(ExtPosBuffer, Bars);

   ArrayResize(ExtNegBuffer, Bars);


   IndicatorShortName("RSI Delta");

   IndicatorDigits(Digits);

   SetIndexBuffer(0, Delta_Buffer);

   SetIndexStyle(0, DRAW_HISTOGRAM);

   SetIndexLabel(0, "RSI Delta");


   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 i, pos;

   double diff;


   if (Bars <= InpRSIPeriod || InpRSIPeriod < 2)

      return (0);


   pos = prev_calculated - 1;


   if (pos <= InpRSIPeriod)

   {

      ExtRSIBuffer[0] = 0.0;

      ExtPosBuffer[0] = 0.0;

      ExtNegBuffer[0] = 0.0;


      double sump = 0.0;

      double sumn = 0.0;

      for (i = 1; i <= InpRSIPeriod; i++)

      {

         ExtRSIBuffer[i] = 0.0;

         ExtPosBuffer[i] = 0.0;

         ExtNegBuffer[i] = 0.0;

         diff = close[i] - close[i - 1];

         if (diff > 0)

            sump += diff;

         else

            sumn -= diff;

      }


      ExtPosBuffer[InpRSIPeriod] = sump / InpRSIPeriod;

      ExtNegBuffer[InpRSIPeriod] = sumn / InpRSIPeriod;


      if (ExtNegBuffer[InpRSIPeriod] != 0.0)

         ExtRSIBuffer[InpRSIPeriod] = 100.0 - (100.0 / (1.0 + ExtPosBuffer[InpRSIPeriod] / ExtNegBuffer[InpRSIPeriod]));

      else

      {

         if (ExtPosBuffer[InpRSIPeriod] != 0.0)

            ExtRSIBuffer[InpRSIPeriod] = 100.0;

         else

            ExtRSIBuffer[InpRSIPeriod] = 50.0;

      }


      pos = InpRSIPeriod + 1;

   }


   for (i = pos; i < rates_total && !IsStopped(); i++)

   {

      diff = close[i] - close[i - 1];

      ExtPosBuffer[i] = (ExtPosBuffer[i - 1] * (InpRSIPeriod - 1) + (diff > 0.0 ? diff : 0.0)) / InpRSIPeriod;

      ExtNegBuffer[i] = (ExtNegBuffer[i - 1] * (InpRSIPeriod - 1) + (diff < 0.0 ? -diff : 0.0)) / InpRSIPeriod;

      if (ExtNegBuffer[i] != 0.0)

         ExtRSIBuffer[i] = 100.0 - 100.0 / (1 + ExtPosBuffer[i] / ExtNegBuffer[i]);

      else

      {

         if (ExtPosBuffer[i] != 0.0)

            ExtRSIBuffer[i] = 100.0;

         else

            ExtRSIBuffer[i] = 50.0;

      }

   }


   for (i = pos; i < rates_total; i++)

   {

      if (Symbol() == Symbol1)

         RSI_Buffer1[i] = ExtRSIBuffer[i];

      else if (Symbol() == Symbol2)

         RSI_Buffer2[i] = ExtRSIBuffer[i];

   }


   for (i = pos; i < rates_total; i++)

   {

      Delta_Buffer[i] = RSI_Buffer1[i] - RSI_Buffer2[i];

   }


   return (rates_total);

}


 
When you post code please use the Code button (Alt+S) !

Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.

Code button in editor

Hover your mouse over your post and select "edit" ... 

MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.