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-06-2008, 06:32 AM   #1
koalboy
Member
 
Join Date: Jan 2008
Location: Austria
Posts: 31
Thanks: 0
Thanked 0 times in 0 posts
Default real-time backtesting

Hi!

I created a strategy with two timeframes (primary is on 1-tick, secondary on 1 Min) on the same instrument what allows me to update the value of a dynamic stop-loss (takes its value from a custom indicator) every tick.

This is needed, because the StopLoss should take the maximum value of the indicator ever reached (calculated on every tick) since a position was entered.

In Market Replay environment the strategy behaves like expected without any problems.

But when I start a backtest with the same setup, I don't get any results and the log-tab shows me following message:

Failed to call mehtod "Initialize" for strategy "AATrailProb"; "Position" property can not be accessed from within "Initialize" method.

1. What does this mean?
2. In general: Is my logic right that I should get "near to live-trading"-behaviour of my strategy when I backtest this strategy calculating indicator values on a timeframe that should represent the live-trading-primary-bar-intervall (eg 1 Min) but letting the strategy run on a one-tick-primary-timeframe when backtesting?

I'm using the Position-method for resetting purposes within the strategy:
Here is my code:

Code:
 
#region Initialize protected override void Initialize() { Add(PeriodType.Minute, xminutes); CalculateOnBarClose = true; StopValueSCalc = new DataSeries(this); StopValueLCalc = new DataSeries(this); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> /// #endregion #region OnBarUpdate protected override void OnBarUpdate() { if (Historical) return; if (CurrentBar < 10) return; if (BarsInProgress == 1) { StopValueSCalc.Set(ATRTrailingStop(10, 1, 20, 1).ATRTrailup[0]); StopValueLCalc.Set(ATRTrailingStop(10, 1, 20, 1).ATRTraildown[0]); ResetSLL = ATRTrailingStop(10, 1, 20, 1).ATRTraildown[0]; ResetSLS = ATRTrailingStop(10, 1, 20, 1).ATRTrailup[0]; } if (BarsInProgress == 0) { #region LONG if (Closes[0][0] > Highs[0][1]) { EnterLong(DefaultQuantity, "ENTERLONG"); } if (Positions[1].MarketPosition == MarketPosition.Long) { StopValueL = Math.Max(ResetSLL, MAX(StopValueLCalc, BarsSinceEntry())[0]); SetStopLoss("ENTERLONG", CalculationMode.Price, StopValueL, false); } if (Positions[1].MarketPosition == MarketPosition.Flat) { SetStopLoss("ENTERLONG", CalculationMode.Price, ResetSLL, false); } #endregion
thx for help!!
koalboy is offline  
Reply With Quote
Old 02-06-2008, 06:47 AM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

- please make sure you are on latest 6.5.0.8 or 6.0.1000.9
- somehow you access the Position property directly or indirectly in the Initialize method in your code. This is not allowed. Please revisit your code
- any backtest is different than the "real" thing. Please read more here why: http://www.ninjatrader-support.com/H...sBacktest.html
NinjaTrader_Dierk is offline  
Reply With Quote
Old 02-06-2008, 08:11 AM   #3
koalboy
Member
 
Join Date: Jan 2008
Location: Austria
Posts: 31
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Dierk!

1.) I updated from 6.0.1000.7 to 6.0.1000.9 but I still get the same error in the log tab.

2.) you wrote
"- somehow you access the Position property directly or indirectly in the Initialize method in your code. This is not allowed."

If you take a look at my code, you can see, that I only access the values of the custom dataseries "StopValueSCalc" and "StopValueLCalc", which have to be defined within the Initialize-Method, havn't they?
Anyway I moved the DataSeries-definition to the beginning of the OnBarupdate-Section and changed the code in the Initialize-section to:

Code:
 
{
Add(PeriodType.Minute, 1);
 
 
CalculateOnBarClose = true;
 
 
}
and I also tried the variations with "Position" instead of "Positions[1]" but without any change of result.

I still get the same error message after starting the backtest-procedure. Does that mean, the Position-method cannot be used within a MTF-Strategy?

3.) Of course I already read the chapter in the NT-help-section and some other articles on backtesting-problems in general.

Historical tick-data is provided by my data-supplier so I try to come as close as possible to real-time-conditions (of course there are systemical restrictions).

The Market-Replay-Tool of NT is the only alternative to this, though I don't have enough replay data yet to get valid results. Also optimization of input parameters of a strategy can only be done on historical basis economically (instead of trying several set ups manually).

Would you agree that my approach of a 1-Tick-MTF-Strategy is right concerning that target or would you suggest something completely different? I'd be glad for just a little push in the right direction!

thx
koalboy is offline  
Reply With Quote
Old 02-06-2008, 08:17 AM   #4
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Could you please mail be your complete strategy and a screenshot of any settings needed to reproduce the problem to "dierk AT ninjatrader DOT com"? Thanks
NinjaTrader_Dierk 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
data box showing real time? zq655 Charting 4 02-01-2008 12:04 PM
Changing Indicators in Real Time Agamenon Strategy Development 1 11-21-2007 06:35 AM
Next bar and Real time Agamenon Strategy Development 4 11-19-2007 06:16 PM
Backtesting Multi-Timeframe does not match real market data. MONTERO Strategy Analyzer 17 10-01-2007 06:48 PM
RemoveDrawObject not working in real time JangoFolly Indicator Development 2 07-12-2007 10:13 AM


All times are GMT -6. The time now is 02:16 AM.