Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RSI Smooth CrossOver bug - NT7(B19)

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

    RSI Smooth CrossOver bug - NT7(B19)

    Hello,

    I'm new to NT, and I'm following the tutorial.
    While testing the example "RSI with Stop Loss and Profit Target", I've encountered an issue that may be a bug.

    Setup:
    Version = NT 7.0.0.19
    .NET/CLR Version = 2.0.50727.3603
    Datafeed = Yahoo (builtin)
    Ticker = BP (British Petroleum)

    With this setup, I run a backtest in the Strategy Analyzer, on ticker BP, with the script below,
    which is a slight modification of the script in the tutorial.

    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>
        /// RSI with Stop Loss and Profit Target
        /// </summary>
        [Description("RSI with Stop Loss and Profit Target")]
        public class Tutorial2 : Strategy
        {
            #region Variables
            // Wizard generated variables
            private int rSIPeriod = 13; // Default setting for RSIPeriod
            private int rSISmooth = 10; // Default setting for RSISmooth
            private int profitTarget = 10; // Default setting for ProfitTarget
            private int stopLoss = 10; // Default setting for StopLoss
            private CalculationMode calcMode = CalculationMode.Percent;
            // 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;
     
                // This will add the RSI indicator to the chart for visualization
                Add(RSI(rSIPeriod, rSISmooth));
     
                // Add stop loss and profit target orders
                SetStopLoss(calcMode, stopLoss);
                SetProfitTarget(calcMode, profitTarget);
            }
     
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                if (CurrentBar < RSIPeriod)
                        return;
     
                if (CrossAbove(RSI(RSIPeriod, RSISmooth), 30, 1))
                {
                    EnterLong();
                }
            }
     
            #region Properties
            [Description("RSI Period")]
            [GridCategory("Parameters")]
            public int RSIPeriod
            {
                get { return rSIPeriod; }
                set { rSIPeriod = Math.Max(1, value); }
            }
     
            [Description("RSI Smooth")]
            [GridCategory("Parameters")]
            public int RSISmooth
            {
                get { return rSISmooth; }
                set { rSISmooth = Math.Max(1, value); }
            }
     
            [Description("Profit Target Offset")]
            [GridCategory("Parameters")]
            public int ProfitTarget
            {
                get { return profitTarget; }
                set { profitTarget = Math.Max(1, value); }
            }
     
            [Description("Stop Loss Offset")]
            [GridCategory("Parameters")]
            public int StopLoss
            {
                get { return stopLoss; }
                set { stopLoss = Math.Max(1, value); }
            }
     
            [Description("Calculation Mode")]
            [GridCategory("Parameters")]
            public CalculationMode CalcMode
            {
                get { return calcMode; }
                set { calcMode = value; }
            }
            #endregion
        }
    }
    There are 2 issues:

    Issue 1: Signal acts on RSI instead of Smoothed RSI.
    My code says to enter Long if (CrossAbove(RSI(RSIPeriod, RSISmooth), 30, 1))
    For this test, RSIPeriod = 13, and RSISmooth = 10.
    The data for RSI(BP(Daily),13,10) in the Data Box on the chart is:
    • On 12/02/2000:
      • RSI = 26,9
      • Avg = 27,37
    • On 15/02/2000:
      • RSI = 31,01
      • Avg = 28,03
    • On 16/02/2000:
      • RSI = 30,87
      • Avg = 28,55
    NT sees that the RSI crosses above 30 on 15/02/2000, and goes long at the next bar.
    Now, my expectation is that this crossover should be triggered on the Smoothed data (Avg).
    In that case, there would be no crossing above 30 on 15/02/2000.
    Else, what's the point in using the smooth parameter in the formula?
    Is this a bug?


    Issue 2: SetStopLoss and SetProfitTarget don't work
    My SetStopLoss and SetProfitTarget seem to get triggered.
    I only get 2 trades with this script:
    The first is on 16/02/2000 (see issue 1 above)
    And the second is on the last bar (exit on close)
    I don't suppose this is a bug, but something that I'm missing...

    #2
    Hello bmistiaen,

    Welcome to the NinjaTrader forums!

    1) The crossing statement you're evaluating here is not based on the RSI's average, but rather the main plot. You're specifying that you'd like the average calculation to use RSISmooth number of periods, but not actually referencing the average plot. Below is how you would reference the RSI average plot:

    if
    (CrossAbove(RSI(RSIPeriod, RSISmooth).Avg, 30, 1))

    A good way to identify the syntax for multi-plot indicators is with the strategy wizard condition builder. This help guide article can help with this.

    2) You're using calculation mode percent, and this needs to be expressed in decimal form for the percent equivelent.

    Example:
    10% = .1
    1% = .01
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the answers
      It works great now.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      595 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      343 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      556 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      554 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X