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

Data box shows different value than strategy

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

    Data box shows different value than strategy

    I have RSI and EMA of RSI (with RSI as input series). On the databox it shows the correct values for the EMA and RSI, however when I add the code to the strategy and get values, the EMA shows a different value. Thanks!!

    #2
    Perhaps one of them is rounding the value, and the other is not?

    Any chance you could throw us a bone and give an example of
    of the values you're talking about?

    Comment


      #3
      It is not just rounding. The values are very different. On the chart, I add RSI of 12 smoothing 3, and then add EMA 43 with the Input series of RSI (12,3).

      In the strategy my code is code -
      RSI1 = RSI(Close, Convert.ToInt32(12), 3);
      EMA1 = EMA(RSI1, 43);

      On the chart (Data box) the values
      RSI - 63.44
      EMA of RSI - 53.69

      and on the Strategy debug mode the
      RSI - 56.9177110180709---
      EMA of RSI - 49.7395368011012​

      Comment


        #4
        Hello Graci117,

        Thanks for your post.

        When you mention "and on the Strategy debug mode" are you referring to adding Prints to your script that print out the values to a New > NinjaScript Output window?

        I have created a simple indicator that plots the RSI and EMA values you shared and prints them to a NinjaScript Output window. When comparing the values from the test script to the RSI and EMA indicators that come default with NinjaTrader using the same exact properties as the code, I am seeing values that match in the chart, Data Box, and NinjaScript Output window.

        See the attached screenshot.

        Also, see the attached script used to test this.​
        Attached Files
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thank you! That's exactly what I am doing - using the print statements and comparing it with the databox. I don't see the script here. Could you please post the script as well and the screenshot of the indicator parameters on GraciTest??

          Comment


            #6
            Hello Graci117,

            Thanks for your notes.

            You could find the test script attached in post # 4. Attached you'll find the images for the RSI and EMA indicator parameters I used for comparison.

            I have also attached the script to this post.
            Attached Files
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_BrandonH View Post
              Hello Graci117,

              Thanks for your notes.

              You could find the test script attached in post # 4. Attached you'll find the images for the RSI and EMA indicator parameters I used for comparison.

              I have also attached the script to this post.
              Thanks! I don't see the script attached to post#4 or this post. The only attached file is the screenshot in both cases.

              Comment


                #8
                Hello Graci117,

                Thanks for your note.

                It seems the Forums hid the scripts from view. I have made them visible again so that you could view them.

                Attached to this post I have also added a screenshot of the test indicator's code.
                Attached Files
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_BrandonH View Post
                  Hello Graci117,

                  Thanks for your note.

                  It seems the Forums hid the scripts from view. I have made them visible again so that you could view them.

                  Attached to this post I have also added a screenshot of the test indicator's code.
                  Unfortunately, the script is still not available. I tried to create the indicator and for some reason when I try to add the indicator I get this error on the output window -

                  Indicator 'RSIMA': Error on calling 'OnBarUpdate' method on bar 10: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                  And on the strategy code I get this error =

                  Strategy 'FILevelsOMARSI/-1': An order placed at '06/01/2023 09:41:00' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met.

                  Comment


                    #10
                    Originally posted by Graci117 View Post

                    Unfortunately, the script is still not available. I tried to create the indicator and for some reason when I try to add the indicator I get this error on the output window -

                    Indicator 'RSIMA': Error on calling 'OnBarUpdate' method on bar 10: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                    And on the strategy code I get this error =

                    Strategy 'FILevelsOMARSI/-1': An order placed at '06/01/2023 09:41:00' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met.
                    Can you please help??

                    Comment


                      #11
                      Hello Graci117.

                      Thanks for your note.

                      Please see the test script attached on post # 6 as seen in the attached screenshot.

                      The error message "You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart." means that you are trying to access an invalid index. A more simple example using one series would be on bar 5 you check for 6 BarsAgo. There are not yet 6 bars so the CurrentBar minus 6 would be a negative number or a non-existent bar.

                      A CurrentBar check could be used in your indicator's logic to ensure that a certain number of bars have processed before the indicator begins calculation. A CurrentBar check would look something like this.

                      Code:
                      if (CurrentBar < 10)
                          return;
                      This would check to make sure that 10 bars have processed before the indicator begins it's calculations.

                      See the help guide documentation below for more information.
                      CurrentBar - https://ninjatrader.com/support/help...currentbar.htm
                      CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm
                      Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm


                      The second "error" is simply a warning message letting you know that the strategy tried to place a trade before the BarsRequiredToTrade property was met. The BarsRequiredToTrade property is set to 20 by default and means that there must be at least 20 bars on the chart before a trade is placed.

                      You could consider setting this property to 0 in the Properties section of the Strategies window when enabling your strategy.

                      See this help guide about the BarsRequiredToTrade property: https://ninjatrader.com/support/help...totrade​
                      Attached Files
                      Brandon H.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by AaronKoRn, Today, 09:49 PM
                      0 responses
                      1 view
                      0 likes
                      Last Post AaronKoRn  
                      Started by carnitron, Today, 08:42 PM
                      0 responses
                      6 views
                      0 likes
                      Last Post carnitron  
                      Started by strategist007, Today, 07:51 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post strategist007  
                      Started by StockTrader88, 03-06-2021, 08:58 AM
                      44 responses
                      3,975 views
                      3 likes
                      Last Post jhudas88  
                      Started by rbeckmann05, Today, 06:48 PM
                      0 responses
                      9 views
                      0 likes
                      Last Post rbeckmann05  
                      Working...
                      X