NexusFi: Find Your Edge


Home Menu

 





executing strategy in backtesting


Discussion in NinjaTrader

Updated
    1. trending_up 6,294 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 11 posts
    2. attach_file 2 attachments




 
Search this Thread

executing strategy in backtesting

  #1 (permalink)
cicondo
Munich
 
Posts: 6 since Apr 2011
Thanks Given: 1
Thanks Received: 1

Hi guys,

I find out a strange behaviour between a strategy which is working well in realtime or marketreplay, but NOT
in backtesting mode.
The problem is, that an indicator, I wrote, send changes with events to any listener (strategy). The creation of that indicator will be done within the initialize method of the strategy and added to the indicators list. I real mode the indicator is updated on every OnBarUpate, but in backtesting the method of the indicator will never be called. I tried to debug this kind of code but I cannot see any fault.

Does anyone know this problem? And is there a solution for this?

Here is a part of code, so it's easier to follow my description:

protected override void Initialize()
{

indi = DDF(AtrPeriod, SessionEnds, Duration, Session, StartTime, 65.0);
indi.OnLimitOrder += new LimitOrderHandler(OnLimitOrder);
indi.OnModifyLimit += new ModifyLimitHandler(OnModifyLimit);
indi.OnModifyStop += new ModifyStopHandler(OnModifyStop);
indi.OnScaleOutOrder += new ScaleOutOrderHandler(OnScaleOutOrder); Add(indi);
indi.OnCancelOrder += new CancelOrdersHandler(OnCancelOrder);
indi.OnNewSession += new NewSessionHandler(OnNewSession);
Target1 = 15;
Target2 = 25;
Target3 = 35;
StoppLoss = 30;
CalculateOnBarClose = true;

TraceOrders = true;
}


void OnNewSession(object sender, TimeSpan start, TimeSpan duration, TimeSpan sessionEnd)
{
_currentTrendDirection = SessionKind.Sideway;
_currentStop = 0;
_currentLimit = 0;
_executedNewLimitOrder = false;
_firstOrder = false;
_unfilledNewLimitOrder = false;

}


Hope that helps to make things clear.

Thx
Markus

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Trade idea based off three indicators.
Traders Hideout
REcommedations for programming help
Sierra Chart
Increase in trading performance by 75%
The Elite Circle
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (permalink)
 
redratsal's Avatar
 redratsal 
Milan (I)
 
Experience: Advanced
Platform: Ninjatrader
Broker: Kinetick
Trading: FDAX,6E,CL,YM,NQ,ES
Posts: 1,648 since Oct 2010
Thanks Given: 1,215
Thanks Received: 2,090


cicondo View Post
Hi guys,

I find out a strange behaviour between a strategy which is working well in realtime or marketreplay, but NOT
in backtesting mode.
The problem is, that an indicator, I wrote, send changes with events to any listener (strategy). The creation of that indicator will be done within the initialize method of the strategy and added to the indicators list. I real mode the indicator is updated on every OnBarUpate, but in backtesting the method of the indicator will never be called. I tried to debug this kind of code but I cannot see any fault.

Does anyone know this problem? And is there a solution for this?

Here is a part of code, so it's easier to follow my description:

protected override void Initialize()
{

indi = DDF(AtrPeriod, SessionEnds, Duration, Session, StartTime, 65.0);
indi.OnLimitOrder += new LimitOrderHandler(OnLimitOrder);
indi.OnModifyLimit += new ModifyLimitHandler(OnModifyLimit);
indi.OnModifyStop += new ModifyStopHandler(OnModifyStop);
indi.OnScaleOutOrder += new ScaleOutOrderHandler(OnScaleOutOrder); Add(indi);
indi.OnCancelOrder += new CancelOrdersHandler(OnCancelOrder);
indi.OnNewSession += new NewSessionHandler(OnNewSession);
Target1 = 15;
Target2 = 25;
Target3 = 35;
StoppLoss = 30;
CalculateOnBarClose = true;

TraceOrders = true;
}


void OnNewSession(object sender, TimeSpan start, TimeSpan duration, TimeSpan sessionEnd)
{
_currentTrendDirection = SessionKind.Sideway;
_currentStop = 0;
_currentLimit = 0;
_executedNewLimitOrder = false;
_firstOrder = false;
_unfilledNewLimitOrder = false;

}


Hope that helps to make things clear.

Thx
Markus

Hi,

That is a limit of backtesting with NT, you cannot go lower than the actual bar granularity like in real time (in BT only works OBC), if you search there are plenty of threads on this issue, a turn around would be to adapt your strategy to 1 tick granularity.

Sorry Mate

Visit my NexusFi Trade Journal Reply With Quote
  #3 (permalink)
cicondo
Munich
 
Posts: 6 since Apr 2011
Thanks Given: 1
Thanks Received: 1



redratsal View Post
Hi,

That is a limit of backtesting with NT, you cannot go lower than the actual bar granularity like in real time (in BT only works OBC), if you search there are plenty of threads on this issue, a turn around would be to adapt your strategy to 1 tick granularity.

Sorry Mate

Thanks for your answer.

I know the problems BT in NT, but this is not the core problem. The indicators OnBarUpdate should be called each time a new bar is build, but isn't. The strategie's Update-Method is getting called correctly.

Thx
Markus

Reply With Quote
  #4 (permalink)
 
redratsal's Avatar
 redratsal 
Milan (I)
 
Experience: Advanced
Platform: Ninjatrader
Broker: Kinetick
Trading: FDAX,6E,CL,YM,NQ,ES
Posts: 1,648 since Oct 2010
Thanks Given: 1,215
Thanks Received: 2,090


redratsal View Post
Hi,

That is a limit of backtesting with NT, you cannot go lower than the actual bar granularity like in real time (in BT only works OBC), if you search there are plenty of threads on this issue, a turn around would be to adapt your strategy to 1 tick granularity.

Sorry Mate

How did you debug, did you try with print and outputwindow?

Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
cicondo
Munich
 
Posts: 6 since Apr 2011
Thanks Given: 1
Thanks Received: 1


redratsal View Post
How did you debug, did you try with print and outputwindow?

Hi,

I printed some information with print and debugged it with Visual Studio to follow the event handling.
I can see, that an instance of the indicator exists, with the listener for the event.

One side effect is, that all the other indicators I used and added to the strategy (ATR and MACD) have the same problem, they will not beeing updated. Really scary

Markus

Reply With Quote
  #6 (permalink)
 
redratsal's Avatar
 redratsal 
Milan (I)
 
Experience: Advanced
Platform: Ninjatrader
Broker: Kinetick
Trading: FDAX,6E,CL,YM,NQ,ES
Posts: 1,648 since Oct 2010
Thanks Given: 1,215
Thanks Received: 2,090


cicondo View Post
Hi,

I printed some information with print and debugged it with Visual Studio to follow the event handling.
I can see, that an instance of the indicator exists, with the listener for the event.

One side effect is, that all the other indicators I used and added to the strategy (ATR and MACD) have the same problem, they will not beeing updated. Really scary

Markus

I suggest you use the output window of NT it is integrated with your charts; print as much information as possible and compare backtested vs realtime, make also sure the session templates are the same. Sorry I can't help don't have enough information.

Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,442 since Jun 2009
Thanks Given: 33,215
Thanks Received: 101,602


cicondo View Post
Hi,

I printed some information with print and debugged it with Visual Studio to follow the event handling.
I can see, that an instance of the indicator exists, with the listener for the event.

One side effect is, that all the other indicators I used and added to the strategy (ATR and MACD) have the same problem, they will not beeing updated. Really scary

Markus

What version of NT? I saw all kinds of similar problems with 6.5.

Is this MTF within the strategy (multiple bars series?)?

Start a new project with only minimalist code, see if the problem persists at the most basic and simple level possible.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #8 (permalink)
cicondo
Munich
 
Posts: 6 since Apr 2011
Thanks Given: 1
Thanks Received: 1


Big Mike View Post
What version of NT? I saw all kinds of similar problems with 6.5.

Is this MTF within the strategy (multiple bars series?)?

Start a new project with only minimalist code, see if the problem persists at the most basic and simple level possible.

Mike

Hi Mike,

thx fro your answer. It will not work with NT7 1000.4. But I think you're right. I'll do this with a very simple system to figure out the problem.

Markus

Reply With Quote
  #9 (permalink)
cicondo
Munich
 
Posts: 6 since Apr 2011
Thanks Given: 1
Thanks Received: 1


Big Mike View Post
What version of NT? I saw all kinds of similar problems with 6.5.

Is this MTF within the strategy (multiple bars series?)?

Start a new project with only minimalist code, see if the problem persists at the most basic and simple level possible.

Mike

Hi Mike,

now I have a really simple projekt, but it shows the same problems. Please have a look at the attached both files.
Hope you can see the fault, otherwise it is a bug to report to NT.

Cheers
Markus

Attached Files
Elite Membership required to download: EMACrossEvent.cs
Elite Membership required to download: EMACrossStrategy.cs
Reply With Quote
Thanked by:
  #10 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,442 since Jun 2009
Thanks Given: 33,215
Thanks Received: 101,602



cicondo View Post
Hi Mike,

now I have a really simple projekt, but it shows the same problems. Please have a look at the attached both files.
Hope you can see the fault, otherwise it is a bug to report to NT.

Cheers
Markus

Hopefully someone can duplicate and help, but won't be me - I stopped using Ninja well over a year ago.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on May 5, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts