I am accessing intra-bar data by using a secondary tick series, but have also noticed that the strategy can behave a bit differently with tick replay enabled as well. Usually the difference isn't large but enough to worth mentioning. I would have suspected that if the entry detection was truly occurring intra-bar (time series), then the tick-replay shouldn't have any effect.
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
Market Orders used during Backtesting
Collapse
X
-
Market Orders used during Backtesting
I have noticed that when I am detecting a trade entry intra-bar, the actual market order isn't firing until the next open bar (time series). Now I know that I detect the entry in the bar prior because I am drawing a up/down arrow at the bar/price in which the entry is detected. But I dont understand why the market order still shows entry at the open of the next bar.
I am accessing intra-bar data by using a secondary tick series, but have also noticed that the strategy can behave a bit differently with tick replay enabled as well. Usually the difference isn't large but enough to worth mentioning. I would have suspected that if the entry detection was truly occurring intra-bar (time series), then the tick-replay shouldn't have any effect.Tags: None
-
Hello BraisedInBlue,
I can say for certain that if Calculate is OnEachTick or OnPriceChange in real-time and a market order is submitted before the bar closes, that order will fill intra-bar.
With historical, 1 tick intra-bar granularity is required for the orders to have 1 tick accuracy with fill prices, and orders must be submitted to the BarsInProgress index of that 1 tick series.
If an order is showing on the next bar then the order was submitted after the bar closes, or the order was submitted in historical data without being submitted to a 1 tick series.Chelsea B.NinjaTrader Customer Service
-
I believe I was using either a 50 tick or 5 tick series, but I will try a 1 tick series to see if that changes anything in historical back-testing.
Comment
-
So I tried this out with the 1 tick series, and submitted the order against the 1 tick series, with no change. The attached screenshot highlights the behavior. The arrows are drawn right before submitting the order. Unfortunately this is highlighting two issues. First, the order should have been submitted sooner, this can be tested by running the strategy real-time with market replay.
I believe the issue is that the entry processing is occurring during the time-series barInProgress, and thus the entry checking isn't going to execute due to the fact that the entry checking is across multiple bars (current and into the past).
Am I correct in saying that even with 1 Tick series data, if you are in OnBarUpdate() called from the primary time-series bar (barInProgress == 0), its series data (OCHLV, I am using Close[0] as what I thought should be the Last traded price if I am seeing intra-bar data on the time-series stream) is still going to reflect the previously complete bar, and not the un-closed bar we are currently in?
And to take this one step further, if I force call Update() on any of my dataProcessors/Analyzers (Indicators), if we are in barInProgress == 0, they too will use the outdated data?Last edited by BraisedInBlue; 12-28-2020, 08:00 AM.
Comment
-
Ironically, after testing some of this out in Market Replay mode, I determined with the debugger that my intended behavior is correct within the back-test, but for some reason the draw of the arrow is aligned to previous bar, even though it is called with 0 Bars ago as the barsAgo parameter.
When looking at how this operates in real-time via Market Replay mode, the order is significantly delayed (It should fire at the open of the bar as pictured above) however it doesn't fire until later in the bar. I am looking into this now, but it appears this is working as intended.
Comment
-
Hello BraisedInBlue,
The orders must be submitted to the bars in progress of the 1 tick series.
EnterLong(int barsInProgressIndex, int quantity, string signalName)
The orders must be submitted before the bar closes, which means the condition that submits the order must evaluate as true before the bar closes.Chelsea B.NinjaTrader Customer Service
Comment
-
To make my description clear, I am submitting the order against BarsIndex=1, but the processing the submits the order occurs within OnBarUpdate() with BarsInProgress == 0.
Comment
-
It is set to OnPriceChange, but in real-time replay mode, tick replay is disabled (I assumed it didnt do anything in playback mode anyways). I will caveat this by saying that the order is firing intra-bar (in replay mode), but its not at the beginning of the open bar like I believe it should be.
When debugging the back-test, (with no tick replay, but a secondary tick series), the order is firing at the open of the bar and conditions are met (my original assumption in posting this was that the position of the draw was good, and the order placement was wrong. But after digging with the debugger, it appears that the reverse is true. The order triggers under the right conditions, but the bar the draw is attached to is off).
Comment
-
Looks like now I am hitting a debug assertion randomly. Not sure what has changed, but I cant back-test at all right now.
at NinjaTrader.NinjaScript.StrategyBase.SubmitStopTar get(Position position, Order order, StopTarget stopTarget, Execution entryExecution, Boolean changeQuantity)
at NinjaTrader.NinjaScript.StrategyBase.AddExecution( Position position, Execution execution, Order order)
at NinjaTrader.NinjaScript.StrategyBase.FillOrder(Ord er order, Double fillPrice, Double slippage)
at NinjaTrader.NinjaScript.DefaultFillType.OnBar()
at NinjaTrader.NinjaScript.StrategyBase.ProcessBackte stOrders()
at NinjaTrader.NinjaScript.StrategyBase.OnOnBarUpdate (Boolean[] toProcess)
at NinjaTrader.NinjaScript.NinjaScriptBase.Update(Int 32 idx, Int32 bip)
at NinjaTrader.NinjaScript.NinjaScriptBase.TickReplay OrUpdate()
at NinjaTrader.NinjaScript.NinjaScriptBase.SetState(S tate state)
at NinjaTrader.Gui.NinjaScript.StrategyRenderBase.Set State(State state)
at NinjaTrader.NinjaScript.StrategyBase.RunBacktestIn ternal()
at NinjaTrader.NinjaScript.Optimizers.Optimizer.RunBa cktest(StrategyBase template, Parameter[] parameters)
at NinjaTrader.NinjaScript.Optimizers.Optimizer.<>c__ DisplayClass65_0.<WaitForIterationsCompleted>b__1( )
at System.Windows.Threading.ExceptionWrapper.Internal RealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatch When(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.Invok eImpl()
at System.Threading.ExecutionContext.RunInternal(Exec utionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run( CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invok e()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(In tPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation( Object o)
at System.Windows.Threading.ExceptionWrapper.Internal RealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatch When(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeIm pl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl( DispatcherFrame frame)
at NinjaTrader.NinjaScript.Optimizers.Optimizer.<>c__ DisplayClass60_1.<SetState>b__1()
at System.Threading.ExecutionContext.RunInternal(Exec utionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Comment
-
Hello BraisedInBlue,
Calculate will always be OnBarClose if TickReplay is not enabled.
"On a historical data set, only the OHLCVT of the bar is known and not each tick that made up the bar. As a result, State.Historical data processes OnBarUpdate() only on the close of each historical bar even if this property is set to OnEachTick or OnPriceChange. You can use TickReplay or a Multi-time frame script to obtain intrabar data."
This means orders will be submitted with the primary bar fully closes. Since the order is submitted after the bar is closed, it is submitted at the open of the new bar.
Regarding the error, does this occur with the SampleMACrossover strategy included with NinjaTrader?
Are you using 8.0.23.2?Chelsea B.NinjaTrader Customer Service
Comment
-
So far it seems its tied to trying to run my strategy at the 1 minute time series as the primary data series without tick replay on. The sample does not have the assertion failure, nor does running at a higher time-series. It doesn't occur with the sample strategy.
Also, I dont believe what you quoted above is entirely true. If it were true, using a secondary time series with ticks, shouldn't change the results of backtesting at all if the primary series is a time-series. But it absolutely does change the results, and it causes slightly different entries and exits (prices) depending on the tick size of the secondary series.
However, the results will also change when enabling tick replay (in back-testing), all-else remaining equal. But I am unsure why the behavior is different between a tick-replay back-test and a real-time market replay test of an identical trade.Last edited by BraisedInBlue; 12-28-2020, 10:10 AM.
Comment
-
Hello BraisedInBlue,
Are you using 8.0.23.2?
(Help -> About)
May I test this on my end to see if I am able to reproduce?
To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:- Click Tools -> Export -> NinjaScript...
- Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
- Click the 'Export' button
- Enter a unique name for the file in the value for 'File name:'
- Choose a save location -> click Save
- Click OK to clear the export location message
- (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
http://ninjatrader.com/support/helpG...-us/export.htm
Once exported, please attach the file as an attachment to your reply.
On what date, instrument, bar type, and interval are you testing this with Playback using Market Replay data?
Chelsea B.NinjaTrader Customer Service
Comment
-
I am using 8.0.23.2, and I am not necessarily comfortable sharing source code. But that doesnt mean I am not willing to help try to narrow down the issue / replicate it over email.
Comment
-
Hello BraisedInBlue,
Create a demonstrate script that can reproduce the behavior.
Do not include your custom logic. Only include the bare minimum necessary to reproduce the error.
As a suggestion, if it was working previously, remove any recent changes.Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by mly916, Today, 09:48 PM
|
0 responses
10 views
0 likes
|
Last Post
by mly916
Today, 09:48 PM
|
||
Started by Mikey_, Today, 09:21 PM
|
0 responses
11 views
0 likes
|
Last Post
by Mikey_
Today, 09:21 PM
|
||
Started by cre8able, Today, 05:53 PM
|
3 responses
13 views
0 likes
|
Last Post
by cre8able
Today, 09:20 PM
|
||
Started by Aryan Kumar, Today, 09:04 PM
|
0 responses
4 views
0 likes
|
Last Post
by Aryan Kumar
Today, 09:04 PM
|
||
Started by yertle, Yesterday, 05:49 PM
|
3 responses
16 views
0 likes
|
Last Post
by Mindset
Today, 08:38 PM
|
Comment