• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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.
            https://www.screencast.com/t/hJsi4H0E00S

            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 TazoTodua, Today, 01:50 AM
                          3 responses
                          18 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by b16_aln, Today, 08:53 AM
                          1 response
                          18 views
                          0 likes
                          Last Post NinjaTrader_Kate  
                          Started by learningnt, Yesterday, 10:52 PM
                          1 response
                          10 views
                          0 likes
                          Last Post NinjaTrader_ChrisL  
                          Started by U0000999, Today, 07:31 AM
                          3 responses
                          11 views
                          0 likes
                          Last Post NinjaTrader_PaulH  
                          Started by TheGameOfProbabilities, Today, 06:56 AM
                          5 responses
                          25 views
                          0 likes
                          Last Post NinjaTrader_Tyler  
                          Working...
                          X