Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RSI Overbought/Oversold strategy

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

    RSI Overbought/Oversold strategy

    Hi everyone,

    I am currently trying to code a strategy that would enter long on a cross of the RSI above its exponential moving average (the "smooth") in the oversold area (below 20), and enter short on a cross of the avg above the RSI in the oversold area (above 80).

    The exit strategy for a long position would be on a cross of the smooth above the RSI, and the exit strategy for a short position would be on a cross of the RSI above the smooth.

    It sounded like a simple strategy to code in the first place, but now I'm having trouble with the results I get.

    With the following code, I get trades firering off on each an every candle, which is really unexpected.

    Am I doing something wrong here?

    HTML Code:
    // Short Entry
    			if ( RSI(7, 3)[0] >= 80
    			&& RSI(7, 3).Avg[0] >= 80
    			&& CrossAbove(RSI(7, 3).Avg, RSI(7, 3), 1) )
    				{
    					EnterShort(DefaultQuantity, "");
    				}
    			// Long Entry
    			if ( RSI(7, 3)[0] <= 20 
    			&& RSI(7, 3).Avg[0] <= 20
    			&& CrossAbove(RSI(7, 3), RSI(7, 3).Avg, 1) )
    				{
    					EnterLong(DefaultQuantity, "");
    				}
    			// Short Exit
    			if ( CrossAbove(RSI(7, 3), RSI(7, 3).Avg, 1) )
    				{
    					ExitShort("", "");
    				}
    			// Long Exit
    			if ( CrossAbove(RSI(7, 3).Avg, RSI(7, 3), 1) )
    				{
    					ExitLong("", "");
    				}
    Attached Files

    #2
    Hello jmayerb,

    Thank you for writing in. To confirm, here is what the entry conditions for your code do right now:

    If the RSI(7, 3) average of the current bar has crossed above the RSI(7, 3) of the current bar and the RSI(7, 3) of the current bar is greater than or equal to 80 and the RSI(7, 3) average of the current bar is greater than or equal to 80, then enter short.

    If the RSI(7, 3) average of the current bar has crossed above the RSI(7, 3) of the current bar and the RSI(7, 3) of the current bar is less than or equal to 20 and the RSI(7, 3) average of the current bar is less than or equal to 20, then enter long.

    I do not see any logical errors in the code you provided.

    I have run a backtest on the 4 renko GC continuous contract with the code you provided which caused only 1 trade to happen between 01/01/2015 and 07/19/2015, specifically on 04/05/2015.

    Could you please provide more of your code so I may investigate the issue further? If you do not wish to post to the forums, please attach it to an email to platformsupport[AT]ninjatrader[DOT]com and make sure to reference this ticket number in the body of the email: #1354504

    Thank you in advance.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      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 RenkoRSItest : Strategy
          {
              #region Variables
              // Wizard generated variables
              private int rSIlenght = 7; // Default setting for RSIlenght
              private int smooth = 3; // Default setting for Smooth
              private int overbought = 80; // Default setting for Overbought
              private int oversold = 20; // Default setting for Oversold
              // 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(7, 3));
      			
      			CalculateOnBarClose = true;
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
      			// Short Entry
      			if ( RSI(7, 3)[0] >= 80
      			&& RSI(7, 3).Avg[0] >= 80
      			&& CrossAbove(RSI(7, 3).Avg, RSI(7, 3), 1) )
      				{
      					EnterShort(DefaultQuantity, "");
      				}
      			// Long Entry
      			if ( RSI(7, 3)[0] <= 20 
      			&& RSI(7, 3).Avg[0] <= 20
      			&& CrossAbove(RSI(7, 3), RSI(7, 3).Avg, 1) )
      				{
      					EnterLong(DefaultQuantity, "");
      				}
      			// Short Exit
      			if ( CrossAbove(RSI(7, 3), RSI(7, 3).Avg, 1) )
      				{
      					ExitShort("", "");
      				}
      			// Long Exit
      			if ( CrossAbove(RSI(7, 3).Avg, RSI(7, 3), 1) )
      				{
      					ExitLong("", "");
      				}
              }
      
              #region Properties
              [Description("")]
              [GridCategory("Parameters")]
              public int RSIlenght
              {
                  get { return rSIlenght; }
                  set { rSIlenght = Math.Max(1, value); }
              }
      
              [Description("")]
              [GridCategory("Parameters")]
              public int Smooth
              {
                  get { return smooth; }
                  set { smooth = Math.Max(1, value); }
              }
      
              [Description("")]
              [GridCategory("Parameters")]
              public int Overbought
              {
                  get { return overbought; }
                  set { overbought = Math.Max(1, value); }
              }
      
              [Description("")]
              [GridCategory("Parameters")]
              public int Oversold
              {
                  get { return oversold; }
                  set { oversold = Math.Max(1, value); }
              }
              #endregion
          }
      }

      Originally posted by NinjaTrader_MichaelM View Post
      Hello jmayerb,

      Thank you for writing in. To confirm, here is what the entry conditions for your code do right now:

      If the RSI(7, 3) average of the current bar has crossed above the RSI(7, 3) of the current bar and the RSI(7, 3) of the current bar is greater than or equal to 80 and the RSI(7, 3) average of the current bar is greater than or equal to 80, then enter short.

      If the RSI(7, 3) average of the current bar has crossed above the RSI(7, 3) of the current bar and the RSI(7, 3) of the current bar is less than or equal to 20 and the RSI(7, 3) average of the current bar is less than or equal to 20, then enter long.

      I do not see any logical errors in the code you provided.

      I have run a backtest on the 4 renko GC continuous contract with the code you provided which caused only 1 trade to happen between 01/01/2015 and 07/19/2015, specifically on 04/05/2015.

      Could you please provide more of your code so I may investigate the issue further? If you do not wish to post to the forums, please attach it to an email to platformsupport[AT]ninjatrader[DOT]com and make sure to reference this ticket number in the body of the email: #1354504

      Thank you in advance.

      Comment


        #4
        Hello jmayerb,

        Thank you for posting your code. I have backtested this code as well and I am still not able to reproduce the behavior you are seeing for the GC ##-## on a 4 renko period. The backtest produced 1 entry between 01/01/2015 and 07/21/2015.

        When I change the cross above lookBackPeriod to a higher value than 1 on the long or short entry conditions, more trades occur.

        Please send a screenshot of the "Trades" tab of the strategy analyzer showing all of the trades that your strategy is executing as well as a screenshot of your strategy backtest settings so I can narrow down the issue further.

        To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

        http://windows.microsoft.com/en-us/w...#1TC=windows-8

        Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

        http://take-a-screenshot.org/

        Thank you in advance.
        Michael M.NinjaTrader Quality Assurance

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by gbourque, Today, 06:39 AM
        0 responses
        2 views
        0 likes
        Last Post gbourque  
        Started by cmtjoancolmenero, Yesterday, 03:58 PM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by benmarkal, Yesterday, 12:52 PM
        3 responses
        23 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by helpwanted, Today, 03:06 AM
        1 response
        20 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        12 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Working...
        X