Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Analyzer not purchasing at indicator

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

    Strategy Analyzer not purchasing at indicator

    Hello all,

    I'm very new to the software and have started using the strategy analyzer for SPY trades on a 3 minute chart.

    I set up a simple strategy so that when the MACD crosses the 0 line to initiate the buying of positions. However, whenever I run the test, I find that the backtester won't initiate the buy until about 4 bars in, which cuts into my profit and is not representative of when I would actually purchase. Would anyone know how I can fix this problem on my backtesting or if there is a setting that I'm missing. Any help would be greatly appreciated

    #2
    Hello Kodama78,

    Thank you for your post and welcome to the Forums!

    You can try setting the BarsRequired to 0 for the Strategy parameters when running the backtest.

    Also, would you mind sharing some of the script in what your conditions are for entering?
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Script

      Hi Cal,

      Thank you for your reply. It's a real basic set up to buy when the MACD crosses over the 0 line and sell when the STO hits the overbought indicator.

      Script:

      #region Using declarations
      using System;
      using System.ComponentModel;
      using System.Diagnostics;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Data;
      using NinjaTrader.Indicator;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Strategy;
      #endregion

      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
      /// <summary>
      /// Buy with MACD and sell with Sto ob/os signal
      /// </summary>
      [Description("Buy with MACD and sell with Sto ob/os signal")]
      public class MACDSto : Strategy
      {
      #region Variables
      // Wizard generated variables
      private int myInput0 = 1; // Default setting for MyInput0
      // 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()
      {

      CalculateOnBarClose = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Condition set 1
      if (CrossAbove(MACD(12, 26, 9).Avg, 0, 1))
      {
      EnterLong(DefaultQuantity, "");
      }

      // Condition set 2
      if (CrossBelow(MACD(12, 26, 9).Avg, 0, 1))
      {
      EnterShort(DefaultQuantity, "");
      }

      // Condition set 3
      if (Stochastics(7, 14, 3).D[0] > 0)
      {
      ExitLong("", "");
      }

      // Condition set 4
      if (Stochastics(7, 14, 3).D[0] < 8)
      {
      ExitShort("", "");
      }
      }

      #region Properties
      [Description("")]
      [GridCategory("Parameters")]
      public int MyInput0
      {
      get { return myInput0; }
      set { myInput0 = Math.Max(1, value); }
      }
      #endregion
      }
      }

      Any help would be appreciated. The basic problem is that it doesn't buy when the indicator goes off and I'm not exactly sure why and neither is my friend who is a little more familiar with ninjatrader.

      Comment


        #4
        Hello kodama78,

        Thank you for your response.

        Can you provide a screenshot of the chart tab in the Strategy Analyzer after running a test that shows where the strategy should have entered and where it actually entered?

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        69 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        42 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        24 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        27 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        54 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X