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 JonesJoker, 04-22-2024, 12:23 PM
        6 responses
        32 views
        0 likes
        Last Post JonesJoker  
        Started by GussJ, 03-04-2020, 03:11 PM
        12 responses
        3,239 views
        0 likes
        Last Post Leafcutter  
        Started by AveryFlynn, Today, 04:57 AM
        0 responses
        5 views
        0 likes
        Last Post AveryFlynn  
        Started by RubenCazorla, 08-30-2022, 06:36 AM
        3 responses
        79 views
        0 likes
        Last Post PaulMohn  
        Started by f.saeidi, Yesterday, 12:14 PM
        9 responses
        25 views
        0 likes
        Last Post f.saeidi  
        Working...
        X