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 > Application Technical Support > Miscellaneous Support > Historical Version 7 Beta Threads > Version 7 Beta General Questions & Bug Reports

Version 7 Beta General Questions & Bug Reports Ask questions here and post bug reports.

 
 
Thread Tools Display Modes
Old 04-19-2010, 06:35 PM   #1
richa61416
Senior Member
 
Join Date: Jun 2007
Location: Anguilla
Posts: 140
Thanks: 0
Thanked 0 times in 0 posts
Default Failed to call method 'Initialize' for strategy '

I get the following error after reloading my NInja script or changing the number of days that I have on the chart.

Failed to call method 'Initialize' for strategy 'XXXXX': 'TickSize' property can not be accessed from within 'Initialize' Method.

When i first load the strategy to the chart, it works fine, however if I reload Ninja script or change the number of days loaded, from 15 to 30 day, then i get the error, and cannot run the strategy on the chart, and have to load a new chart. Any ideas as to why this may be?
richa61416 is offline  
Old 04-20-2010, 05:55 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,395
Thanks: 252
Thanked 968 times in 951 posts
Default

Please move the call to TickSize out of the Initialize() method of your strategy and then retry - http://ninjatrader.com/support/helpG...7/ticksize.htm
NinjaTrader_Bertrand is online now  
Old 04-20-2010, 11:44 AM   #3
richa61416
Senior Member
 
Join Date: Jun 2007
Location: Anguilla
Posts: 140
Thanks: 0
Thanked 0 times in 0 posts
Default

This is my initialise statements. While it generates that error, it is normally not related to the message.

SetStopLoss(
"", CalculationMode.Ticks, 56, false);
TimeInForce = Cbi.TimeInForce.Day;
EntriesPerDirection =
2;
CalculateOnBarClose =
true;
period1 =
10;
period2 =
20;
trend =
new DataSeries ( this);
macd = MACD (Input,
8, 13, 5);
macd.Input = Input;
CalculateOnBarClose =
true;

Add(StrategyPlot(
0));
Add(StrategyPlot(
1));
Add(StrategyPlot(
2));
Add(StrategyPlot(
3));
// Set the color for the indicator plots
StrategyPlot(0).Plots[0].Pen.Color = Color.Green;
StrategyPlot(
0).Plots[0].Pen.Width = 3;
StrategyPlot(
1).Plots[0].Pen.Color = Color.Gray;
StrategyPlot(
2).Plots[0].Pen.Color = Color.Red;
StrategyPlot(
3).Plots[0].Pen.Color = Color.Green;
// Set the panel which the plots will be placed on. 1 = price panel, 2 = panel under the price panel, etc.
StrategyPlot(0).PanelUI = 2;
StrategyPlot(
1).PanelUI = 2;
StrategyPlot(
2).PanelUI = 2;
StrategyPlot(
3).PanelUI = 3;
StrategyPlot(
3).Name = "Cum profit";
StrategyPlot(
0).Name = "ZeroLine";
StrategyPlot(
1).Name = "Gain";
StrategyPlot(
2).Name= "Loss";
StrategyPlot(
0).Plots[0].Min = 0;
StrategyPlot(
2).Plots[0].Max = 0;
richa61416 is offline  
Old 04-20-2010, 01:49 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

This line may be problematic: macd = MACD (Input, 8, 13, 5);

There is no bars yet so no Input. Please move that along with the other macd.Input line to OnStartUp().
NinjaTrader_Josh is offline  
Old 04-21-2010, 06:25 AM   #5
J_o_s
Senior Member
 
Join Date: Aug 2008
Location: Netherlands
Posts: 159
Thanks: 17
Thanked 5 times in 5 posts
Default

I've got the same error,
Code:
**NT** Failed to call method 'Initialize' for strategy XXXXX: Object reference not set to an instance of an object.
when trying to backtest a strategy.

Through trail and error I've found the problem in the SetTrailStop command. When I use
Code:

SetTrailStop(CalculationMode.Price, Bollinger(2, 14).Middle[1]);
I get the error mentioned above.

If I change it to:
Code:

SetTrailStop(CalculationMode.Ticks, 25);
It does work. And if I move the SetTrailStop from the Intialize() section to the OnBarUpdate() section I don't get an error, but it doesn't work in either case.

I doubt it if this is some kind of bug, so I must be doing something pretty stupid. Can someone suggest me what I'm doing wrong?
J_o_s is offline  
Old 04-21-2010, 08:14 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,395
Thanks: 252
Thanked 968 times in 951 posts
Default

J_o_s, please just set to a static value in the Initialize() and then move the dynamic call based on the Bollinger value to the OnBarUpdate(), then recheck.
NinjaTrader_Bertrand is online now  
Old 04-21-2010, 10:23 AM   #7
J_o_s
Senior Member
 
Join Date: Aug 2008
Location: Netherlands
Posts: 159
Thanks: 17
Thanked 5 times in 5 posts
Default

Thanks for your quick reply Bertrand.
Quote:
Originally Posted by NinjaTrader_Bertrand View Post
(..)
Hm, that works partially. I don't get anymore an error, but the stops aren't being triggerd.

I've also tried to use the "SamplePriceModification" on the forum, but without succes. A little bit wierd if I may say so.

This is what I've done:
1. Imported the SamplePriceModification,
2. Changed in the code the point at which the stoploss goes to breakeven from 50 points to 10 points (otherwise it would be hard to spot; notice I didn't change anything else).
3. Run a backtest with this strategy.
4. Inspected the graph for any exits; I could find none.

Please see the attached screenshot. There is a buy order @ 2727, en the trade get exits at the stoploss @ 2707. If I'm correct this shouldn't happen according to this code snippet from SamplePriceModification:
Code:
// If a long position is open, allow for stop loss modification to breakeven
elseif (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price+10 ticks, set stop loss to breakeven
if (Close[0] > Position.AvgPrice + 10 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice);
}
}
Honestly, it doesn't matter a lot if SamplePriceModification doesn't work, because I won't trade with it. However, if I try to use the Bollinger Middle band as a trailing stop loss, those doesn't get triggered either.

Here's what I've done in that context:
Code:
// Variables
privatedouble tickStop = 10000; // i.e. 10 points
Code:
protectedoverridevoid Initialize()
{
CalculateOnBarClose = true;
 
SetTrailStop(CalculationMode.Price, tickStop);
}
 
and:
Code:
protectedoverridevoid OnBarUpdate()
{
if( Position.MarketPosition == MarketPosition.Long)
{
tickStop = Close[0] + Bollinger(2, 14).Middle[0];
}
if (Position.MarketPosition == MarketPosition.Short)
{
tickStop = Bollinger(2, 14).Middle[0] - Close[0];
}
What am I doing wrong?

Regards,
Attached Images
File Type: jpg FESX ##-## (60 Min) 4-11-2009.jpg (53.7 KB, 6 views)
J_o_s is offline  
Old 04-21-2010, 10:45 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,395
Thanks: 252
Thanked 968 times in 951 posts
Default

Please set a default stop loss value in the Initialize() and reset to this value when flat as in the sample, then set the dynamic Bollinger value in your OnBarUpdate() conditions...SetStopLoss(CalculationMode.Price, Bollinger(2, 20).Middle[0])
NinjaTrader_Bertrand is online now  
Old 04-21-2010, 11:12 AM   #9
J_o_s
Senior Member
 
Join Date: Aug 2008
Location: Netherlands
Posts: 159
Thanks: 17
Thanked 5 times in 5 posts
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
Please set a default stop loss value in the Initialize() and reset to this value when flat as in the sample, then set the dynamic Bollinger value in your OnBarUpdate() conditions...SetStopLoss(CalculationMode.Price, Bollinger(2, 20).Middle[0])
Thanks a lot, it works now!

In case someone else finds this thread and have the same error/problem, here's what happened:

I made a thinking error when creating a trailing stop loss. I've thought I had to use SetTrailStop() in the OnBarUpdate() section. That's not correct, because a SetStopLoss() in the OnBarUpdate() section will be in effect a trailing stop loss, because it is updated every bar.

So the code then becomes in the OnBarUpdate() section:
Code:
// Reset the stoploss when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Price, Bollinger(2, 14).Middle[0]);
}
// Modify the stoploss when there is an open position
elseif (Position.MarketPosition == MarketPosition.Long || Position.MarketPosition == MarketPosition.Short)
{
SetStopLoss(CalculationMode.Price, Bollinger(2, 14).Middle[0]);
}
Once again, thanks Bertrand!

Regards,
J_o_s is offline  
Old 04-22-2010, 05:01 PM   #10
richa61416
Senior Member
 
Join Date: Jun 2007
Location: Anguilla
Posts: 140
Thanks: 0
Thanked 0 times in 0 posts
Default

SetStopLoss("", CalculationMode.Ticks, 56, false);I have removed that line also from my initialise, and it seems to work fine now. Strange that is takes it first, however when the script is rerun on the chart due to data range change or reloading script, it then fails. Should have warned me from first run.
richa61416 is offline  
Old 04-23-2010, 04:20 AM   #11
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,395
Thanks: 252
Thanked 968 times in 951 posts
Default

Thanks for reporting back richa61416 - will check into this behavior here.
NinjaTrader_Bertrand is online now  
 

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
failed to call method 'initialize' for indicator tinkerz General Programming 4 02-22-2010 09:46 AM
ERROR: Failed to call method 'Initialize' for indicator NinjaCustomer Indicator Development 11 12-09-2009 05:41 AM
ERROR: Failed to call 'Add' method for period type 'Tick' RK_trader Miscellaneous Support 24 06-04-2009 05:49 AM
Failed to call method "Initialize" for indicator 'Test': Object reference not set to clearpicks Indicator Development 3 04-23-2008 12:53 PM
Multiple Calls to "Initialize()" Method on Strategy Start tomcat Strategy Development 3 11-04-2007 01:12 PM


All times are GMT -6. The time now is 05:42 AM.