Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Defect in code?

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

    Defect in code?

    When I try to back test this strategy I don't get any trades. I wrote it in Strategy Wizard. I'm assuming that there is something about the code that isn't correct. Can someone spot what it is an tell me how to correct it? Thanks and Merry Christmas!

    #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>
    /// Using an outside to inside crossover to entry market
    /// </summary>
    [Description("Using an outside to inside crossover to entry market")]
    public class StochasticEntry : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int low = 4; // Default setting for Low
    private int high = 96; // Default setting for High
    // 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()
    {
    SetProfitTarget("", CalculationMode.Ticks, 32);
    SetStopLoss("", CalculationMode.Ticks, 8, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(Stochastics(7, 14, 3).D, 4, 1))
    {
    DrawArrowUp("My up arrow" + CurrentBar, false, 0, 0, Color.Cyan);
    }

    // Condition set 2
    if (CrossBelow(Stochastics(7, 14, 3).D, 96, 1))
    {
    DrawArrowDown("My down arrow" + CurrentBar, false, 0, 0, Color.Magenta);
    }
    }

    #region Properties
    [Description("Low line in Stochastic")]
    [GridCategory("Parameters")]
    public int Low
    {
    get { return low; }
    set { low = Math.Max(1, value); }
    }

    [Description("High line in Stochastic")]
    [GridCategory("Parameters")]
    public int High
    {
    get { return high; }
    set { high = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #2
    Originally posted by pjwinner View Post
    When I try to back test this strategy I don't get any trades. I wrote it in Strategy Wizard. I'm assuming that there is something about the code that isn't correct. Can someone spot what it is an tell me how to correct it? Thanks and Merry Christmas!

    #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>
    /// Using an outside to inside crossover to entry market
    /// </summary>
    [Description("Using an outside to inside crossover to entry market")]
    public class StochasticEntry : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int low = 4; // Default setting for Low
    private int high = 96; // Default setting for High
    // 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()
    {
    SetProfitTarget("", CalculationMode.Ticks, 32);
    SetStopLoss("", CalculationMode.Ticks, 8, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(Stochastics(7, 14, 3).D, 4, 1))
    {
    DrawArrowUp("My up arrow" + CurrentBar, false, 0, 0, Color.Cyan);
    }

    // Condition set 2
    if (CrossBelow(Stochastics(7, 14, 3).D, 96, 1))
    {
    DrawArrowDown("My down arrow" + CurrentBar, false, 0, 0, Color.Magenta);
    }
    }

    #region Properties
    [Description("Low line in Stochastic")]
    [GridCategory("Parameters")]
    public int Low
    {
    get { return low; }
    set { low = Math.Max(1, value); }
    }

    [Description("High line in Stochastic")]
    [GridCategory("Parameters")]
    public int High
    {
    get { return high; }
    set { high = Math.Max(1, value); }
    }
    #endregion
    }
    }
    You have not made any orders. All that you have done is to draw arrows. You cannot have trades if you have made no orders.

    Comment


      #3
      Thanks, koganan! However, when I added Long and Short positions, I'm still not getting any trades. What else might I be missing?

      #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>
      /// Using an outside to inside crossover to entry market
      /// </summary>
      [Description("Using an outside to inside crossover to entry market")]
      public class StochasticEntry : Strategy
      {
      #region Variables
      // Wizard generated variables
      private int low = 4; // Default setting for Low
      private int high = 96; // Default setting for High
      // 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()
      {
      SetProfitTarget("", CalculationMode.Ticks, 32);
      SetStopLoss("", CalculationMode.Ticks, 8, false);

      CalculateOnBarClose = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Condition set 1
      if (CrossAbove(Stochastics(7, 14, 3).D, 4, 1))
      {
      DrawArrowUp("My up arrow" + CurrentBar, false, 0, 0, Color.Cyan);
      EnterLong(DefaultQuantity, "");
      }

      // Condition set 2
      if (CrossBelow(Stochastics(7, 14, 3).D, 96, 1))
      {
      DrawArrowDown("My down arrow" + CurrentBar, false, 0, 0, Color.Magenta);
      EnterShort(DefaultQuantity, "");
      }
      }

      #region Properties
      [Description("Low line in Stochastic")]
      [GridCategory("Parameters")]
      public int Low
      {
      get { return low; }
      set { low = Math.Max(1, value); }
      }

      [Description("High line in Stochastic")]
      [GridCategory("Parameters")]
      public int High
      {
      get { return high; }
      set { high = Math.Max(1, value); }
      }
      #endregion
      }
      }

      Comment


        #4
        Originally posted by pjwinner View Post
        Thanks, koganan! However, when I added Long and Short positions, I'm still not getting any trades. What else might I be missing?

        #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>
        /// Using an outside to inside crossover to entry market
        /// </summary>
        [Description("Using an outside to inside crossover to entry market")]
        public class StochasticEntry : Strategy
        {
        #region Variables
        // Wizard generated variables
        private int low = 4; // Default setting for Low
        private int high = 96; // Default setting for High
        // 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()
        {
        SetProfitTarget("", CalculationMode.Ticks, 32);
        SetStopLoss("", CalculationMode.Ticks, 8, false);

        CalculateOnBarClose = true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
        // Condition set 1
        if (CrossAbove(Stochastics(7, 14, 3).D, 4, 1))
        {
        DrawArrowUp("My up arrow" + CurrentBar, false, 0, 0, Color.Cyan);
        EnterLong(DefaultQuantity, "");
        }

        // Condition set 2
        if (CrossBelow(Stochastics(7, 14, 3).D, 96, 1))
        {
        DrawArrowDown("My down arrow" + CurrentBar, false, 0, 0, Color.Magenta);
        EnterShort(DefaultQuantity, "");
        }
        }

        #region Properties
        [Description("Low line in Stochastic")]
        [GridCategory("Parameters")]
        public int Low
        {
        get { return low; }
        set { low = Math.Max(1, value); }
        }

        [Description("High line in Stochastic")]
        [GridCategory("Parameters")]
        public int High
        {
        get { return high; }
        set { high = Math.Max(1, value); }
        }
        #endregion
        }
        }
        Do the arrows get drawn?
        Are there any errors in your log?

        Comment


          #5
          No arrows get drawn. The log error says: Error for getting/setting property 'Low' for strategy 'StochasticEntry'/... Object of type 'NinjaTrader Indicator Data Series Helper' cannot be converted to type 'SystemInt32'.

          Comment


            #6
            Originally posted by pjwinner View Post
            No arrows get drawn. The log error says: Error for getting/setting property 'Low' for strategy 'StochasticEntry'/... Object of type 'NinjaTrader Indicator Data Series Helper' cannot be converted to type 'SystemInt32'.
            You get no output because you have an error.

            The error message is telling you that you are attempting to redefine a property from a base class. Reading your code, you are attempting to redefine High and Low to ints, from their definition as DataSeries in the base class.

            Correct your variables by naming them something that is not already defined as another type of variable.

            Comment


              #7
              Thank you, koganan! That was what I needed. Merry Christmas!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by f.saeidi, Today, 12:14 PM
              8 responses
              17 views
              0 likes
              Last Post f.saeidi  
              Started by Mikey_, 03-23-2024, 05:59 PM
              3 responses
              49 views
              0 likes
              Last Post Sam2515
              by Sam2515
               
              Started by Russ Moreland, Today, 12:54 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Erick  
              Started by philmg, Today, 12:55 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_ChristopherJ  
              Started by TradeForge, 04-19-2024, 02:09 AM
              2 responses
              32 views
              0 likes
              Last Post TradeForge  
              Working...
              X