Different value of indicator received from API compared to value shown on tester during backtest

 

Hi,

I am using ADX indicator and the values I received at the time of execution of trade was 69 and 72 for 2 consecutive bars (increasing), while the values shown in tester for that trade was 62.5 and 58 (reducing).

I have observed the same for other indicators also (Bollinger bands, MACD, EMA etc). Because of this reason, I am getting trades where I don't expect and my strategy is failing every time.

For ADX, I used main value from buffer 0 and extracted 3 values from buffer 0 with shift 0. Below is the code:

   adxHandle = iADX(_Symbol, _Period, ADX_Period);

   CopyBuffer(adxHandle, 0, 0, 3, iMABuffer);

   double adxValue[3];

   adxValue[0] = iMABuffer[0];

   adxValue[1] = iMABuffer[1];

   adxValue[2] = iMABuffer[2];

Please suggest what could be the issue

.

Thanks

Vinayak.

 

In case of Bollinger band, in some cases I also got absurd values where upper value is smaller than lower value.

Below is the code I used for Bollinger Bands:

   bbHandle = iBands(_Symbol, _Period, BB_Period, i, BB_Deviation, PRICE_CLOSE);

   CopyBuffer(bbHandle, 0, 0, 3, iMABuffer);

   bb_upper[i] = iMABuffer[1];

   bb_lower[i] = iMABuffer[2];


Please suggest.

Regards

Vinayak

 
Shift 0 continues to change until the bar is closed. I strongly suggest to start checking values from shift 1 (last closed candle). 

These values will never change into the future and will be consistent from what you see on chart and what you retrieve with iADX or iBands commands.