NinjaTrader Support Forum  

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 10-03-2010, 09:06 AM   #1
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default Backtesting Problem - Code or software problem?

I'm currently using Ninjatrader 7.0.0.16 to backtest a strategy.

I'm finding that I get some very strange results when backtesting. here is a list of some of the problems:

  • For some reason the system exits the market at 16:00 (GMT) on numerous occassions for no reason. It also exits at a price that is often very different from the market price at the time of exit.
  • If I run the backtest for a different period i.e. for just a week as opposed to the entire year, I get different entry and exits.
I can't see anything wrong with the code. Am I experiencing bugs with the software or could it be something else?

Many thanks

Mark

[IMG]file:///C:/Users/user/AppData/Local/Temp/moz-screenshot.png[/IMG]
MJUK10 is offline  
Reply With Quote
Old 10-03-2010, 11:27 AM   #2
MarkT
Junior Member
 
Join Date: Aug 2010
Posts: 13
Thanks: 0
Thanked 0 times in 0 posts
Default

I was consider upgrade to version beta 22 ... there were big improvements after beta 17
MarkT is offline  
Reply With Quote
Old 10-03-2010, 11:28 AM   #3
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default

Thanks Mark...I'll give it a try.
MJUK10 is offline  
Reply With Quote
Old 10-03-2010, 01:00 PM   #4
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 90 times in 82 posts
Default

MJUK10, yes you'll have to upgrade to the latest beta because there were many changes made between beta 22 and beta 16 in the backtesting area. Please let us know if the issue persists after the update - also, read the upgrade instructions carefully, there could be something specific relating to your update path.
NinjaTrader_Austin is offline  
Reply With Quote
Old 10-10-2010, 08:51 AM   #5
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default

Austin. I updated to the latest version and it still did not work so I rolled the code back to an ealier version where the bug wasn't present and started again.

However, after getting it working I seem to have found another bug! All I did was insert the following code at the beginneing (initialize section) to make reference to different timeframes.

Quote:

Add(PeriodType.Minute, 60);
Add(PeriodType.Day, 1);
I then backtested on the same conditions to make sure there was no problem and the backtesting results were dramtically different. It should not have any affect what so ever as I havn't refered to the code yet.

I like Ninjatrader and want to use it to trade live in due course but i'm beginning to lose faith in the software due to all these random errors. Can you give me any explanation why this might happen?
MJUK10 is offline  
Reply With Quote
Old 10-11-2010, 04:54 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

Mark, it will have an effect, even if just added, as the OnBarUpdate() would still be called for those timeframes as well, if you don't return out specifically or filer by the BarsInProgress, please see the SampleMultiTimeFrame or SampleMultiInstrument as examples.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 10-17-2010, 09:21 AM   #7
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default

Bertrand

I was under the impression it they would only have an affect when the specific bararray is made reference to in the code. What you're saying if I understand it correctly is the entire code will be processed over all the called time frames? How to i stop this?

Thanks

Mark
MJUK10 is offline  
Reply With Quote
Old 10-17-2010, 10:16 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

The OnBarUpdate() is called for all added series, you can just add a print to it to see the sequence of calls - Print(Time[0] + " BIP " + BarsInProgress);

You would need to work with if sets to only execute logic on a specific BarsInProgress being called :

if (BarsInProgress == 0)
{
do calcs if OBU is called from primary series
}

else return; // return out if called from another BIP
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 10-17-2010, 10:46 AM   #9
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default

so

I just add

if (BarsInProgress == 0)
{
enitre code
}

Or would I have to add BarsInProgress ==0 to each if statement?

I am assuming BarsinProgress 0 is equal to the default period and BarsinProgress 1 to array 1 etc etc
MJUK10 is offline  
Reply With Quote
Old 10-17-2010, 10:54 AM   #10
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

Hello MJUK10,

You just need one BarsInProgress check, and can use multiple if statements within.

if (BarsInProgress == 0)
{
enitre code
}

Yes, BIP 0 is the series that the strategy is run against. BIP 1 is the first added series.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 11-07-2010, 06:31 AM   #11
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default

Hi guys. I'm still having small issues with this. Could you give some advice please? Backtestting results are still marginally different when I put the extra arrays into the code. My code is as follow:

Quote:

protectedoverridevoid Initialize()
{
CalculateOnBarClose =
true;
Add(PeriodType.Minute,
60);
Add(PeriodType.Day,
1);



}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()

{

if (BarsInProgress == 0)
{







PROGRAM CODE


}

}
}}
As far as I can see, this should mean the all the code within the BarsInProgress brackets should only trigger on the default timeframe? Based on this, I can't understand where the different results are coming from.
MJUK10 is offline  
Reply With Quote
Old 11-07-2010, 12:27 PM   #12
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 90 times in 82 posts
Default

MJUK10, can you please post the code you're using so we can test this out?
NinjaTrader_Austin 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
problem with backtesting worldfxsignals Version 7 Beta General Questions & Bug Reports 3 03-02-2010 03:26 PM
backtesting problem worldfxsignals Version 7 Beta General Questions & Bug Reports 1 02-25-2010 09:51 AM
backtesting problem kaywai Strategy Development 25 12-17-2009 01:06 PM
Problem backtesting spacebalts67 Strategy Analyzer 3 06-28-2008 09:35 PM
Software freezing problem oriondesign Miscellaneous Support 1 06-01-2007 09:47 AM


All times are GMT -6. The time now is 12:53 PM.