Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator Plot v. Strategy Calculation problem

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

    Indicator Plot v. Strategy Calculation problem

    Hello.

    I have created a custom indicator which plots two moving averages.

    I took the code that is used to calculate the plots from the indicator and put it into a strategy. After adding some debug prints to the output window, I find that the indicator as displayed on the chart does not line up with the indicator calculations within the strategy I'm trying to build with it. I'm not sure why but it seems to be a few bars off.

    Any ideas?
    mrlogik
    NinjaTrader Ecosystem Vendor - Purelogik Trading

    #2
    I suggest debugging the "input" values and "output" values. If they are identical (including the first "BarsRequired" datapoints, see docs for details), then your calcs will yield the same results.

    Comment


      #3
      Note that if the strategy has CalculateOnBarClose set to false and the indicator doesn't by default then when you use the Add() method to add it to the strategy chart then the indicator's CalculateOnBarClose will change from the default. Thats even when you call the indicator directly from within OnBarUpdate, not just when you declare an instance of it...caught me out a few times.

      Comment


        #4
        Gumphrie.

        I have CalculateOnBarClose = true set in the initialize function of both the strategy and the indicator. It seems that in real time, using the output window, some of the values calculated are incorrect when compared to the historical values. I don't understand why the values are correct historically, but in forward testing they are different.

        Its the zerolagma indicator.

        thanks
        mrlogik
        NinjaTrader Ecosystem Vendor - Purelogik Trading

        Comment


          #5
          Hey Guys.

          I'm still having the same problem with values calculated in an indicator v. values calculated in a strategy.

          I have a basic stripped strategy that calculates at bar close and an indicator. I copied the functions from the indicator for use in the strategy. I have attached both.

          Looking at the internal values of both the indicator and strategy during back testing they are accurate. Forward testing, they yield different results. The indicator is a basic HMAs.

          I have prints from both the strategy and the indicator.

          "
          INDICATOR
          HMA1 = 1.5757751982684
          STRATEGY
          HMA1 = 0.94550581991342
          "

          Please take a look for me.
          The strategy is called test.
          The indicator is called hmatest.

          Any help is appreciated.

          Thanks
          Anthony
          Attached Files
          Last edited by mrlogik; 06-30-2008, 12:11 PM.
          mrlogik
          NinjaTrader Ecosystem Vendor - Purelogik Trading

          Comment


            #6
            I took a very quick look.

            For sure I can not comment on why it may or may no be different since you are not comparing an indicator being called from an indicator vs a strategy.

            What I suggest is build an indicator for FHMAc, then call this indicator from a strategy and call it from another indicator on a chart, make sure the underlying series is set up correctly and compare the values.

            If the underlying series is identical, then NT will hold only one internal reference to the FCHMAc indicator and thus any object needing the same instance of this indicator will use this reference and identical values will be generated.
            RayNinjaTrader Customer Service

            Comment


              #7
              Thanks for the response Ray. I will try what you have suggested.

              When you get a chance could you please take a closer look. The fact that the values only differ when new bars are created in realtime troubles me. Either I have an incorrect understand of how NT functions / processes data, or there is a bug. Either way I need to know whats going on in order to further my development. I would rather not call indicator values because I don't want to have some of the indicators on the chart for my strategy.

              Thanks for your time.
              Anthony
              mrlogik
              NinjaTrader Ecosystem Vendor - Purelogik Trading

              Comment


                #8
                I have taken a look and there is something that does not seem right to me. I have forwarded a simplied test case to development and should report back by tomorrow.
                RayNinjaTrader Customer Service

                Comment


                  #9
                  Ray.

                  Thank you for taking a look.

                  I created a function that basically does the three functions of an HMA via "for loops." It seems to work 100% in my strategy in both back testing and forward testing. Let me know how you make out, and if you would like me to post my function.

                  Anthony
                  mrlogik
                  NinjaTrader Ecosystem Vendor - Purelogik Trading

                  Comment


                    #10
                    Anthony,

                    We found an internal logic flaw pointed out by your sample. Thanks for that. For now, you will have to work around this by stuffing your FHMAc logic into an indicator and calling this indicator from another indicator or strategy. This is on our list to resolve for NT7. It only shows up as you use a custom data series in a strategy as input to an indicator.
                    RayNinjaTrader Customer Service

                    Comment


                      #11
                      Ray.

                      Thank you for checking into this for me. I wrote a WMA function and created a FHMAc function using for loops and such that seems to work fine for now.

                      Anthony
                      mrlogik
                      NinjaTrader Ecosystem Vendor - Purelogik Trading

                      Comment


                        #12
                        Hi Anthony!

                        I think, I have the same problem like you. I tried to use a custom indicator in my strategy but when it comes to smoothing with an EMA within the indicator-calculation the strategycode starts to produce wrong values, what means the indicator-value within the strategy is not the same like the values of the same indicator stated on the chart...

                        As I'm not a C#-Pro I don't know how to code a workaround for the EMA-smoothing. I tried, but I failed. Could you help me on that with a little code-snippet. Even if you only could upload your functions described above (WMA, FHMA), I'd be really glad. Maybe I'm able to figure out how it could work by myself. Or I simply use the WMA-smoothing...

                        thx a lot!!

                        Karl

                        Comment


                          #13
                          Hey Koal,

                          You can mess around with the following which is NTs built in MA function. The DataSeries Input is where you would put your "to be smoothed" data.

                          Code:
                          double maValue = MAV(DataSeries Input, iPeriod (int)NinjaTrader.Indicator.MAV.MAType.EMA)[0]);
                          mrlogik
                          NinjaTrader Ecosystem Vendor - Purelogik Trading

                          Comment


                            #14
                            Hi There,

                            I have also run into an issue where I am using a couple of custom data series in a strategy as input to an indicator. In this case, the strategy easily runs simple math on the custom data series (Subtraction), but as soon as I seek to take the result (stored as a 3rd custom dataseries in the strategy) and try to feed it into HMA, EMA or SMA to smooth it, the resulting values end up becoming 0 quickly (There are no errors in the log).

                            I tried the MAV code below, but had trouble compiling it. Is the only work around to reproduce the indicator logic (Eg. EMA or HMA) inside the strategy feeding it the custom dataseries?

                            Thanks for the help,

                            Learning1

                            Comment


                              #15
                              On your DataSeries are you able to reference all the historical points correctly? myDataSeries[0] and myDataSeries[1] returns correctly?

                              Have you done myDataSeries = new DataSeries(this); inside the Initialize() method?
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              574 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              333 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              553 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              551 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X