I have a weird issue and was hoping your could shed some light on it. I am sure I am missing something very obvious. I have a function that is called when the user clicks the chart. In that function, it checks Close[0] to get the last quoted price. Weirdly, that quoted price, in this instance (in my testing last few hours on NQ), is always 7537.25, yet the current price is far from that. Around 7566. if I print Close[0] in onbarupdate, I get the correct price. If I do not call that function immediately, but leave it until the next bar, I get the correct price! I have worked around the issue by setting a global variable in OnBarUpdate, i.e. currentPrice = close[0]. This is the only place currentPrice is set.
In OnBarUpdate
currentPrice = Close[0];
In the function, I use the following for debug
Print(Close[0].ToString() + "-" + currentPrice.ToString());
But, I get this!
7537.75-7568
I'm a bit dumfounded by this. Are there instances where Close[0] will not report valid data for the last price? Perhaps in a new thread? (I am using events attached to the mouse click to trigger the function). Close[0] is OK to be used outside of OnBarUpdate? For clarity, this is a single series nq chart, with indicator set to onPriceUpdate.
What am I missing?
Thanks.
Comment