Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question about RSI Strategy

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

    Question about RSI Strategy

    Hi ,

    I hope someone can help me. I am trying to develop a strategy which uses RSI in a multi time frame scenario. My situation is this. I want to go short whenever RSI crosses above let us say 65 in a 15 minute and a 5 minute chart.

    I used your SampleMulti Time Frame strategy to develop my strategy. However this is not working. I can see the RSI cross over in both time periods however my stratey doesn't execute. Maybe I am doing something wrong.

    Below is the code. If someone can tell me what I am doing wrong I will appreciate it.

    Thanks

    //
    // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    #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.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// This is a sample multi-time frame strategy.
    /// </summary>
    [Description("This is a sample multi-time frame strategy.")]
    public class RSIMultiTimeFrame : Strategy
    {
    #region Variables
    // Wizard generated variables
    // User defined variables (add any user defined variables below)
    private int rSIPeriod = 14; // Default setting for RSIPeriod
    private int rSISmooth = 3; // Default setting for RSISmooth
    private int profitTarget = 13; // Default setting for ProfitTarget
    private int stopLoss = 12; // Default setting for StopLoss
    double crossoverValue = 65;
    double crossoverValue2 = 65;
    #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 a 5 minute Bars object to the strategy
    Add(PeriodType.Minute, 5);

    // Add a 15 minute Bars object to the strategy
    Add(PeriodType.Minute, 15);

    // Note: Bars are added to the BarsArray and can be accessed via an index value
    // E.G. BarsArray[1] ---> Accesses the 5 minute Bars object added above

    // Add simple moving averages to the chart for display
    // This only displays the SMA's for the primary Bars object on the chart
    // Add(SMA(5));
    // Add(SMA(50));
    Add(RSI(14,3));

    CalculateOnBarClose = true;
    }
    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (Historical)
    return;
    Print("" + Time[0] + " " + "RSI OUTSIDE IS NOW " + crossoverValue + RSI(BarsArray[2], 14,3));
    // OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
    // We only want to process events on our primary Bars object (index = 0) which is set when adding
    // the strategy to a chart
    //if (BarsInProgress != 0)
    // return;

    // Checks if the 5 period SMA is above the 50 period SMA on both the 5 and 15 minute time frames

    if (CrossAbove(RSI(BarsArray[2], 14,3), crossoverValue,1))

    Print("" + Time[0] + " " + "RSI IS NOW in 5 Min chart " + crossoverValue);



    if (CrossAbove(RSI(BarsArray[1], 14,3), crossoverValue2,1))

    Print("" + Time[0] + " " + "RSI IS NOW in 15 Min chart " + crossoverValue2);

    // Checks for a cross below condition of the 5 and 15 period SMA on the 15 minute time frame and exits long
    //if (CrossAbove(RSI(RSIPeriod, RSISmooth),crossoverValue,1))
    if (CrossAbove(RSI(BarsArray[2], 14,3), crossoverValue,1) && (CrossAbove(RSI(BarsArray[1], 14,3), crossoverValue2,1)))
    EnterShort(2);
    }
    #region Properties
    #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("Crossover value")]
    [GridCategory("Parameters")]
    public double CrossoverValue
    {
    get { return crossoverValue; }
    set { crossoverValue = Math.Max(1, value); }
    }

    [Description("Crossover value 2")]
    [GridCategory("Parameters")]
    public double CrossoverValue2
    {
    get { return crossoverValue2; }
    set { crossoverValue2 = Math.Max(1, value); }
    }
    #endregion
    #endregion
    }
    }

    #2
    Hello,

    if (CrossAbove(RSI(BarsArray[2], 14,3), crossoverValue,1) && (CrossAbove(RSI(BarsArray[1], 14,3), crossoverValue2,1)))

    You might want to try :

    if (CrossAbove(RSI(BarsArray[2], 14,3), crossoverValue,1))
    {
    flag1 = true;
    }

    if (CrossAbove(RSI(BarsArray[1], 14,3), crossoverValue2,1))
    {
    flag2 = true;
    }

    if ( flag1 && flag2 )
    {
    EnterShort();
    flag1 = false;
    flag2 = false;
    }
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thanks I am trying this now. Also I wanted to ask you how do I print the RSI value to the output window. I am doing this print(RSI(BarsArray[2], 14,3) but that only gives me the something like this RSI(CL 01-13 (15 Min),14,3) in the output window. I want the actual RSI value. How do I get that printed ?

      Thanks

      Comment


        #4
        Hello,

        You would want to do this :

        Print( RSI(BarsArray[2], 14,3)[0].ToString() );
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Thank you this works also the multi time frame is now working

          Thanks a lot.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          647 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          572 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X