EA calcultions are always 1 bar behind Indicator values

 

Hello everyone;

Over the last few months I have managed to become a little more proficient at programming, thanks mainly to the great tips on this forum and the comments by some of you (thank you!!!!).

However, I seem to constantly get stuck in a situation where my EAs are in effect one (and sometimes 2) bars behind the actual value of the iCustom indicators that I am refererencing.

I use a new bar control for my EAs, so that it only runs on each new bar for the particular time frame.

Is this a common problem? It seems to occur to me irrespective of the Indicator I use and now that I am using a Heiken Ashi algorithm, 1 or 2 bars delays makes a lot of difference. The frustratng thing is that the Indicator values are spot on - they reflect what is shown on the chart for the particular bar. But at the same time, the values that the EA retrieves are behind by 1 or 2.

Hopefully I am just making a simple silly error and its not a systemic issue. Any one have any suggestions??


many thanks in advance

 

If your call looks something like the below: With the 1 at the end.

iCustom("EURUSD",0,"Dummy_Indicator",0,1);
Then yeah the lagg is normal. Anything else, then I recommend you utilize allot of print statements within both EA and Indicators.
 
ubzen:

If your call looks something like the below: With the 1 at the end.

Then yeah the lagg is normal. Anything else, then I recommend you utilize allot of print statements within both EA and Indicators.


instead of the "1" I have a variable called "BarShift", which executes on each new bar. This should be the same as "zero" in the shift parameter. I use "BarShift + 1" to get a one bar shift.

I suspect its to do with the IndicatorCounted() command in the Indicator, in that it returns the count of bars minus one interacting with my barshift control.

Any thoughts?

 
Drop BarShift from the indicator, totally unnecessary.