And one more question. If I want to reference the last fully closed bar using IsFirstTickofBar, do I need to reference this last bar as [1], so that bar [0] is actually the new bar started by the new first tick?
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
IsFirstTickofBar combined with Calculate on price change
Collapse
X
-
IsFirstTickofBar combined with Calculate on price change
Hi, according to the help guide IsFirstTickofBar also works with CalculateOnPriceChange instead of OnEachTick. But what, if the first tick of the new bar is the same price as the last tick of the previous bar?
And one more question. If I want to reference the last fully closed bar using IsFirstTickofBar, do I need to reference this last bar as [1], so that bar [0] is actually the new bar started by the new first tick?Tags: None
-
Hello philmg,
Thanks for your post.
Correct, IsFirstTickOfBar works with scripts that are set to use Calculate.OnPriceChange or Calculate.OnEachTick.
This property indicates if the incoming tick is the first tick of a new bar. When IsFirstTickOfBar is true, this means the previous bar closed and a new bar is forming.
If the first tick of the new bar is the same price as the first tick of the previous bar, this means the new bar would start forming at the same price as the last tick of the previous bar since the ticks are at the same price.
To reference the previous bar inside an IsFirstTickOfBar condition, you would pass in a Bars Ago value of 1 (ex: Close[1]). To reference the currently forming bar inside an IsFirstTickOfBar condition, you would pass in a Bars Ago value of 0 (ex: Close[0]).
See the help guide documentation below for more information.
IsFirstTickOfBar: https://ninjatrader.com//support/hel...ttickofbar.htmBrandon H.NinjaTrader Customer Service
-
Thanks, understood, but one detail remains unclear. If the first tick of the new bar is the same price as the last tick of the previous bar and calculation is set to OnPriceChange, wouldn't the the calculation only execute on the next tick with a price change and skip the first tick of the new bar? If that is the case on calculation set to OnEachTick would guarantee that the calculation happens with each first tick in each bar.
Comment
-
Hello philmg,
Thanks for your notes.
When testing this on my end, I am seeing that OnBarUpdate is triggered when a new bar is formed when using Calculate.OnPriceChange and IsFirstTickOfBar.
To test this, you could add a debugging print in an IsFirstTickOfBar condition in the script that prints out something like "OnBarUpdate triggered" along with the Time[0] of the bar and test the script on a small interval, such as 1-second bars.
Below is a link to a forum post that demonstrates how to use prints to understand behavior.
https://ninjatrader.com/support/foru...121#post791121
That said, you could consider using Calculate.OnEachTick if you want to have logic processed for each incoming tick
Calculate: https://ninjatrader.com/support/help.../calculate.htmBrandon H.NinjaTrader Customer Service
- Likes 1
Comment
-
I would like to follow up on this after some comparison of live SIM testing vs the backtested trades. When I use OnPriceChange or OnEachTick and want to enter 1 tick above the high of the last closed bar, I have to reference that last bar with [1], so that the live forming bar shows the entry, when it moves above the high of the previous bar (entry bar). However, the backtested historical trades are always shown as occurring one bar later than the live trades, since they executed on the close of the bar that would have entered while the bar was forming during live trading. This is also the same when I set order fill resolution for historical order processing to high on each tick.
How can I achieve that the trades are entered the same in live and in the backtest, meaning both should should trigger when the next bar after the entry bar moves 1 tick above the high?
Comment
-
Hello philmg,
Thanks for your notes.
The Strategy Analyzer is only able to process logic OnBarClose because it does not have intrabar data available to process OnEachTick or OnPriceChange.
Please review the help guide document on the differences on real-time vs backtest (historical).
A strategy running real-time (live brokerage account, live market simulation, Playback connection etc...) will produce different results than the performance results generated during a backtest.
When in historical data, only the Open, High, Low, and Close will be available and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known.
Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.
Below is a link to the help guide on Calculate.
https://ninjatrader.com/support/help.../calculate.htm
To improve the accuracy of a backtest, you may use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar.
Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills. You would need to add a single tick data series and submit orders to that single tick data series for a strategy that uses Tick Replay.
High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.
Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information.
SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/helpGuides/nt8/backtesting_ninjascript_strate.htm
TickReplay — https://ninjatrader.com/support/help...ick_replay.htm
Developing for Tick Replay -
https://ninjatrader.com/support/helpGuides/nt8/developing_for__tick_replay.htm?zoom_highlightsub= developing+for+tick+replay
Additional information may be found in this NinjaTrader Forum post —
https://ninjatrader.com/support/forum/forum/ninjatrader-8/strategy-development/100192-comparing-real-time-historical-and-replay-performance?t=102504Brandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by mishhh, 05-25-2010, 08:54 AM
|
19 responses
6,189 views
0 likes
|
Last Post
by rene69851
Today, 09:29 AM
|
||
Started by gwenael, Today, 09:29 AM
|
0 responses
1 view
0 likes
|
Last Post
by gwenael
Today, 09:29 AM
|
||
Started by Karado58, 11-26-2012, 02:57 PM
|
8 responses
14,829 views
0 likes
|
Last Post Today, 09:09 AM | ||
Started by Option Whisperer, Today, 09:05 AM
|
0 responses
1 view
0 likes
|
Last Post Today, 09:05 AM | ||
Started by cre8able, Yesterday, 01:16 PM
|
3 responses
11 views
0 likes
|
Last Post
by cre8able
Today, 08:28 AM
|
Comment