View Full Version : Identifying Close of Bar when CalculateOnBarClose = false
11-25-2007, 02:57 PM
When CalculateOnBarClose = false the user guide states that on a tick by tick strategy the only way you know when a bar is closed is when the FirstTickOfBar is true. What about interval based bars? Is there a way to know when the last tick is being processed? Why not have an attribute LastTickOfBar ??
11-25-2007, 04:53 PM
The problem is you will not know if the tick is the last tick of the bar until the first tick of the new bar. This is the case for interval based bars too. The only way we know a new 1min bar is opening is when the incoming tick comes in with a timestamp of the new 1min. Until that tick comes in we have no idea if the current tick we are handling will be the last tick of the current 1min bar.
06-16-2009, 03:50 PM
(I realize that this is an old thread, but I'm dealing with this issue now...)
Josh mentions that the only way that NT knows that a bar is closed is when the first tick of a new bar comes in.
That does not seem to jive with the fact that if CalculateOnBarClose == true, then OnBarUpdate is called with (what is in effect) the last tick of the bar.
I'm assuming that the NT internal code queues the OnBarUpdate event to the strategy code with the previous bar when it sees the first tick of a new bar and CalculateOnBarClose == true. Couldn't it do the same thing if CalculateOnBarClose == false and have a LastTickOfBar flag ?
The way things currently work makes strategy code very messy if you want to handle both settings of CalculateOnBarClose. Lots of "if" statements like:
if (CalculateOnBarClose == false && FirstTickOfBar == true) closingBarPrice = Close;
else closingBarPrice = Close;
Getting rid of the FirstTickOfBar flag and having a LastTickOfBar flag would eliminate all this messy code.
06-16-2009, 04:00 PM
CalculateOnBarClose = true triggers OnBarUpdate() events when the first tick of the next bar is received. The closing event of a bar is only determined when the next bar begins.
If you want to use CalculateOnBarClose = false you can do so and then use if(FirstTickOfBar) and then offset all your  indexing by 1. So  would be  to get the closing price of the previous bar. These are your two options available for checking the last tick of a bar.
04-20-2011, 01:43 AM
Does FirstTickOfBar work in indicators as well as strategies ?
What if the strategy/indicator has data series for multiple frames ? It seems to need an array FirstTickOfBars, so one can check each timeframe...
04-20-2011, 05:15 AM
splat, it would be applicable to both - you can check it in the respective BarsInProgress context for MultiSeries use.
04-20-2011, 07:40 AM
I am still not quite clear about how that works though. I understand that when using CalculateOnBarClose = true with multiple timeframes, OnBarUpdate will be called for each bar close, so if (say) a 1min and 5min bar close at the same time, OnBarUpdate will be called twice (with different BarsInProgress values). But if CalculateOnBarClose = false, then OnBarUpdate will be called on "each incoming tick". Does it in fact get called on each incoming tick for *each* timeframe (e.g. N times on each tick, given N timeframes), with different BarsInProgress values? Or does it get called once on each incoming tick for the primary data series, plus an extra call whenever a secondary series bar has its first tick (with different BarsInProgress value) ? (If only called exactly once for each tick, I cannot see how your suggestion would work.)
04-20-2011, 08:28 AM
When using CalculateOnBarClose = false, it will be called once for every single tick for each BarsInProgress. If you have 1min and 5min, you will have the tick processed once for the 1min and once for the 5min.
04-20-2011, 11:20 AM
Thanks, Josh, that is clear to me now.