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

Problems with indicator & strategy in RealTime

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

    #16
    Ok, i will remove that line from the indicator.

    I had mentioned several times that the indicator is working just fine.

    The problem I am having is that this same code executing in a strategy starts producing incorrect results as soon as the strategy encounters live data.

    When backtesting the strategy, the code produces accurate results. When the strategy is starting up but processing historical data, it produces accurate results. As soon as the first bar of live data enters the strategy, the calculations go haywire. There doesn't seem to be any logical explanation for that behavior.

    At this point, I am going to modify the strategy to spit out all of the underlying data so that i can more effectively demonstrate the problem.

    Comment


      #17
      If you feel it is a live issue you will unfortunately just have to slowly step through it and see what is happening with the calculations.
      Josh P.NinjaTrader Customer Service

      Comment


        #18
        Ok, I have been working on trying to understand what is happening with this strategy. I've got some data that shows where the problem begins, but not why. The text below shows the output from the strategy and the indicator both during start up and real time. The indicator output is real time, while the strategy output is a mixture of historical (during startup) and real time. The strategy has processed it's first real-time bar where it says it has successfully started up.

        9/2/2009 1:40:21 PM : INDICATOR wERG Value = 0.582960213618333
        9/2/2009 1:40:21 PM : INDICATOR Ergodic Value = 0.698020440981886
        9/2/2009 1:40:21 PM : INDICATOR FAST/SLOW = 49/147
        9/2/2009 1:40:21 PM : STRATEGY wERG Value = 0.582960213618333
        9/2/2009 1:40:21 PM : STRATEGY ERGodic Value = 0.698020440981886
        9/2/2009 1:40:21 PM : STRATEGY FAST/SLOW = 49/147
        9/2/2009 1:41:05 PM : INDICATOR wERG Value = 0.471583001733282
        9/2/2009 1:41:05 PM : INDICATOR Ergodic Value = 0.688962943411942
        9/2/2009 1:41:05 PM : INDICATOR FAST/SLOW = 49/147
        9/2/2009 1:41:05 PM : STRATEGY wERG Value = 0.471583001733282
        9/2/2009 1:41:05 PM : STRATEGY ERGodic Value = 0.688962943411942
        9/2/2009 1:41:05 PM : STRATEGY FAST/SLOW = 49/147
        9/2/2009 1:41:40 PM : INDICATOR wERG Value = 0.407763613563059
        9/2/2009 1:41:40 PM : INDICATOR Ergodic Value = 0.677714970217987
        9/2/2009 1:41:40 PM : INDICATOR FAST/SLOW = 49/147

        9/2/2009 1:42:01 PM : INDICATOR wERG Value = 0.345120796218637
        9/2/2009 1:42:01 PM : INDICATOR Ergodic Value = 0.664411203258013
        9/2/2009 1:42:01 PM : INDICATOR FAST/SLOW = 49/147
        9/2/2009 1:42:01 PM : STRATEGY wERG Value = 0.407763613563059
        9/2/2009 1:42:01 PM : STRATEGY ERGodic Value = 0.677714970217987
        9/2/2009 1:42:01 PM : STRATEGY FAST/SLOW = 49/147
        9/2/2009 1:43:44 PM : INDICATOR wERG Value = 0.282900887715762
        9/2/2009 1:43:44 PM : INDICATOR Ergodic Value = 0.649150790636323
        9/2/2009 1:43:44 PM : INDICATOR FAST/SLOW = 49/147
        STRATEGY STARTED SUCCESSFULLY!
        9/2/2009 1:43:44 PM : STRATEGY wERG Value = 0.345120796218637
        9/2/2009 1:43:44 PM : STRATEGY ERGodic Value = 0.650606371409267
        9/2/2009 1:43:44 PM : STRATEGY FAST/SLOW = 49/147
        9/2/2009 1:45:54 PM : INDICATOR wERG Value = 0.221637022522569
        9/2/2009 1:45:54 PM : INDICATOR Ergodic Value = 0.632050239911773
        9/2/2009 1:45:54 PM : INDICATOR FAST/SLOW = 49/147
        9/2/2009 1:45:54 PM : STRATEGY wERG Value = 0.282900887715762
        9/2/2009 1:45:54 PM : STRATEGY ERGodic Value = 0.624582116552897
        9/2/2009 1:45:54 PM : STRATEGY FAST/SLOW = 49/147
        9/2/2009 1:52:01 PM : INDICATOR wERG Value = 0.163495205313317
        9/2/2009 1:52:01 PM : INDICATOR Ergodic Value = 0.613308038527834
        9/2/2009 1:52:01 PM : INDICATOR FAST/SLOW = 49/147
        9/2/2009 1:52:01 PM : STRATEGY wERG Value = 0.221637022522569
        9/2/2009 1:52:01 PM : STRATEGY ERGodic Value = 0.599598831890781
        9/2/2009 1:52:01 PM : STRATEGY FAST/SLOW = 49/147
        9/2/2009 1:54:27 PM : INDICATOR wERG Value = -0.0813005007681778
        9/2/2009 1:54:27 PM : INDICATOR Ergodic Value = 0.581863058299869
        9/2/2009 1:54:27 PM : INDICATOR FAST/SLOW = 49/147
        9/2/2009 1:54:27 PM : STRATEGY wERG Value = 0.163495205313317
        9/2/2009 1:54:27 PM : STRATEGY ERGodic Value = 0.575614878615149
        9/2/2009 1:54:27 PM : STRATEGY FAST/SLOW = 49/147
        9/2/2009 1:55:06 PM : INDICATOR wERG Value = -0.321677315059425
        9/2/2009 1:55:06 PM : INDICATOR Ergodic Value = 0.543892290872806
        9/2/2009 1:55:06 PM : INDICATOR FAST/SLOW = 49/147
        9/2/2009 1:55:06 PM : STRATEGY wERG Value = 0.0134546772898955
        9/2/2009 1:55:06 PM : STRATEGY ERGodic Value = 0.552590283470544
        9/2/2009 1:55:06 PM : STRATEGY FAST/SLOW = 49/147
        9/2/2009 1:56:57 PM : INDICATOR wERG Value = -0.603946692354537
        9/2/2009 1:56:57 PM : INDICATOR Ergodic Value = 0.496150718531414
        9/2/2009 1:56:57 PM : INDICATOR FAST/SLOW = 49/147
        9/2/2009 1:56:57 PM : STRATEGY wERG Value = -0.180215058363466
        9/2/2009 1:56:57 PM : STRATEGY ERGodic Value = 0.530486672131722
        9/2/2009 1:56:57 PM : STRATEGY FAST/SLOW = 49/147
        9/2/2009 1:58:00 PM : INDICATOR wERG Value = -0.83324726691938
        9/2/2009 1:58:00 PM : INDICATOR Ergodic Value = 0.442974799113382
        9/2/2009 1:58:00 PM : INDICATOR FAST/SLOW = 49/147
        9/2/2009 1:58:00 PM : STRATEGY wERG Value = -0.416199039452591
        9/2/2009 1:58:00 PM : STRATEGY ERGodic Value = 0.509267205246453
        9/2/2009 1:58:00 PM : STRATEGY FAST/SLOW = 49/147


        Note that there is a bar processed by the indicator that is not processed by the strategy. This happens consistently each and every time i start up the strategy -- there is always one bar missing from the strategy list, otherwise the strategy and indicator output match up 100%. The missing bar always seems to be a couple of bars before the strategy finishes starting up.

        As soon as the bar is missed, the calculations diverge and only grow farther apart as time goes on.

        I think there may be even more at play, but so far this is what I have found.

        Comment


          #19
          I should also note I am using volume bars.

          Comment


            #20
            You should only compare apples to apples. Print what you see from the indicators as accessed by the strategy. Embedded indicators can NOT have a CalculateOnBarClose line.
            Josh P.NinjaTrader Customer Service

            Comment


              #21
              The strategy is not calling the indicator. I have recoded the indicator logic into my strategy. What I am comparing is the indicator running on a chart and the strategy running independently.

              Would I be better off leaving the logic in the indicator and somehow call the indicator from the strategy? Is there sample code on this somewhere?

              Comment


                #22
                Yes, you should try calling the indicator from the strategy. You can do this simply by going something like Print(SMA(20)[0]); from the strategy if your indicator name was SMA.
                Josh P.NinjaTrader Customer Service

                Comment


                  #23
                  Ok i have a pretty simple question -- my custom indicator is pretty complicated, it has several plots and values that it calculates. When calling an indicator the way you suggested, what dataset or variable determines what is returned by the indicator?


                  Thanks

                  Comment


                    #24
                    Whichever plot is the main plot. If you want other values you need to access those plots accordingly. Please take a look at the help guide article for MACD to get an example.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #25
                      Found it ....Values[0] or Value is the main indicator value. I can work with that....

                      thanks

                      Comment


                        #26
                        I am going to switch over and try to call the indicator from the strategy, but at the same time I would like to get to the bottom of why the current implementation is not working.

                        I am getting close to having the problem isolated. It appears to be the following line speficically:

                        medium_wErgodic.Set(EMA(medium_wERG, 49)[0]);

                        This is a pretty simple statement -- just an EMA of a data series. When this statement runs over historical data, it works fine. However, when the real time bars start coming in, the value produced by this statement slowly works its way to zero. It kind of seems like the medium_wERG is no longer being populated, but here is the odd part -- I am printing out the contents of the medium_wERG and it does appear to be populated!

                        Is it possible that the EMA indicator is bugged in some way that it would not see the same contents of the data series that I am seeing?


                        Just wanted to see if this might be some sort of known issue. Tomorrow morning I will post the contents of the medium_wERG data series along with the output value produced by the EMA statement. It will demonstrate that the EMA command is producing a value not in line with the underlying dataseries contents.

                        Thanks,
                        Brandon

                        Comment


                          #27
                          There could be any number of reasons they aren't equal. You will just have to slowly step through the code and debug to see where the difference is.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #28
                            Below is the strategy code I am executing. I have it logging all the variable values and output to demonstrate the problem. I am highlighting the line in red which is producing bad values -- it is a simple EMA on a data series. Here is the code:

                            ...
                            medium_wERG.Set(WMA(WMA(medium_absclosediff,fast), slow)[0] == 0 ? 0 : 100 * WMA(WMA(medium_closediff,fast),slow)[0] / WMA(WMA(medium_absclosediff,fast),slow)[0]);

                            medium_wErgodic.Set(EMA(medium_wERG,fast)[0]);

                            medium_wERGhist.Set(72*(medium_wErgodic[0]-medium_wErgodic[1]));


                            int limit = 0;
                            if (CurrentBar < 50)
                            {
                            limit = CurrentBar;
                            }
                            else{
                            limit = 50;
                            }

                            Print(Time[0] + " : STRATEGY wERG Value = " + medium_wERG[0]);
                            Print(Time[0] + " : STRATEGY ERGodic Value = " + medium_wErgodic[0]);
                            Print(Time[0] + " : STRATEGY FAST/SLOW = " + fast + "/" + slow);

                            Print(Time[0] + " : STRATEGY wERG Series = ");

                            for(int i = 0; i < limit; i++)
                            {
                            Print(" :" +medium_wERG[i]);
                            }
                            ...

                            Below is the output that was generated from the execution of this code when run against real time data. Also included is some output from an indicator that was running the same code at the same time (separately). The most important thing to notice is that I have printed out the contents of the medium_wERG dataseries, and those contents show the last 50 values which appear to be correct. The EMA value produced by the line highlighted above is clearly not the correct value that should be produced given the contents of the underlying dataseries. I think I have isolated this problem down to this single line, and i've logged all the inputs and outputs to this line of code, and from my interpretation of the results a value is being produced which is just not correct. This code works just fine on historical data. ON real time data, the value of the EMA call decreases consistently until it eventually reaches near 0.

                            If I am misinterpreting something in this execution or overlooking something, please let me know.

                            Thanks





                            9/3/2009 4:14:37 PM : INDICATOR wERG Value = 22.0525516311123
                            9/3/2009 4:14:37 PM : INDICATOR Ergodic Value = 20.5320847955339
                            9/3/2009 4:14:37 PM : INDICATOR FAST/SLOW = 49/147
                            9/3/2009 4:14:37 PM: Bar Received
                            9/3/2009 4:14:37 PM: Bar Received
                            9/3/2009 4:14:37 PM: Bar Received
                            9/3/2009 4:14:37 PM: Medium Bar
                            9/3/2009 4:14:37 PM : STRATEGY wERG Value = 22.440866802202
                            9/3/2009 4:14:37 PM : STRATEGY ERGodic Value = 0.0317195951199318
                            9/3/2009 4:14:37 PM : STRATEGY FAST/SLOW = 49/147
                            9/3/2009 4:14:37 PM : STRATEGY wERG Series =
                            :22.440866802202
                            :22.6762244401219
                            :22.7402284026026
                            :22.8631964933051
                            :22.9047890954427
                            :22.8659811588866
                            :22.8326980799719
                            :22.8036998073209
                            :22.691838272414
                            :22.6879672169702
                            :22.7388265595227
                            :22.7905702198052
                            :22.8459762865466
                            :22.9045061829721
                            :22.9661169141271
                            :23.0290228486287
                            :23.1445873461958
                            :23.2619474383382
                            :23.4304569592316
                            :23.5222552605107
                            :23.7094422545845
                            :23.8184814264148
                            :23.7707031899475
                            :23.6418202336434
                            :23.5055779193318
                            :23.2883571311779
                            :23.0682871391319
                            :22.8448807147934
                            :22.6167231730066
                            :22.3841525606357
                            :22.146374901564
                            :21.8307851256726
                            :21.4365351872604
                            :21.0333074924943
                            :20.6645455358661
                            :20.3312510072299
                            :19.9910250418422
                            :19.6467507715343
                            :19.2975002558525
                            :18.9424867934842
                            :18.5817944302595
                            :18.2583267492372
                            :17.9266289752484
                            :17.5863495849865
                            :17.2371410043462
                            :16.8777593530392
                            :16.5508196646022
                            :16.254667060807
                            :15.9452204348462
                            :15.623796783804

                            Comment


                              #29
                              bridenour,

                              Please use something very simple. I will not be able to help you evaluate some fancy logic like ergodic. Just have the indicator/strategy print something like the CurrentBar it is processing along with a time stamp.
                              Josh P.NinjaTrader Customer Service

                              Comment


                                #30
                                I understand the surrounding logic is complex but the problem I am demonstrating is a fairly simple one and has little to do with the ergodic - it is that a simple EMA call on a data series is producing a crazy return value. I've included the values in the underlying data series that should demonstrate that the EMA value being returned is incorrect.

                                How does printing out the current bar and timestamp help to demonstrate the problem? I'm glad to provide different or additional information if it would be helpful. I felt I had boiled this down to its most basic aspects - that being a wacky value being returned from an EMA call.

                                I posted this in a thread where someone else had a similar problem involving dataseries and historical vs. real-time data, and someone (i believe it was you) responded that it was an underlying bug in the platform. My original intent was to understand what that defect was and whether or not I might be encountering the same thing.

                                I've invested quite a lot of time isolating this issue and providing what feels like demonstrable evidence of something flaky going on. This is after investing probably several hundred hours in the development of this strategy.

                                I guess this is a no win situation....I could isolate this logic out into a demo strategy that reproduces the problem, but thats only likely to result in a mutual agreement that yes it is a bug and no it won't be fixed, putting me back to square one again.

                                thanks

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by tradingnasdaqprueba, 04-09-2024, 09:52 AM
                                6 responses
                                26 views
                                0 likes
                                Last Post tradingnasdaqprueba  
                                Started by PaulMohn, Today, 02:06 AM
                                1 response
                                2 views
                                0 likes
                                Last Post PaulMohn  
                                Started by Mindset, Today, 01:27 AM
                                0 responses
                                4 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by EB Worx, 03-07-2023, 05:05 AM
                                4 responses
                                97 views
                                1 like
                                Last Post cls71
                                by cls71
                                 
                                Started by patricia70, 11-23-2020, 10:17 AM
                                17 responses
                                548 views
                                1 like
                                Last Post PaulMohn  
                                Working...
                                X