Indicator's value is different from values pulled via iCustom() of the same indicator.

 

I want to backtest one indicator named StableFX. But when I try to run the test "0" buffer of the StableFX indicator is -134, for example, but 0 buffer pulled with iCustom() is -65 on the same date. So the value showed by indicator and value pulled by iCustom is always different. I checked everything and , parameters are matched, buffer indexes to read from are correct, I am trying to detect crossover of the 0 and 1st buffers, but as I mentioned above values are not what indicator is showing in the window. I think I am missing something but can't seem to detect it. I have provided all the code that might be required. I Also attached screenshot with selected values to show what I mean. Please can someone point what I am doing wrong?


int OnInit()
  {
//---
   glTimeBarOpen = D'1971.01.01 00:00';

   atrHandle = iATR(_Symbol,PERIOD_CURRENT,atrPeriod);
   
   stableFxHandle = iCustom(_Symbol,PERIOD_CURRENT, "StableFx.ex5", inpKPeriod,inpDPeriod,inpSlowing,inpCCI,inpC1,inpC2,inpC3,inpP,inpMaPeriod,inpMaMethod,inpPeriod);// this indicator
   
   if(stableFxHandle == INVALID_HANDLE)
     {
         Print("FAILED TO INIT DIDI INDEX INDICATOR");
         return (INIT_FAILED);
     }
   
   if (atrHandle == INVALID_HANDLE) 
   {
      Print("FAILED TO INIT ATR INDICATOR");
      return (INIT_FAILED);
   }
   

   
//---
   return(INIT_SUCCEEDED);

here how I am getting signal :

entrySignal = detectCrossover(stableFxHandle, 0, 1, glTimeBarOpen);



string detectCrossover(int pHandle, int pSignalBuffer1, int pSignalBuffer2, const datetime time)
  {
   MqlDateTime dt;
   TimeToStruct(time,dt);
   double indicator1[];
   double indicator2[];
   CopyBuffer(pHandle,pSignalBuffer1,0,3,indicator1);
   CopyBuffer(pHandle,pSignalBuffer2,0,3,indicator2);
   ArraySetAsSeries(indicator1, true);
   ArraySetAsSeries(indicator2, true);
   if(indicator1[0] > indicator2[0] && (indicator1[1] <= indicator2[1]))// || (dt.day_of_week == 1 && indicator[1] > pCrossLine && indicator[2] <= pCrossLine )))
     {
      return  "LONG";

     }
   else
      if(indicator1[0] < indicator2[0] && (indicator1[1] >= indicator2[1])) // || (dt.day_of_week == 1 && indicator[1] < pCrossLine && indicator[2] >= pCrossLine)))
        {
         return  "SHORT";
        }
   return "NO TRADE - " + DoubleToString(indicator1[0]) + " | " + DoubleToString(indicator2[0])  + " | " + DoubleToString(dt.day_of_week) + " | " + DoubleToString(indicator1[1]) + " | " + DoubleToString(indicator2[1]);
  
  }
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Drawing Styles
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Drawing Styles
  • www.mql5.com
Drawing Styles - Indicator Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
 
int OnInit(){
⋮
      Print("FAILED TO INIT ATR INDICATOR");
      return (INVALID_HANDLE);

Invalid return code.

Perhaps you should read the manual. OnInit - Event Handling - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

   return(INIT_SUCCEEDED);
Correct return code.
 
William Roeder #:

Invalid return code.

Perhaps you should read the manual. OnInit - Event Handling - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

Correct return code.

Thank you for pointing out this error. I have already fixed it, but my issue still remains. I hoped that someone would help me find my mistake causing this behavior. 

 
suvroc #:

Thank you for pointing out this error. I have already fixed it, but my issue still remains. I hoped that someone would help me find my mistake causing this behavior. 

Since I don't see the rest of your code...

It might be related to this:

   ArraySetAsSeries(indicator1, true);
   ArraySetAsSeries(indicator2, true);
Try setting it to false and see if it matches then.



 
Dominik Christian Egert #:
Since I don't see the rest of your code...

It might be related to this:

Try setting it to false and see if it matches then.



I have tried but there was no result. I have uploaded all the source code of the indicator and EA if you want to see the whole code.
 
Dominik Christian Egert #: Try setting it to false and see if it matches then.

Or set it to true, before filling the arrays.

 
William Roeder #:

Or set it to true, before filling the arrays.

 Tried it too, values stays the same. As far as I can deduce buffer 1 of the indicator and iCustom's buffer 1 are showing nearly the same values, difference, I think, is coming from the fact that I am reading values at 23.30 , 30 minutes before daily bar close. But buffer the difference between buffer 0 of the indicator and iCustom is just too big, nearly 2x difference.