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&am p; 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", "[email protected]", "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", "[email protected]", "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 } }
Comment