Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Seeking help with simple strategy

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

    Seeking help with simple strategy

    I am new to this and tried to create a strategy to backtest the following-

    1. buy 500 shares if the price reaches 3% above the open
    2. sell 500 shares if the price increases to 3% above the purchase price(or 6% above the open)
    3. sell 500 shares if the price drops back down to the opening price

    just a simple breakout strategy I would like to play around with, when I try to backtest I get no results

    here is what I have, any help would be greatly appreciated.

    Code:
    #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>
        /// Enter the description of your strategy here
        /// </summary>
        [Description("Enter the description of your strategy here")]
        public class Test : 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()
            {
                SetStopLoss("", CalculationMode.Percent, -0.03, false);
                SetProfitTarget("", CalculationMode.Percent, 0.03);
    
                CalculateOnBarClose = false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Condition set 1
                if ((GetCurrentBid()) * (1 + 0.03) > Open[1])
                {
                    EnterLongStop(500, 0, "");
                }
            }
    
            #region Properties
            [Description("")]
            [Category("Parameters")]
            public int MyInput0
            {
                get { return myInput0; }
                set { myInput0 = Math.Max(1, value); }
            }
            #endregion
        }

    #2
    Hi subrock,

    Thank you for your note.

    In the SetStopLoss() there is no need to put a negative value, you can just use 0.03
    More info at - http://www.ninjatrader-support.com/H...ml?SetStopLoss

    With that change, you will also need a exemption for avoid the error discussed at the following link.
    TimNinjaTrader Customer Service

    Comment


      #3
      Removing the negative value wouldnt make the stoploss the same amount as the profittarget?

      I wasnt receiving errors prior to the change suggested but I did following the link and modified this portion:

      protected override void OnBarUpdate()
      {
      // Condition set 1
      if ((GetCurrentBid()) * (1 + 0.03) > Open[Math.Min(CurrentBar, 1)])
      {
      EnterLongStop(500, 0, "");
      }
      }

      I still cant seem to get any results good or bad when i try to backtest.

      Thanks for your time

      Comment


        #4
        No, when you use SetStopLoss() it is already negative and will always be applied in the correct direction depending on the entry order. All you need to do is say I want 3% as my stop loss and it will handle the rest.

        If you aren't getting any trades then I suggest you debug your if-statement. Use Print() and print out the individual components and evaluate it by hand to see if it should ever be true.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          thanks I will check this out.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          650 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          577 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X