Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RSI two time frames

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

    RSI two time frames

    I'm trying to develop a simple strategy based on RSI on two different time frames (30min primary Series, 5min secondary Series).
    I used the Sample Data Series as a guide, but yet it doesn't work (it takes just one trade, regardless of the backtest period):

    protectedoverridevoid Initialize()
    {
    Add(PeriodType.Minute, 5);

    primarySeries = new DataSeries(this);



    CalculateOnBarClose =
    true;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    if (secondarySeries == null)
    {
    secondarySeries = new DataSeries(RSI(BarsArray[1], 2, 0));
    }

    // Executed on primary bar updates only
    if (BarsInProgress == 0)
    {
    primarySeries.Set(RSI(2, 0)[0]);
    }

    // Executed on secondary bar updates only
    if (BarsInProgress == 1)
    {
    secondarySeries.Set(RSI(2, 0)[0]);
    }

    if (primarySeries[0] > 0 && secondarySeries[0] > 0 && secondarySeries[0] > primarySeries[0])
    {
    EnterLong(DefaultQuantity,
    "");
    ExitShort(
    "", "");
    }

    if (primarySeries[0] < 0 && secondarySeries[0] < 0 && secondarySeries[0] < primarySeries[0])
    {
    EnterShort(DefaultQuantity,
    "");
    ExitLong(
    "", "");
    }
    }

    I don't get any error message in the Log.

    Thank you

    #2
    Hi stefy,

    I would guess it does not do what you expect because you check for < > 0 and meant to write 50 instead...

    Please see this tip and the Print() statements to your code to make it easier to spot where your calculations do not deliver as expected - http://www.ninjatrader-support2.com/...ead.php?t=3418

    Also you can assess the RSI value for different bars objects directly, thus making your code more efficient -

    Code:
    [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (RSI([/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000], [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]5[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]] > [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]50[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] && RSI(BarsArray[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]], [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000], [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]5[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]] > [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]50[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]) [/COLOR][/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{ [/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// Do some trades [/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]} [/SIZE][/FONT]
    [/SIZE][/FONT][/COLOR][/FONT]

    Comment


      #3
      Yes, it was meant to be 50, thank you.

      Two questions:

      1. If I used the RSI(BarsArray[1], 20, 5)[0] function, apart from introducing the secondary time frame in Initalize(), would I need to use the if (BarsInProgress) logic, or I could simply code my conditions like in a one timeframe only environment?

      2. I understand I cannot plot RSI with different timeframes, but I could calculate the difference between RSI(30min) and RSI(5min) and plot it on a 5min chart? How could I do that?

      Thank you

      Comment


        #4
        Hi stefy,

        1. You still want to use the BarsInProgress check to decide when the OnBarUpdate() for this bars object is called in your code, please see this link - http://www.ninjatrader-support.com/H...struments.html

        2. You can calculate the difference, correct, but it could not be displayed properly. NinjaTrader 7 will offer more features in this area.

        Comment

        Latest Posts

        Collapse

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