Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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]
    BertrandNinjaTrader Customer Service

    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.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Balage0922, Today, 07:38 AM
        0 responses
        2 views
        0 likes
        Last Post Balage0922  
        Started by JoMoon2024, Today, 06:56 AM
        0 responses
        6 views
        0 likes
        Last Post JoMoon2024  
        Started by Haiasi, 04-25-2024, 06:53 PM
        2 responses
        19 views
        0 likes
        Last Post Massinisa  
        Started by Creamers, Today, 05:32 AM
        0 responses
        6 views
        0 likes
        Last Post Creamers  
        Started by Segwin, 05-07-2018, 02:15 PM
        12 responses
        1,786 views
        0 likes
        Last Post Leafcutter  
        Working...
        X