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

SMA Wrong Values

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

    SMA Wrong Values

    For some reason I can't get the correct value for the 200 SMA on the H1 or the higher timeframe, H4. I attached the code below.

    Also on the chart on the higher timeframe seems to be lagging, see the image attached. What am I doing wrong?

    Thanks!!
    Attached Files

    #2
    Hello mrmistermike2016,

    The indicators on your chart are being manually added, is this correct?

    The script you have supplied does not call AddChartIndicator().

    Added to the script is an additional series with 240 minutes. This series will also trigger OnBarUpdate() for each bar close.

    The script is set to print the values of the indicators any time either bar closes.

    For the script to update on real-time Calculate must be set to OnEachTick.
    For this to work historically TickReplay has to be turned on.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I built this code with the strategy builder and unlocked it. When the bar closes of the primary data series, shouldn't it print the correct values for the 200 SMA for the primary data series and the additonal data series, 240 minutes?

      If I run it when the market is open, will the values be correct?

      Thanks in advance!!

      Comment


        #4
        I tried it again with the strategy builder and I can not get the correct values for 200 SMA on a higher timeframe. Please test this to see if you can't duplicate this issue.

        Thanks in advance!!

        Comment


          #5
          I'm having the same issue with a very basic scenario. Would be nice to see if this is a bug or my error.

          Thanks!!

          Comment


            #6
            Hello mrmistermike2016,

            Without making any changes to your script, I have manually added the indicators to the chart and compared this with the prints made by the script.

            These are matching. Below is a link to a video demonstrating.
            Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


            I am not able to reproduce this behavior.

            To avoid confusion, I highly recommend that you ensure you know which BarsInProgress is processing and also print the time of the bar with the print.

            Just as a heads up, the indicator applied to the secondary series is not plotting correctly but is showing the correct values.
            We've got this behavior reported to our development.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thanks Chelsea. I do print the barsinprogress, I just sent you a watered down version. But does it really matter? Shouldn't it print the same values? Meaning, when the bars in progress is H1, the H4 200 SMA, will be the same when its the bar in progress?

              Thanks!!

              Comment


                #8
                Hello mrmistermike2016,

                Without timestamps and BarsInProgress in the print, it is impossible to know which print goes with which value on the chart. This leads to a lot of guessing and is not a good way to debug a script.

                No, the SMA1 will not be equal to the SMA2 no matter the bars in progress. However, for most bars SMA1 will be the same in both BarsInProgress 0 and BarsInProgress 1.

                That said, I have made a video demonstrating I was not able to reproduce the behavior. Have I taken the correct steps in the video?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hey Chelsea, I'm at work so I can't test it. I'll let you know when I get home. But it's very similar to what you did.

                  Thanks!!

                  Comment


                    #10
                    I did some testing and I found that the results changed base on the # of days I used in the data series, which shouldn't be the case. I tested this with H1 and H4.

                    Thanks!!
                    Attached Files

                    Comment


                      #11
                      Hello mrmistermike2016,

                      Both scripts are added to the same chart correct? Both would be using the same data source and number of days correct?

                      If the SMA indicator uses a different amount of days or different set of data, the results will be different.

                      When you mention "I found that the results changed base on the # of days I used in the data series, which shouldn't be the case" are you expecting the SMA to give the same value no matter how much data is used for the calculations?
                      Are you expecting different amounts of data to produce the same results?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        DUH!! It was early ...LOL!! Ok, I'll test some more later today.

                        Thanks!!

                        Comment


                          #13
                          Thanks Chelsea, that was it. I was loading different # of days on the chart. And since I added the strategy from the control center I could change the # of days and that's what threw it off.

                          Thanks!!

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by TheMarlin801, 10-13-2020, 01:40 AM
                          20 responses
                          3,914 views
                          0 likes
                          Last Post Bidder
                          by Bidder
                           
                          Started by timmbbo, 07-05-2023, 10:21 PM
                          3 responses
                          150 views
                          0 likes
                          Last Post grayfrog  
                          Started by Lumbeezl, 01-11-2022, 06:50 PM
                          30 responses
                          805 views
                          1 like
                          Last Post grayfrog  
                          Started by xiinteractive, 04-09-2024, 08:08 AM
                          3 responses
                          11 views
                          0 likes
                          Last Post NinjaTrader_Erick  
                          Started by Johnny Santiago, 10-11-2019, 09:21 AM
                          95 responses
                          6,194 views
                          0 likes
                          Last Post xiinteractive  
                          Working...
                          X