The strategy I am working on makes two entries in 1 hour time frame, and I setstoplosses individually for each entry. Once in a while, I see one entry is stopped out and the other entry is not stopped out when both should be stopped out. As a result, the backtest isn't as accurate as I'd like. What's the best way to deal with this?
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
Entry and exit in the same bar when backtesting
Collapse
X
-
Entry and exit in the same bar when backtesting
Hello,
The strategy I am working on makes two entries in 1 hour time frame, and I setstoplosses individually for each entry. Once in a while, I see one entry is stopped out and the other entry is not stopped out when both should be stopped out. As a result, the backtest isn't as accurate as I'd like. What's the best way to deal with this?
Tags: None
-
Hello op1031,
Thank you for your post.
This behavior could be caused by historical overfills occurring when using the Managed Approach in a custom NinjaScript strategy.
Something you could do is use High Order Fill Resolution along with an added 1-tick series to run backtests with intrabar granularity.
See this forum post for more information about adding intrabar granularity - https://ninjatrader.com/support/foru...ive#post773377
Or, you could modify your strategy's logic to use the Unmanaged approach to place orders and take control of those orders with OCO IDs. See the attached example script demonstrating the use of the Unmanaged Approach.
See the help guide documentation below for more information.
Discrepancies between realtime vs backtest - https://ninjatrader.com/support/help...ime_vs_bac.htm
High Order Fill Resolution - https://ninjatrader.com/support/help...fill_.htm#Unde rstandingOrderFillResolution
Unmanaged Approach - https://ninjatrader.com/support/help...d_approach.htm
Let us know if we may assist further.Attached FilesBrandon H.NinjaTrader Customer Service
-
Hi Brandon,
Thank you for the response. I am looking to add intrabar granularity. SampleIntrabarBacktest has the following comment:
/* Add a secondary bar series.
Very Important: This secondary bar series needs to be smaller than the primary bar series.
Note: The primary bar series is whatever you choose for the strategy at startup. In this example I will
reference the primary as a 5min bars series. */
Primary - 4 HOUR
Secondary - 1 HOUR
Third - 1 tick
Then I would submit my by orders in the 1 tick data series. Is this the right approach?
Comment
-
Hello op1031,
Thank you for your note.
Yes, that would be the correct way to set up the added data series. You would add the data series to your script as mentioned and submit orders to the 1-tick data series.
Please let us know if we may further assist.Brandon H.NinjaTrader Customer Service
Comment
-
Hi Brandon,
Could you let me know how I can import tick data for backtesting? when I go to Historical Data -> Load, I only see that I can import bar and not tick data.
For now, I tried using the 1-minute data as my granular intrabar; however, it seems to have the same problem. I still see the profit / stop-loss are filled incorrectly. To avoid the problem of overfill, do I need to detect stoploss and submit sell order manually instead of using setstoploss?
Comment
-
Hello op1031,
Thank you for your note.
Please see this help guide documentation regarding importing data. Note that the data being imported would need to be formatted as Tick data.
Importing Data - https://ninjatrader.com/support/help...?importing.htm
To avoid historical overfill High Order Fill Resolution should be used along with an added 1-tick series to run backtests with intrabar granularity. Or, you could modify your strategy's logic to use the Unmanaged approach to place orders and take control of those orders with OCO IDs.
See the help guide documentation in post number 2 for more information.
Let us know if we may assist further.Brandon H.NinjaTrader Customer Service
Comment
-
Hi Brandon,
So the correct way to set up the data series is
Primary - 4 HOUR
Secondary - 1 HOUR
Third - 1 tick
I am interested in knowing what exactly can go wrong if I set up the data series as
Primary - 1 HOUR
Secondary - 4 HOUR
Third - 1 tick
The reason I want to set it up like that is that the decision to make trades is in 1 HOUR, so I want to see 1 HOUR on the chart when I examine the trades. Could you explain what will go wrong if I use 1 HOUR as the primary data series?
Comment
-
Hello op1031,
Thank you for your note.
You could set up the data series in your script so that it uses a primary series of 1-Hour and adds a secondary 4-Hour series and 1-Tick series.
The note 'Very Important: This secondary bar series needs to be smaller than the primary bar series.' refers to the secondary series that you will be submitting orders to. If you are submitting orders to a 1-Tick added series, the primary series would need to be greater than 1-Tick.
Let us know if we may assist further.Brandon H.NinjaTrader Customer Service
Comment
-
Hello op1031,
Thank you for your note.
Yes, you could have your strategy run on and submit orders to a 1-Tick primary series and use the 1-Hour and 4-Hour added secondary series for your entry order conditions. Note that having the 1-Tick series as your primary series means that the strategy will run on a 1-Tick series. A 1-Tick series would also be what is displayed on the chart.
Let us know if we may further assist.Brandon H.NinjaTrader Customer Service
Comment
-
Hi NinjaTrader team,
I am resurrecting this thread because my question is related to setstoploss with High Order fill resolution.
I implemented a strategy with a primary data series, and I use setstoploss with High Order fill resolution. Everything is working fine as expected, and I am planning to add a higher time frame to check for trend confirmation. However, if I add a new data series, then I am unable to use High Order fill resolution which also means when using setstoploss I can potentially run into overfill issues as described earlier in this thread.
Does this mean that if I add multiple data series, then I am not able to rely on setstoploss anymore?
Thank you,
Comment
-
Hello op1031,
Thanks for your note.
If you are using a MultiTimeFrame strategy or Tick Replay, a single tick data series would need to be added to your script for intrabar granularity.
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/foru...mance?t=102504
Please let us know if we may be of further assistance.Brandon H.NinjaTrader Customer Service
Comment
-
Hi Brandon,
Thank you for the info. I will take a look at those.
You didn't specifically say it, but I think the answer is "yes, we can't rely on setstoploss if we have multiple data series". I come to this conclusion because setstoploss has to be submitted in the primary series and not in the series with lower granularity. Could you confirm?
Comment
-
Hello op1031,
Thanks for your note.
You would be able to use SetStopLoss/SetProfitTarget when submitting an entry order to an added secondary series. For example, if you submit an entry order with a signal name of "myEntry" to the added secondary series and called SetStopLoss/SetProfitTarget using a 'from entry signal' of "myEntry", then the Stop Loss and Profit Target would submit along with the entry order.
See the attached example script demonstrating this.
Also, see the help guide documentation below for more information.
BarsInProgress - https://ninjatrader.com/support/help...inprogress.htm
EnterLong - https://ninjatrader.com/support/help.../enterlong.htm
SetStopLoss - https://ninjatrader.com/support/help...etstoploss.htm
SetProfitTarget - https://ninjatrader.com/support/help...ofittarget.htm
Let us know if we may assist further.Last edited by NinjaTrader_BrandonH; 06-10-2021, 12:36 PM.Brandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Lele2k24, Yesterday, 11:24 AM
|
11 responses
36 views
0 likes
|
Last Post Today, 03:07 PM | ||
Started by RaygunWizzle, Yesterday, 08:52 PM
|
3 responses
11 views
0 likes
|
Last Post Today, 02:50 PM | ||
Started by Tim-c, Today, 08:36 AM
|
4 responses
14 views
0 likes
|
Last Post Today, 02:45 PM | ||
Started by JohnS52, 03-22-2024, 08:06 AM
|
4 responses
28 views
0 likes
|
Last Post
by JohnS52
Today, 02:30 PM
|
||
Started by carnitron, 03-25-2024, 01:59 PM
|
11 responses
53 views
0 likes
|
Last Post
by carnitron
Today, 02:18 PM
|
Comment