Help of Error: Not all data of RSI calculated

 

Dear Fellows

I am getting following error and have no idea, how to resolve it. Search on forum/google did not help much.

2023.12.13 19:31:45.367 iStochRSI (US30,H1)     Not all data of RSI calculated (38018 un-calculated bars )

Regards.

 
Anil Varma:

Dear Fellows

I am getting following error and have no idea, how to resolve it. Search on forum/google did not help much.

Regards.

Is it a custom indicator?
Could be a bug inside the indicator...
 
Anil Varma: iStochRSI

Is that log output form the "Journal" or from the "Experts" log?

It seems to be a log message from the "Experts" log, as it's most definitely a custom indicator, so you should look into its code for the issue.

 
Fernando Carreiro #:

Is that log output form the "Journal" or from the "Experts" log?

It seems to be a log message from the "Experts" log, as it's most definitely a custom indicator, so you should look into its code for the issue.

Thanks @Fernando Carreiro and @Yashar Seyyedin

Yeh it is custom indicator by @Mladen Rakic. The problem seems to be more frequent since I have activated the following input from 1 (no stochastic if <2) to 34.

I usually have custom LogError statements, however as I did not modify the mladen indicator, I could not recognize the error source :(.

                // START POSITION IS pIndex AND COUNT IS SINGLE VALUE
                ResetLastError();
                if(CopyBuffer(mHandleSRSI,_bStochRSI,pIndex,1,arrayData) == -1) {
                 string vMethod = "[" + (string)mSymbol + "," + EnumToString(mTimeFrame) + "] " + (string)__FUNCTION__;
                  PrintFormat("%s LogError[#%i] getting iStochRSI at Index[%i]",vMethod,GetLastError(),pIndex);
                  return(0.00);
                }

I could not figure out any issue in the code except the error print from 'checkCalculated(). Guide from experts will be much appreciated about how to fix it.

input int                       SRSI_PeriodStoch2       = 34;
//+-----------------------------------------------------------------------------------------------------------------------------+
//| Stochastic RSI.mq5
//+-----------------------------------------------------------------------------------------------------------------------------+
        #property copyright "mladen"
        #property link      "mladenfx@gmail.com"
        #property version   "1.00"

        #property indicator_separate_window
        #property indicator_buffers   5
        #property indicator_plots     2

        #property indicator_type1   DRAW_FILLING                                                                                // FILLS OVER BOUGHT AND OVER SOLD REGION WITH COLOR
        #property indicator_color1  Green,Red
        #property indicator_style1  STYLE_SOLID
        #property indicator_width1  1
        #property indicator_type2   DRAW_LINE                                                                                           // DRAWS INDICATOR LINE WITH DIM GRAY COLOR
        #property indicator_color2  clrDimGray
        #property indicator_width2  2
//+-----------------------------------------------------------------------------------------------------------------------------+
//| Define Input Parameters
//+-----------------------------------------------------------------------------------------------------------------------------+
        input int                       SRSI_PeriodRSI          = 13;           // RSI PERIOD [14]
        input ENUM_APPLIED_PRICE        SRSI_AppliedPrice       = PRICE_CLOSE;  // APPLIED PRICE FOR RSI CALCULATION [PRICE_CLOSE]
        input int                       SRSI_PeriodStoch1       = 55;           // 1st STOCHASTIC PERIOD [55] (no stochastic, if < 2)
        input int                       SRSI_PeriodStoch2       = 34;           // 2nd STOCHASTIC PERIOD [55] (no stochastic, if < 2)
        input int                       SRSI_EMAPeriod          = 2;            // EXPONENTIAL SMOOTHING PERIOD [15] (no smoothing, if < 2)
        input double                    SRSI_ThldOB                             = 90.0;         // OVER BOUGHT LEVEL

        #define         _RangeMax                               100.0
        #define         _RangeMin                                 0.0
        #define         _ThldOB                                 SRSI_ThldOB
        #define         _ThldOS                                 (_RangeMax - _ThldOB)
//+-----------------------------------------------------------------------------------------------------------------------------+
//| Load Indicator Buffers and Global Variables
//+-----------------------------------------------------------------------------------------------------------------------------+
        double StoBuffer[];
        double LevBuffer[];
        double StlBuffer[];
        double RsiBuffer[];
        double StcBuffer[];

        int iRSIPeriod;
        int iStoPeriod1;
        int iStoPeriod2;
        int iEMAPeriod;
        int mHandleRSI;
//+-----------------------------------------------------------------------------------------------------------------------------+
//| Custom indicator initialization function
//+-----------------------------------------------------------------------------------------------------------------------------+
int OnInit() {

   SetIndexBuffer(0,StoBuffer,INDICATOR_DATA);                  ArraySetAsSeries(StoBuffer,true);
   SetIndexBuffer(1,LevBuffer,INDICATOR_CALCULATIONS);          ArraySetAsSeries(LevBuffer,true);     // Original Code INDICATOR_DATA ... Could this cause error ?
   SetIndexBuffer(2,StlBuffer,INDICATOR_CALCULATIONS);    	ArraySetAsSeries(StlBuffer,true);     // Original Code INDICATOR_DATA ... Could this cause error ?
   SetIndexBuffer(3,RsiBuffer,INDICATOR_CALCULATIONS);          ArraySetAsSeries(RsiBuffer,true);
   SetIndexBuffer(4,StcBuffer,INDICATOR_CALCULATIONS);          ArraySetAsSeries(StcBuffer,true);
  //+---------------------------------------------------------------------------------------------------------------------------+
  //| VALIDATE INPUTS
  //+---------------------------------------------------------------------------------------------------------------------------+
                iRSIPeriod  = (SRSI_PeriodRSI > 0)      ? SRSI_PeriodRSI        : 1;
                iEMAPeriod  = (SRSI_EMAPeriod > 0)      ? SRSI_EMAPeriod        : 1;
                iStoPeriod1 = (SRSI_PeriodStoch1 > 0) ? SRSI_PeriodStoch1 : 1;
                iStoPeriod2 = (SRSI_PeriodStoch2 > 0) ? SRSI_PeriodStoch2 : 1;

                mHandleRSI = iRSI(NULL,0,iRSIPeriod,SRSI_AppliedPrice);
     
  //+---------------------------------------------------------------------------------------------------------------------------+
  //| SET INDICATOR SHORT NAME
  //+---------------------------------------------------------------------------------------------------------------------------+
                string strSmooth = (iEMAPeriod  > 1) ? "Smooth " : "";
                string strStoch  = (iStoPeriod1 > 1 || iStoPeriod2 > 1) ? "iStochastic" : "";
                       strStoch  = (iStoPeriod1 > 1 && iStoPeriod2 > 1) ? "iDouble Stochastic" : strStoch;
                IndicatorSetString(INDICATOR_SHORTNAME,strStoch+"RSI " + strSmooth + " ("+(string)iRSIPeriod+","+(string)iStoPeriod1+","+(string)iStoPeriod2+","+(string)iEMAPeriod+")");
  //+---------------------------------------------------------------------------------------------------------------------------+
  //| SET INDICATOR ACCURACY DIGIT, HEIGHT AND FIXED MAXIMUM AND MINIMUM VALUES
  //+---------------------------------------------------------------------------------------------------------------------------+
    IndicatorSetInteger(INDICATOR_DIGITS,3);                                                            // iRSI and iStochRSI kept at default 3 digits
    IndicatorSetInteger(INDICATOR_HEIGHT,175);
                IndicatorSetDouble(INDICATOR_MAXIMUM,_RangeMax + 5);
                IndicatorSetDouble(INDICATOR_MINIMUM,_RangeMin - 5);
  //+---------------------------------------------------------------------------------------------------------------------------+
  //| SET INDICATOR LEVELS
  //+---------------------------------------------------------------------------------------------------------------------------+
                IndicatorSetInteger(INDICATOR_LEVELS,4);
                IndicatorSetDouble(INDICATOR_LEVELVALUE,0,_ThldOB);
                IndicatorSetDouble(INDICATOR_LEVELVALUE,1,60.0);                                // MID POINT
                IndicatorSetDouble(INDICATOR_LEVELVALUE,2,40.0);                                // MID POINT
                IndicatorSetDouble(INDICATOR_LEVELVALUE,3,_ThldOS);
                IndicatorSetInteger(INDICATOR_LEVELCOLOR,clrSilver);
  //+---------------------------------------------------------------------------------------------------------------------------+
  //| SET INDICATOR DATA LABEL
  //+---------------------------------------------------------------------------------------------------------------------------+
    PlotIndexSetString(0,PLOT_LABEL,"StochRSI ("+IntegerToString(iRSIPeriod)+","+IntegerToString(iStoPeriod1)+","+IntegerToString(iStoPeriod2)+","+IntegerToString(iEMAPeriod)+")");
     
   return(0);
}
//+-----------------------------------------------------------------------------------------------------------------------------+
//| Custom indicator calculation 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 limit = rates_total-prev_calculated;
         if (prev_calculated > 0) limit++;
         if (prev_calculated ==0)
         {
            int last   = (iStoPeriod1>iStoPeriod2) ? iStoPeriod1 : iStoPeriod2;
                limit -= (last+1);
                        for (int i=1; i<=last; i++) StoBuffer[rates_total-i] = 0;
         }
         if (!checkCalculated(mHandleRSI,rates_total,"RSI")) return(prev_calculated);
         if (!doCopy(mHandleRSI,RsiBuffer,0,limit   ,"RSI")) return(prev_calculated);

   //
   //
           
      double max,min,sto;
      double alpha = 2.0/(1.0+iEMAPeriod);
      
      //
      //
         
      for (int i=limit; i>=0; i--)
      {
         if (iStoPeriod1>1)
         {
            max = RsiBuffer[i]; for(int k=1; k<iStoPeriod1; k++) max = MathMax(max,RsiBuffer[i+k]);
            min = RsiBuffer[i]; for(int k=1; k<iStoPeriod1; k++) min = MathMin(min,RsiBuffer[i+k]);
            if (max!=min)
                  StcBuffer[i] = (RsiBuffer[i]-min)/(max-min)*100.00;
            else  StcBuffer[i] = 0;
         }
         else StcBuffer[i] = RsiBuffer[i];
         
         //
         //
                     
         if (iStoPeriod2>1)
         {
            max = StcBuffer[i]; for(int k=1; k<iStoPeriod2; k++) max = MathMax(max,StcBuffer[i+k]);
            min = StcBuffer[i]; for(int k=1; k<iStoPeriod2; k++) min = MathMin(min,StcBuffer[i+k]);
            if (max!=min)
                  sto = (StcBuffer[i]-min)/(max-min)*100.00;
            else  sto = 0;
         }
         else sto = StcBuffer[i];
         StoBuffer[i] = StoBuffer[i+1]+alpha*(sto-StoBuffer[i+1]);
         StlBuffer[i] = StoBuffer[i];
         LevBuffer[i] = StoBuffer[i];
   
         //
         //
               
         if (StoBuffer[i]>SRSI_ThldOB) LevBuffer[i] = SRSI_ThldOB;
         if (StoBuffer[i]<_ThldOS) LevBuffer[i] = _ThldOS;
   }
   
   //
   //

   return(rates_total);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool checkCalculated(int bufferHandle, int total, string checkDescription)
{
   int calculated=BarsCalculated(bufferHandle);
   if (calculated<total)
   {
      Print("Not all data of "+checkDescription+" calculated (",(string)(total-calculated)," un-calculated bars )");
      return(false);
   }
   return(true);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool doCopy(const int bufferHandle, double& buffer[], const int buffNum, const int copyCount, string copyDescription)
{
   if(CopyBuffer(bufferHandle,buffNum,0,copyCount,buffer)<=0)
   {
      Print("Getting "+copyDescription+" failed! Error",GetLastError());
      return(false);
   }
   return(true);
}
//+------------------------------------------------------------------+

Best Regards

 

Hi Anil.

I am having the same problem with the same indicator. Have you managed to find any solution?

Thanks in advance.

Reason: