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 averages not same as chart's avgs

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

    RSI averages not same as chart's avgs

    Hello,

    This chart shows RSI average values that are not the same as the Data Box's RSI average values. I thought the index [1], etc would pull the correct values but it is not. Is the syntax incorrect somewhere in the code? See chart in attached.

    Thanks in advance!

    Code:
    namespace NinjaTrader.Strategy
    {
        public class ShowRSIvalue : Strategy
        {
            #region Variables
    		private DataSeries rsi;
    		private DataSeries avg;
            #endregion
    
            protected override void Initialize()
            {
                CalculateOnBarClose = false;
    			Add(RSI(9,3));
    			rsi = new DataSeries(this);
    			avg = new DataSeries(this);
            }
            protected override void OnBarUpdate()
            {
    			rsi.Set(Math.Round((RSI(9,3)[0]),2));
    			avg.Set(Math.Round((RSI(9,3)[1]),2));
    			DrawTextFixed("RSI", "RSI 0: " + rsi[0] + "  " + avg[0]
    			+ "\nRSI 1: " + rsi[1] + "  " + avg[1]
    			+ "\nRSI 2: " + rsi[2] + "  " + avg[2]
    			+ "\nRSI 3: " + rsi[3] + "  " + avg[3]
    			+ "\nRSI 4: " + rsi[4] + "  " + avg[4]
    			+ "\nRSI 5: " + rsi[5] + "  " + avg[5]
    			,TextPosition.Center,Color.Yellow,new Font("Arial",18),Color.Black,Color.Black,10);
            }
    Attached Files

    #2
    Hello,

    Thank you for the question.

    I am looking at the Image you have provided and would like to clarify your question.

    I see that in the image you have the mouse hovering 1 bar in the past, the code which is getting the RSI for 1 bar in the past is the same value.

    Can you please clarify the question as to what you are trying to correct?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Data Box's RSI avg has 52.48 while chart's text has 50.31. All the remaining averages on the chart are not same to Data Box's values (Avg) when pointing specific bar. See next chart attached.

      Thanks.
      Attached Files

      Comment


        #4
        The code of your strategy is flawed.

        Math.Round((RSI(9,3)[1]),2) calls the RSI 1 bar ago.

        If you wish to call the RSI average for the current bar, then the correct formula would be

        Code:
        avg.Set(Math.Round(RSI(9,3).Avg[0],2);

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TheWhiteDragon, 01-21-2019, 12:44 PM
        4 responses
        541 views
        0 likes
        Last Post PaulMohn  
        Started by GLFX005, Today, 03:23 AM
        0 responses
        2 views
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Started by XXtrader, Yesterday, 11:30 PM
        2 responses
        11 views
        0 likes
        Last Post XXtrader  
        Started by Waxavi, Today, 02:10 AM
        0 responses
        7 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Started by TradeForge, Today, 02:09 AM
        0 responses
        14 views
        0 likes
        Last Post TradeForge  
        Working...
        X