Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtest: unique exit only at the end of timeframe

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

    Backtest: unique exit only at the end of timeframe

    Dear Support,

    I went back to the basics and created a simple entry/exit strategy based on RSI crossing above an oversold (entry) line and crossing below an overbought (exit).

    I've tested some stocks using daily data and a 2-year timeframe. The entry condition works well but the unique exit is at the end of the timeframe only! With a such a system there should be plenty of trades and I've only 1!!

    It is probably stupid but I can't see what is wrong with my parameters. Any ideas???

    Thank you for your help,

    Ch90

    #2
    Hi Ch90,

    It's good that you tracked it to the exit condition. Is it possible you can share it here with us so we can see what you may be facing?
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Sure, but I am not sure exactly what do you need? The strategy code, a chart, both?

      Comment


        #4
        Sure, include your code and anything else that will allow us to see the specifics of the problem you're having. We generally do not provide debugging services, but sometimes all it takes is another set of eyes to spot what may be the issue. If you're looking for approaches to solving this, see the following link on debugging your NinjaScript code:
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Here we go:

          QUOTE
          // 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 test0 : Strategy
          {
          #region Variables
          // Wizard generated variables
          private int vleveldown = 10; // Default setting for Vleveldown
          private int vlevelup = 90; // Default setting for Vlevelup
          private int vperiod = 2; // Default setting for Vperiod
          private int vmacdfast = 12; // Default setting for Vmacdfast
          private int vmacdslow = 26; // Default setting for Vmacdslow
          private int vvolume = 10000; // Default setting for Vvolume
          private int vpricemin = 1; // Default setting for Vpricemin
          private int vpricemax = 5; // Default setting for Vpricemax
          // 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()
          {
          Add(RSI(Vperiod, 3));

          CalculateOnBarClose = true;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // Condition set 1
          if (CrossAbove(RSI(Vperiod, 3), Vleveldown, 1))
          {
          EnterLong(DefaultQuantity, "Entrysig");
          }

          // Condition set 2
          if (CrossBelow(RSI(Vperiod, 3), Vlevelup, 1))
          {
          ExitLong("Entrysig", "Exitsig");
          }
          }

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

          [Description("")]
          [GridCategory("Parameters")]
          public int Vlevelup
          {
          get { return vlevelup; }
          set { vlevelup = Math.Max(1, value); }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int Vperiod
          {
          get { return vperiod; }
          set { vperiod = Math.Max(1, value); }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int Vmacdfast
          {
          get { return vmacdfast; }
          set { vmacdfast = Math.Max(1, value); }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int Vmacdslow
          {
          get { return vmacdslow; }
          set { vmacdslow = Math.Max(1, value); }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int Vvolume
          {
          get { return vvolume; }
          set { vvolume = Math.Max(1, value); }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int Vpricemin
          {
          get { return vpricemin; }
          set { vpricemin = Math.Max(1, value); }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int Vpricemax
          {
          get { return vpricemax; }
          set { vpricemax = Math.Max(1, value); }
          }
          #endregion
          UNQUOTE

          Comment


            #6
            It should work better switching the parameters for your exit statement. The exit signal name is first, and the entry signal it should be paired with is second.

            ExitLong(string signalName, string fromEntrySignal)


            ExitLong("Exitsig", "Entrysig");
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              I knew it was stupid! A 1000 thanks for the quick reply and solution

              Comment

              Latest Posts

              Collapse

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