![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Apr 2007
Location: , ,
Posts: 150
Thanks: 0
Thanked 0 times in 0 posts
|
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); |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
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.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Senior Member
Join Date: Apr 2007
Location: , ,
Posts: 150
Thanks: 0
Thanked 0 times in 0 posts
|
Dierk Droth wrote:
Quote:
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). |
|
|
|
|
|
|
#4 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Please proceed as per below. The custom build fixes issues in NT6B10.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Apr 2007
Location: , ,
Posts: 150
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#6 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
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
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#7 | |
|
Senior Member
Join Date: Apr 2007
Location: , ,
Posts: 150
Thanks: 0
Thanked 0 times in 0 posts
|
Dierk Droth wrote:
Quote:
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); } |
|
|
|
|
|
|
#8 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
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.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Apr 2007
Location: , ,
Posts: 150
Thanks: 0
Thanked 0 times in 0 posts
|
I've sent you a pm with the code
|
|
|
|
|
|
#10 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
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.
Dierk
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|