• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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?
        Patrick H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Johnny Santiago, Today, 07:06 AM
        0 responses
        3 views
        0 likes
        Last Post Johnny Santiago  
        Started by HiddenPhilosopher, Today, 04:37 AM
        1 response
        21 views
        0 likes
        Last Post NinjaTrader_ChristopherS  
        Started by aprendiz, Today, 06:44 AM
        1 response
        2 views
        0 likes
        Last Post NinjaTrader_Jim  
        Started by frankduc, Today, 06:35 AM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Jim  
        Started by Trexxx, Today, 06:34 AM
        0 responses
        2 views
        0 likes
        Last Post Trexxx
        by Trexxx
         
        Working...
        X