Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Crash with wizard built strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Crash with wizard built strategy

    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&amp ; 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)

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

    Code:
    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
     }
    }

    #2
    imported post

    There are several issues related to that problem. We need to think a bit how to resolve at best.

    We'll keep you posted.

    Comment


      #3
      imported post

      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
      Code:
      SetStopLoss("", CalculationMode.Price, VMA(8, 8)[0], false);
      to the OnBarUpdate method.

      Hope this helps. Thanks for bringing that up.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by yertle, Today, 08:38 AM
      0 responses
      1 view
      0 likes
      Last Post yertle
      by yertle
       
      Started by Mestor, 03-10-2023, 01:50 AM
      15 responses
      378 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by samish18, Yesterday, 08:57 AM
      10 responses
      27 views
      0 likes
      Last Post samish18  
      Started by matty89, 03-02-2020, 08:31 AM
      34 responses
      3,039 views
      1 like
      Last Post NinjaTrader_BrandonH  
      Started by kujista, Today, 05:44 AM
      3 responses
      14 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X