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

McClellan indicator discrepancy between Chart and Strategy

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

    #16
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello bltdavid,

    Yes, any host script must add the series added by any host script or an error will prevent the script from running.

    Closes[3] would be the 4th added series of the strategy. Anything compared with this must have the same instrument, bar type, interval, and same amount of historical data as the 4th added series added to the strategy.

    This adds a complexity and the calculations should be done similar to the example script I have posted in post #12.

    That said, I made a simple strategy test script that adds the McClellanOscillator with only the primary series while connected to CQG/Continuum, then opened a second chart with the same instrument, bar type, interval, (30 min ES 12-20), with 5 days to load and the values are exactly the same. There are no differences.
    Thank you ChelseaB!

    This makes sense. I will try updating my script logic to use your sample initialization steps. .

    Comment


      #17
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello CyberNate,

      An indicator processes data using the programmed logic in the script.

      If the logic isn't changing, the data is.

      Would you like to find out why the data is changing?

      If the script is running on a secondary series, make a copy of the indicator that also adds a second series and calculates values with that series.
      https://ninjatrader.com/support/foru...196#post820196

      The point of using AddChartIndicator() is that the values from the strategy will exactly match the values on the chart, which what I was understanding you wanted.


      I can explain differences by explaining differences in datafeeds, how historical data is processed, and by comparing real-time values with historical values.

      As an example, some scripts don't process historical data.

      Some data feeds don't have real-time data and the values on the values on the chart will change the moment a new chart is opened or the Reload All Historical Data is selected the chart.

      I'm having a little trouble understanding your response. Should I modify the strategy to sync all three data series with the primary, or should I be modifying the McClellan indicator to sync the ^ADV and ^DECL data series? You seem to indicate that the indicator itself must be modified as you mentioned copying the indicator.

      I already tried syncing the strategy data series. It didn't help.

      Trying to modify the indicator to sync the data series, I get the error
      "Indicator 'McClellanOscillatorRTH': Error on calling 'OnStateChange' method: Index was outside the bounds of the array."

      Debugging it, I see that the error is here:

      else if (State == State.DataLoaded)
      subtractADVDECL = new Series<double>(this);
      secondarySeries = new Series<double>(SMA(BarsArray[1], 1)); <--------------------
      thirdSeries = new Series<double>(SMA(BarsArray[2], 1));
      Last edited by CyberNate; 09-30-2020, 03:47 PM.

      Comment


        #18
        Hello CyberNate,

        The series used for calculations should be hard coded into both the strategy and indicator. The ^ADV and ^DECL must also be added to the primary.
        No matter what the chart primary series is, the indicator always uses the added hard coded series for data.

        To do this, you have to modify the code of the indicator. As the McClellanOscillator is distributed with NinjaTrader the code is locked. You have to make a copy of the script and modify the copy.

        With this, AddChartIndicator() can be used. With this the values received by the strategy will always match the chart.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello CyberNate,

          The series used for calculations should be hard coded into both the strategy and indicator. The ^ADV and ^DECL must also be added to the primary.
          No matter what the chart primary series is, the indicator always uses the added hard coded series for data.

          To do this, you have to modify the code of the indicator. As the McClellanOscillator is distributed with NinjaTrader the code is locked. You have to make a copy of the script and modify the copy.

          With this, AddChartIndicator() can be used. With this the values received by the strategy will always match the chart.
          Hello ChelseaB,

          I must not be following what you're saying. When I make the following mod to the McClellan Indicator to force the same data series as strategy, it fails right at this section when I try to sync the series with error even though I have loaded in more than a years worth of data for each series::

          Indicator 'McClellanOscillatorRTH': Error on calling 'OnStateChange' method: Index was outside the bounds of the array.

          Click image for larger version  Name:	indicator_code.PNG Views:	0 Size:	381.9 KB ID:	1120718


          I should add, if I comment those 3 sync lines out the indicator compiles and works, but I the indicator is still incorrect in the strategy.
          Last edited by CyberNate; 09-30-2020, 04:59 PM.

          Comment


            #20
            Click image for larger version

Name:	debug.PNG
Views:	101
Size:	203.5 KB
ID:	1120720

            Comment


              #21
              I don't see how to apply the sync to McClellan. Please help if you can. I really need to get this working correctly. In the strategy I was able to sync the different series as you've described, but in the indicator itself, I cannot get past this OutOfRangeException. I've tried various ways of adding the data series.
              Last edited by CyberNate; 09-30-2020, 05:19 PM.

              Comment


                #22
                I have simplified the test further by removing secondary ES series and only have the ^ADV and ^DECL series added, running strategy on 30min chart. Again the issue shows up. Yes, the strategy does match the chart that it's on, but it does not match a second chart which has same settings and no strategy. I see the discrepancy occurs with the 2nd bar after RTH open. On left is the chart that has strategy and on right is standalone chart with same indicator. You see how they match exactly and then that second bar comes and out of sync. Do you still believe this is a synchronization issue between the ADV/DECL and primary series? I have synced in strategy, but I can't figure out how to do it in the indicator.



                Click image for larger version  Name:	shot1.PNG Views:	0 Size:	335.0 KB ID:	1120728

                Click image for larger version  Name:	shot2.PNG Views:	0 Size:	336.0 KB ID:	1120729
                Last edited by CyberNate; 09-30-2020, 06:55 PM.

                Comment


                  #23
                  Hello CyberNate,

                  I've been testing using CQG/Continuum which was stated in post #4.

                  Are you able to reproduce this behavior with CQG/Continuum?

                  For playback, have you recorded ^DECL and ^ADV from a live stream? I don't believe is available for download.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Is I use OnPriceChange calculation with condition "if (BarsInProgress == <30min series index> && IsFirstTickOfBar) " I see that bars ago 1, 2 show correct McClellan values, but bar 0 is showing a much extreme value not matching. I would expect bar 0 to be the last 30 minute close, but apparently I'm mistaken . I guess IsFirstTickOfBar does not work the way I think, only relevant for main bar series. Anyway, I wish I could get this working with OnBarClose as it is very painful to backtest OnPriceChange or OnEachTick.

                    Comment


                      #25
                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hello CyberNate,

                      I've been testing using CQG/Continuum which was stated in post #4.

                      Are you able to reproduce this behavior with CQG/Continuum?

                      For playback, have you recorded ^DECL and ^ADV from a live stream? I don't believe is available for download.
                      ^ADV and ^DECL data is available for download from both Kinetic and CQG. I've download the last 3 contracts worth of data for backtesting. I try to use CQG as there is a difference in data between the 2 providers.

                      Yes, I have reproduced the issue with both when running OnBarClose calculation. I will need to verify if OnPriceChange is working correctly. OnPriceChange seems to be working on live data at the moment if I check bars ago 1 and back. Current bar is not correct as stated above, but bars ago 1 appears to be the last 30 min bar close.
                      Last edited by CyberNate; 10-01-2020, 10:48 AM.

                      Comment


                        #26
                        Hello CyberNate,

                        Historical data and Market Replay data are not the same thing.

                        You have Market Replay selected in the Playback. This will not use historical data for the playback.

                        So the data you have Kinetick and CQG will not apply here.

                        I was not able to confirm, are you able to reproduce this behavior while connected CQG/Continuum?

                        Currently, I am only testing with OnBarClose. I am not able to reproduce.

                        I may need to schedule a call to verify on your end that you are actively connected to CQG/Continuum and have you open two new charts with default settings, a simple test strategy with only the AddChartIndicator() and no other added series added to one chart and the indicator directly added to the other.
                        Last edited by NinjaTrader_ChelseaB; 10-01-2020, 10:54 AM.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #27
                          You see here that when I use OnPriceChange, McClellan is correct at bars ago 1 and older where 1 bar back is latest 30m close. This strategy has been running all morning. That's a good sign. I would prefer to get OnBarClose to work correctly as well to make backtesting fast, but if I have to, could run this way. Click image for larger version

Name:	McClellanOnPriceChange.PNG
Views:	100
Size:	135.3 KB
ID:	1120846

                          Comment


                            #28
                            Hello CyberNate,

                            What are you connected to while testing this?

                            I can't confirm if these values are correct or not.

                            I don't see another chart you are comparing with.

                            Is this being added with AddChartIndicator and compared with values to the strategy?

                            I think the issue is you are connected to Playback using Market Replay Data and you don't have the market relay data.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #29
                              Originally posted by NinjaTrader_ChelseaB View Post
                              Hello CyberNate,

                              What are you connected to while testing this?

                              I can't confirm if these values are correct or not.

                              I don't see another chart you are comparing with.

                              Is this being added with AddChartIndicator and compared with values to the strategy?

                              I think the issue is you are connected to Playback using Market Replay Data and you don't have the market relay data.
                              This is live data and the chart you see is a standalone chart. The NinjaScript output is coming from the strategy. So in this case you see that the strategy is matching the chart. The data is correct. If I use the AddChartIndicator() the chart will always match the strategy, but that is not meaning anything as both are simply wrong. I want the data to be correct and generally the standalone chart is showing the correct data whether running Market Replay or running Live.

                              Comment


                                #30
                                Hello CyberNate,

                                The point of using AddChartIndicator() is so that you don't have to check data and settings to make sure they match and that the indicator begins processing data at the same time for the chart and the strategy.

                                To confirm you are connected to CQG, you are using a new test script that just adds the ^DECL and ^ADV and calls AddChartIndicator and there are no other series added to the strategy and Calculate is OnBarClose, and only the print of the value is in OnBarUpdate and no other logic?

                                Send an email to platformsupport [at] ninjatrader [dot] com with a link to this forum thread so that we may schedule call so that I may confirm these. So far it seems we may not be testing the same thing that we started with in post #4 as somehow the playback is involved.


                                After we confirm you are doing the same thing i am testing, the next step I recommend you start adding prints to find out what is different in the data.

                                In the indicator print the Time, the BarsInProgress, the state, and the Close value for all series in OnBarUpdate. Print the bar type, interval, instrument, and break at eod in state.configure.

                                Test over a very small amount of data and then include the output from the prints with your reply. With that information we should be able to spot what is different.

                                Below is a link to a forum post that demonstrates using prints to understand behavior.
                                Chelsea B.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by GussJ, 03-04-2020, 03:11 PM
                                11 responses
                                3,229 views
                                0 likes
                                Last Post xiinteractive  
                                Started by andrewtrades, Today, 04:57 PM
                                1 response
                                14 views
                                0 likes
                                Last Post NinjaTrader_Manfred  
                                Started by chbruno, Today, 04:10 PM
                                0 responses
                                7 views
                                0 likes
                                Last Post chbruno
                                by chbruno
                                 
                                Started by josh18955, 03-25-2023, 11:16 AM
                                6 responses
                                441 views
                                0 likes
                                Last Post Delerium  
                                Started by FAQtrader, Today, 03:35 PM
                                0 responses
                                12 views
                                0 likes
                                Last Post FAQtrader  
                                Working...
                                X