Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Debugging Backtesting Entries
Collapse
X
-
Debugging Backtesting Entries
I am having a problem with strategies I have developed. For example, when I backtest and discover an entry on 12/9/2011 for example. I add a print, and set the end date to 12/9/2011. The strategy runs but does not produce an entry. If I set the end date to 12/12/2011, then an entry is produced, but it already one day into the trade, and the intermediate debug information is never printed. What am I doing wrong?Tags: None
-
Code sample
I run this with default parameters, on symbol IJR from 1/1/2009 to 12/9/2011.
The last print shown below:
12/7/2011 11:00:00 PM True : 0.000319733582671233 >= -0.000316299490147524 -0.00102319152946961 -0.00216533075753313
12/8/2011 11:00:00 PM False : 0.000701294134699992 >= 0.00101144049000936 0.000319733582671233 -0.000316299490147524
12/9/2011 11:00:00 PM False : 0 >= 0.00182418701002328 0.000701294134699992 0.00101144049000936
now with dates 1/1/2009 to 12/12/2011 print is
12/7/2011 11:00:00 PM True : 0.000319733582671233 >= -0.000316299490147524 -0.00102319152946961 -0.00216533075753313
12/8/2011 11:00:00 PM False : 0.000701294134699992 >= 0.00101144049000936 0.000319733582671233 -0.000316299490147524
12/9/2011 11:00:00 PM True : 0.00387286108994545 >= 0.00331807196658401 0.000701294134699992 0.00101144049000936
future entry ZQ 03-12 Globex 4167 N = 168
>>>>>>>>>> ZQ 03-12 Globex 12/9/2011 ENTER LONG: quantity 168 ATR 0.0042946247398297 MFI -37.6374619236986 -54.3016093781112 smoothedMFI -65.9511320047251 ACVal 0.00213759328556882 ac1 0.00179928629058366 SSV 34.3948399211687 SSR 24.1478887333829
>>>>>>>>>> ZQ 03-12 Globex 12/9/2011 Long Trade: quantity 168 ATR 0.0042946247398297 MFI -37.6374619236986 -54.3016093781112 smoothedMFI -65.9511320047251 ACVal 0.00213759328556882 ac1 0.00179928629058366 SSV 34.3948399211687 SSR 24.1478887333829 LongStopPrice 99.91 fill: 99.92 Cost 16786.56
12/12/2011 11:00:00 PM False : 0 >= 0.00204163314212091 0.00387286108994545 0.00331807196658401
>>>>>>>>>> ZQ 03-12 Globex 12/9/2011 In market long: 12/12/2011 quantity 168 ATR 0.0042946247398297 MFI -37.6374619236986 -54.3016093781112 smoothedMFI -65.9511320047251 ACVal 0.00213759328556882 ac1 0.00179928629058366 SSV 34.3948399211687 SSR 24.1478887333829 LongStopPrice 99.91 fill: 99.92 Cost 16786.56 ExitPrice 99.92 Close 99.92 profit 0 account 300000
trades 1 Total Shares : 168 Average Price 99.92
12/12/2011 11:00:00 PM 2/5/2012 9:11:54 PMAttached Files
Comment
-
Your strategy uses COBC = false; thus, in live or quasi-live trading, allowing entry on the bar on which an entry condition becomes true. Backtesting must needs use COBC = true, due to the lack of granularity when one has only 4 values (OHLC) to identify a bar, meaning that there is no intrabar information.
If COBC = true, entry can only occur on the next bar which opening event is the coincident confirming event for the close of the previous bar.
Comment
-
Thanks. I have tried your suggestion and the results are the same. I have had different results in the past using COBC = false. At the end of the bar, a message was printed showing an entry on that day. That message is no longer reached. I have had similar experience when I was using candle sticks
Comment
-
rocketman,
COBC = true essentially in back testing always even if you set it differently. The reason for this is the lack of intra-bar granularity. As such this behavior is expected. If you would like to add intrabar granularity you can use the following reference sample.
You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this byAdam P.NinjaTrader Customer Service
Comment
-
Do I need intrabar data for this to work. When I tried the code by adding the snippet from the file, my prints no longer come out at all.
I have another question as well. If you look at the prints I put in the body of a previous post, you will see that the calculations for the backtest ending on 12/9/2011 are not correct. The logical value false says the strategy did not enter, and the indicator values that follow it are the values that are involved in the logical values calculation.
When one additional bar is added, the values printed out now change. the logical value for 12/9/2011 is now true, and the indicators are consistent with that new value. How is that possible?
Thanks.Last edited by rocketman75; 02-06-2012, 06:33 PM.
Comment
-
rocketman75,
Best recommendation we have for your strategy is to simplify it. You have almost 200 lines of variables, and if it's not working the way you expect, it's best to reduce the complexity until its at a point where you can follow its behavior. Once you are confident with behavior of a simple strategy, then add additional complexity and verify once more.Ryan M.NinjaTrader Customer Service
Comment
-
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
647 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
573 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|
Comment