custom indicator access from cBot based on DateTime of the bar [not index of bar]

Created at 19 Mar 2017, 11:09
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
DE

deansi

Joined 30.10.2014

custom indicator access from cBot based on DateTime of the bar [not index of bar]
19 Mar 2017, 11:09


I have a custom indicator Im trying to use in a cbot that uses 2 TFs and makes some dots in the form of IndicatorDataSeries in history AND on the chart ahead of the current price, which draws all ok if you attach the indicator to a chart.

Accessing it from a cBot gets either the wrong dot or an empty IndicatorDataSeries entry, if I try to use the index of the

MarketSeries.Open.Count -1

to point at the right indicator series output, this would work on a standard EMA, with this custom indi it will get a NaN because the indicator doesnt start adding IndicatorDataSeries entries on the first few bars of the chart so the count is generally behind, then because it also projects between 0 to 12 bars ahead of the current actual time, I tried using instead:

myMA.Result.Count -1

this would point to the last value in the result series which is giving a value but usually not the one of the current under contruction bar but instead the most advanced indicator calculation in the list which is anywhere between for example 0 to 12 bars ahead of the bar result I want to access.

I know I can add the counting mechanism into my cbot to get it to point to the right amount of bars away from the last result bar to have the right offset, but its adding more things to go out of sync, and potential bugs, and in the future I want to know for other cases how to handle this situation.

So my question is, is there a safe way like requesting a certain DateTime of the myMA.Result series to be sure of reading the bar that I actually want? Or if someone has another suggestion.


@deansi