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 Philippe56140, Today, 02:35 PM
        0 responses
        1 view
        0 likes
        Last Post Philippe56140  
        Started by 00nevest, Today, 02:27 PM
        0 responses
        1 view
        0 likes
        Last Post 00nevest  
        Started by Jonafare, 12-06-2012, 03:48 PM
        5 responses
        3,986 views
        0 likes
        Last Post rene69851  
        Started by Fitspressorest, Today, 01:38 PM
        0 responses
        2 views
        0 likes
        Last Post Fitspressorest  
        Started by Jonker, Today, 01:19 PM
        0 responses
        2 views
        0 likes
        Last Post Jonker
        by Jonker
         
        Working...
        X