OnBar Method Open, Close, High, and Low values

Created at 25 May 2015, 17:15
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!
BO

botmaster

Joined 24.05.2015

OnBar Method Open, Close, High, and Low values
25 May 2015, 17:15


I have a question/issue regarding the OnBar Method.

Does anyone know why the current bar's MarketSeries.Open.Last(0), Close.Last(0), High.Last(0), and Low.Last(0) values always contain the same value?

I have an indicator that uses all 4 values every time frame, but when I use those indicators in a cbot that references that indicator the values returned are completely different.  The reason is that the Open, Close, High, and Low values in the MarketSeries are the same for the most recent bar.   .

My Indicator doesn't act this way when run on its own, but when it's referenced and in a cBot the values returned by the indicator are completely different.  

I need the values from the last bar to the current bar.  I can look back one Bar by passing 1 to the Last() method, but I'm not sure that's the value I'm looking for.    

Thanks

 

 

 

 

 

 

 

 

 


@botmaster
Replies

botmaster
25 May 2015, 17:22

Just to be more clear.

I'm saying that for the current bar 

Open.Last(0) = Close.Last(0) = High.Last(0) = Low.Last(0)  which doesn't make much sense to me.     


@botmaster

JeremyG
27 May 2015, 05:29

Did you try using Open.LastValue instead of Open.Last(0) etc?


@JeremyG

botmaster
27 May 2015, 17:00

RE:

JeremyG said:

Did you try using Open.LastValue instead of Open.Last(0) etc?

Yes, that returns the same value too.

 

 

 

 


@botmaster

botmaster
27 May 2015, 23:23

RE: RE:

botmaster said:

JeremyG said:

Did you try using Open.LastValue instead of Open.Last(0) etc?

Yes, that returns the same value too.

 

 

 

 

So far I've moved my code to the OnTimer event and started the timer on the first OnBar().    This ensures that all the values are different.   They are not exactly the same as the indicator values, but they are close enough to be useful.     

 

 


@botmaster

trend_meanreversion
29 May 2015, 09:54

Just my initial cents to your initial query : 

As far as my understanding goes, OnBar() is triggered on the first tick of a new bar(unfinished) so at that time you will have Open=High=Close=Low=LastValue=CurrentTickValue . So conceptually it is returning the correct numbers but if you are interested in OHLC of previous bar ( completed ) bar then you should use Last(1) to retrieve OHLC values.

 

 


@trend_meanreversion