PDA

View Full Version : Crash with wizard built strategy


zoltran
04-03-2007, 05:44 AM
Get the following error on the strategy below
This is a 100% wizard built strategy

-----------------------------------
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Exception: 'Positions' property can not be accessed from within 'Initialize' method
at NinjaTrader.Strategy.StrategyBase.get_Positions()
at NinjaTrader.Strategy.StrategyBase.SetInput(Bars[] bars)
at NinjaTrader.Gui.Chart.ChartControl.Add(StrategyBas e strategyTemplate)
at NinjaTrader.Gui.Chart.ChartStrategies.Apply()
at NinjaTrader.Gui.Chart.ChartStrategies.OnOkButtonCl ick(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

=======================

public class Mama : Strategy
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#endregion

/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
Add(MAMA(0.5, 0.05));
SetStopLoss("", CalculationMode.Price, VMA(8, 8)[0], false);

CalculateOnBarClose = false;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(MAMA(0.5, 0.05), MAMA(0.5, 0.05).Fama, 1)
&& CCI(14)[0] > 100)
{
Alert("MamaL", Priority.High, "", "", 60, Color.Lime, Color.Black);
EnterLong(DefaultQuantity, "MamaL");
SendMail("Ninja", "wesmith@rogers.com", "MamaL", "");
}

// Condition set 2
if (CrossBelow(MAMA(0.5, 0.05), MAMA(0.5, 0.05).Fama, 1)
&& CCI(14)[0] < -100)
{
Alert("MamaS", Priority.High, "Short", "", 60, Color.Red, Color.Black);
EnterShort(DefaultQuantity, "MamaS");
SendMail("Ninja", "wesmith@rogers.com", "MamaS", "");
}



// Condition set 5
if (Low[0] < MAMA(0.5, 0.05).Fama[0]
&& Position.MarketPosition == MarketPosition.Long)
{
ExitLong("XL1", "");
}

// Condition set 6
if (High[0] > MAMA(0.5, 0.05).Fama[0]
&& Position.MarketPosition == MarketPosition.Short)
{
EnterShort(DefaultQuantity, "XS1");
}
}

#region Properties
#endregion
}
}

NinjaTrader_Dierk
04-03-2007, 07:31 AM
There are several issues related to that problem. We need to think a bit how to resolve at best.

We'll keep you posted.

NinjaTrader_Dierk
04-04-2007, 03:10 AM
Here is the deal:
- you can not have indicator values like VMA(8, 8)[0] for the stop target settings in the Initialize method. The wizard in the next release will prevent you doing that.
- however in no event NT should crash. Next release will hold a fix which would trap a situation like the above.
- if you want to have indicator values in your stop/target settings then you need to switch from wizard to manual mode and move the line
SetStopLoss("", CalculationMode.Price, VMA(8, 8)[0], false);to the OnBarUpdate method.

Hope this helps. Thanks for bringing that up.