Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Identifying Close of Bar when CalculateOnBarClose = false
Collapse
X
-
Identifying Close of Bar when CalculateOnBarClose = false
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 ??Tags: None
-
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.Josh P.NinjaTrader Customer Service
-
(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[1];
else closingBarPrice = Close[0];
Getting rid of the FirstTickOfBar flag and having a LastTickOfBar flag would eliminate all this messy code.
Comment
-
BAltman,
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 [0] would be [1] to get the closing price of the previous bar. These are your two options available for checking the last tick of a bar.Josh P.NinjaTrader Customer Service
Comment
-
FirstTickOfBar in multi-timeframe indicator/strategy
Josh,
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...
Comment
-
Thanks, Bertrand.
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.)
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by usazencort, Today, 01:16 AM
|
0 responses
1 view
0 likes
|
Last Post
by usazencort
Today, 01:16 AM
|
||
Started by kaywai, 09-01-2023, 08:44 PM
|
5 responses
603 views
0 likes
|
Last Post Today, 12:32 AM | ||
Started by xiinteractive, 04-09-2024, 08:08 AM
|
6 responses
22 views
0 likes
|
Last Post Today, 12:31 AM | ||
Started by Pattontje, Yesterday, 02:10 PM
|
2 responses
20 views
0 likes
|
Last Post
by Pattontje
Yesterday, 11:49 PM
|
||
Started by flybuzz, 04-21-2024, 04:07 PM
|
17 responses
230 views
0 likes
|
Last Post
by TradingLoss
Yesterday, 11:45 PM
|
Comment