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 04-05-2007, 05:19 PM   #1
FireFly
Senior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 150
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

The NT6 manual recommends to put SetStopLoss and SetProfitTarget in the Initialize part. However,any of the statements below generate an exception:

"Positions property can not be accessed from 'Initialize' method"



SetStopLoss(LongEntrySignal, CalculationMode.Ticks, stoploss,
false);

SetStopLoss(ShortEntrySignal, CalculationMode.Ticks, stoploss,
false);

SetProfitTarget(LongEntrySignal, CalculationMode.Ticks, profitTarget);

SetProfitTarget(ShortEntrySignal, CalculationMode.Ticks, profitTarget);
FireFly is offline  
Reply With Quote
Old 04-05-2007, 05:43 PM   #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
Post imported post

We recently fixed an issue related. Could you please:
- uninstall NT6 via control panel
- install latest custom build from here: http://www.ninjatrader-support.com/n...er.Install.msi

You then need to inspect the logs after starting you strategy. There likely are issues reported which then are related to strategy code.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 04-05-2007, 05:50 PM   #3
FireFly
Senior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 150
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Dierk Droth wrote:
Quote:
We recently fixed an issue related. Could you please:
- uninstall NT6 via control panel
- install latest custom build from here: http://www.ninjatrader-support.com/n...er.Install.msi

You then need to inspect the logs after starting you strategy. There likely are issues reported which then are related to strategy code.
I installed build 10 just days ago. I guess that is still the latest?

I cannot run the strategy at all when I put these lines in 'Initialize' (if I continue after the exception, NT6 crashes). However, everything is fine if I move the statements to the OnBarUpdate section (so that's what I'm doing now).
FireFly is offline  
Reply With Quote
Old 04-05-2007, 05:54 PM   #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
Post imported post

Please proceed as per below. The custom build fixes issues in NT6B10.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 04-05-2007, 06:26 PM   #5
FireFly
Senior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 150
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

I have uninstalled NT6 and installed the latest version (your link).

NT6 doesn't crash anymore, but the strategy cannot be executed. The logfile shows the following message:

"4/6/2007 14:18 Strategy Failed to call method 'Initialize' for strategy 'ORBELCID001': Object reference not set to an instance of an object."

Everything is fine when I move the StopLoss- and ProfitTarget statements to the OnBarUpdate section





FireFly is offline  
Reply With Quote
Old 04-05-2007, 09:58 PM   #6
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
Post imported post

Right, as I suspected there is a problem with the Initialize method. Could you please post your complete code of the Initialize method as the strategy crashes. Thanks
NinjaTrader_Dierk is offline  
Reply With Quote
Old 04-05-2007, 10:14 PM   #7
FireFly
Senior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 150
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Dierk Droth wrote:
Quote:
Right, as I suspected there is a problem with the Initialize method. Could you please post your complete code of the Initialize method as the strategy crashes. Thanks
Nothing fancy in there...


protectedoverridevoid Initialize()

{

CalculateOnBarClose =
true;

EntriesPerDirection =
1;

EntryHandling = EntryHandling.AllEntries;

TraceOrders =
true;



SetStopLoss(LongEntrySignal, CalculationMode.Ticks, stoploss,
false);

SetStopLoss(ShortEntrySignal, CalculationMode.Ticks, stoploss,
false);

SetProfitTarget(LongEntrySignal, CalculationMode.Ticks, profitTarget);

SetProfitTarget(ShortEntrySignal, CalculationMode.Ticks, profitTarget);

}
FireFly is offline  
Reply With Quote
Old 04-05-2007, 10:18 PM   #8
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
Post imported post

Great.

Hmm, I would need more information. Do you mind posting the complete strategy (e.g. as attachment)? You may consider blanking out the OnBarUpdate method (if you want to keep your strategy secret), which is not relevent for researching this issue.

NinjaTrader_Dierk is offline  
Reply With Quote
Old 04-05-2007, 11:41 PM   #9
FireFly
Senior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 150
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

I've sent you a pm with the code
FireFly is offline  
Reply With Quote
Old 04-05-2007, 11:52 PM   #10
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
Post imported post

This is bug which will be fixed with next beta/release. As you figured you cand get around by moving your stop/target settings to OnBarUpdate method.

Thanks for providing your strategy and pointing this out.
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


All times are GMT -6. The time now is 06:49 AM.