![]() |
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
|
|||||||
| Version 7 Beta General Questions & Bug Reports Ask questions here and post bug reports. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jun 2007
Location: Anguilla
Posts: 140
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,395
Thanks: 252
Thanked 968 times in 951 posts
|
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
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jun 2007
Location: Anguilla
Posts: 140
Thanks: 0
Thanked 0 times in 0 posts
|
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; |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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().
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Aug 2008
Location: Netherlands
Posts: 159
Thanks: 17
Thanked 5 times in 5 posts
|
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. 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]); If I change it to: Code:
SetTrailStop(CalculationMode.Ticks, 25); 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?
|
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,395
Thanks: 252
Thanked 968 times in 951 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Aug 2008
Location: Netherlands
Posts: 159
Thanks: 17
Thanked 5 times in 5 posts
|
Thanks for your quick reply Bertrand.
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);
}
}
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);
}
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];
}
![]() Regards, |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,395
Thanks: 252
Thanked 968 times in 951 posts
|
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])
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#9 | |
|
Senior Member
Join Date: Aug 2008
Location: Netherlands
Posts: 159
Thanks: 17
Thanked 5 times in 5 posts
|
Quote:
![]() 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]);
}
Regards, |
|
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Jun 2007
Location: Anguilla
Posts: 140
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#11 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,395
Thanks: 252
Thanked 968 times in 951 posts
|
Thanks for reporting back richa61416 - will check into this behavior here.
Bertrand
NinjaTrader Customer Service |
|
|
|
| Thread Tools | |
| Display Modes | |
|
|
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 |