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

Cummulative rsi calculation

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

    Cummulative rsi calculation

    I'm trying to do something rather simple and it's just not working - My indicator comes up blank on the chart. What am I doing wrong? the code I came up with is a simple summation of a two period RSI for the last three bars. I don't see how it could be simpler! The plot just comes up with nothing calculated. I've saved and compiled. Any help on this would be greatly appreciated.


    protected override void OnBarUpdate()
    {
    //CALCULATE THE 2 PERIOD SUMMED RSI

    double CUMRSI = RSI(2,3)[0] + RSI(2,3)[1] + RSI(2,3)[2];

    Plot0.Set(CUMRSI);
    }

    Note: Today is my first day using NT - so be easy on me

    #2
    Hi ShruggedAtlas,

    It is always a good idea (in my opinion) to name your plots.

    In the Initialize() you need to have something like:
    Add(new Plot(Color.Cyan, PlotStyle.Line, "CumRSI"));

    In OnBarUpdate() you set the value:
    CumRSI.Set(...);

    In the properties you need to get the values you calculate.The following should work for you.

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries CumRSI
    {
    get { return Value[0]; }
    }

    If you have more than one plot chnage return Value[0]; to return Values[0];

    I hope this gets you going. :-)

    Last edited by Zeos6; 06-13-2011, 11:57 AM.

    Comment


      #3
      Hi ShruggedAtlas,

      If you apply indexing to values but do not see a plot, check the log tab of control center for any error messages. It's likely you're running into this issue:


      You can resolve by preventing bar processing for the first 3 bars.
      if (CurrentBar < 2) return;

      You can also consider using built in method SUM(), which accepts series as input.

      Plot0.Set(SUM(RSI(2,3), 3)[0]);
      Ryan M.NinjaTrader Customer Service

      Comment


        #4
        problem solved!

        Thanks RyanM! It turned out that it was in fact the problem you suggested. I checked the log and did indeed find error alerts notifying me of the problem. The code checking for current bar position was added and it fixed the problem. Also, the SUM function definitely shortens my code up a bit. Thx!

        Also thanks to Zeos6 for giving me some practical tips to make my code a bit more readable. I did name my plot as you suggested and it makes the code more understandable.

        Thx guys!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mongo, Today, 11:05 AM
        4 responses
        14 views
        0 likes
        Last Post Mongo
        by Mongo
         
        Started by traderqz, Today, 12:06 AM
        7 responses
        13 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by Skifree, Today, 03:41 AM
        5 responses
        13 views
        0 likes
        Last Post Skifree
        by Skifree
         
        Started by traderqz, Yesterday, 09:06 AM
        5 responses
        34 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by guillembm, Today, 11:25 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X