NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 02-05-2012, 05:08 PM   #1
rocketman75
Junior Member
 
Join Date: Dec 2008
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default 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?
rocketman75 is offline  
Reply With Quote
Old 02-05-2012, 06:51 PM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

rocketman,

If you could post you code, it would help in solving your issue.

Unfortunately without seeing if I cannot comment further.

Please let me know if I may assist further.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 02-05-2012, 08:13 PM   #3
rocketman75
Junior Member
 
Join Date: Dec 2008
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default 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 PM
Attached Files
File Type: cs BollingerBaseLine.cs (98.4 KB, 3 views)
rocketman75 is offline  
Reply With Quote
Old 02-06-2012, 12:01 AM   #4
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,201
Thanks: 24
Thanked 1,227 times in 998 posts
Send a message via Skype™ to koganam
Default

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.
koganam is offline  
Reply With Quote
The following user says thank you to koganam for this post:
Old 02-06-2012, 04:31 AM   #5
rocketman75
Junior Member
 
Join Date: Dec 2008
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default

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
rocketman75 is offline  
Reply With Quote
Old 02-06-2012, 07:58 AM   #6
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

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.

http://www.ninjatrader.com/support/f...ead.php?t=6652
NinjaTrader_AdamP is offline  
Reply With Quote
Old 02-06-2012, 05:06 PM   #7
rocketman75
Junior Member
 
Join Date: Dec 2008
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default

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 at 05:33 PM.
rocketman75 is offline  
Reply With Quote
Old 02-07-2012, 07:26 AM   #8
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

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.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-07-2012, 04:23 PM   #9
rocketman75
Junior Member
 
Join Date: Dec 2008
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks. I had guessed that was my best course of action. I appreciate your help.
rocketman75 is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Backtesting strategy doesn't yield enough entries JimTrader75 Strategy Development 4 01-27-2012 06:32 PM
Backtesting with Bid Ask entries? kenb2004 Strategy Development 9 01-03-2011 05:16 AM
NT 7 Backtesting: How to Backtest Short and Long futures entries on Same Day ChiTrader2000 Version 7 Beta General Questions & Bug Reports 5 11-29-2010 08:32 AM
Debugging & Backtesting Sienna General Programming 9 11-23-2008 09:34 AM
Entries: 1 Bar Slower when backtesting samuelg Strategy Development 2 04-13-2008 07:01 PM


All times are GMT -6. The time now is 08:43 AM.