View Full Version : SetStopLoss and SetProfitTarget in Initialize
FireFly
04-05-2007, 06:19 PM
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);
NinjaTrader_Dierk
04-05-2007, 06:43 PM
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/ninjatrader/nt6.custom/NinjaTrader.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.
FireFly
04-05-2007, 06:50 PM
Dierk Droth wrote: 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/ninjatrader/nt6.custom/NinjaTrader.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).
NinjaTrader_Dierk
04-05-2007, 06:54 PM
Please proceed as per below. The custom build fixes issues in NT6B10.
FireFly
04-05-2007, 07:26 PM
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
NinjaTrader_Dierk
04-05-2007, 10:58 PM
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
FireFly
04-05-2007, 11:14 PM
Dierk Droth wrote: 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...
protected override void 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);
}
NinjaTrader_Dierk
04-05-2007, 11:18 PM
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.
FireFly
04-06-2007, 12:41 AM
I've sent you a pm with the code
NinjaTrader_Dierk
04-06-2007, 12:52 AM
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.