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

Testing multi bar indicators

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

    Testing multi bar indicators

    I need to generate a triple smoothed TSI off a slower bar series than the underlying chart. Putting the 2nd bar series on the chart is not an option since NT screws up the X axis.

    Unfortunately, generating the indicator off the internal bar series is very inaccurate.

    I wrote a couple of tests. Test 1 is just an MA -- that works: the internally generated indicator does match the indicator on the same external bar series. See Chart1. Unfortunately, Test2 tries it with just the TSI indicator and it fails rather spectacularly. See Chart2.

    I cannot see why the second test doesn't work. Can some-one explain why the indicator calculates such wrong values when applied to an internal BIP=1 series?
    Both test cases are attached. They are very simple and similar to one another.
    Attached Files

    #2
    Lost Trader,

    First thing to check would most likely be ensuring you are actually having the correct, same session template applied to your various series objects. Please check which session template the various series are running on by printing the Bars.Session.TemplateName from each object.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      All are ES, all chart data series are set to use instrument settings, which are set via Instrument Manager to be ETH. All load the same # days.

      BIP 0 = CME US Index Futures ETH
      BIP 1 = CME US Index Futures ETH

      Sorry, that's not it.

      Comment


        #4
        Lost Trader,

        Line #42 in Test2. Your second data series you add is not the 25 minute series. This would be an apples to oranges comparison since the indicator is running on different series for calculations.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Line #42 in Test2. Your second data series you add is not the 25 minute series.
          Thanks for catching that, Josh, my bad. -- for a minute I thought you meant 5x5 wasn't 25 and I was confused. LOL. This series is supposed to be picking up the interval type from the underlying. I fixed Line 42 to be
          Add(BarsPeriod.Id, BarsPeriod.Value*_basePrime);
          where _basePrime is the primary input 5.

          Now the TSI matches, and I can work on getting the histogram to match.
          Attached Files

          Comment


            #6
            Please be aware that plotting data from higher time frame on a lower time frame will inherently result in a step-wise or ladder type result as you see. This is expected behavior due to the granularity available.

            A 5min series has 2 data points for every 10 minutes while a 1min series has 10 data points. On the 1 minute series as you keep polling the 5min series for values you end up with the same values most of the time since the 5min series hasn't updated data points yet. Result is the laddering you see in the plot.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Test4 Volume charts & Histogram plotting

              Yes, Josh, I know and expect that.

              Here's Test4 -- the histogram is not coming out right on Volume bars. The histogram bar is not being updated. It is being overwritten which leaves false artifacts behind. Obviously for a given bar, it should be updated, not overwritten. You will notice that on the minute chart, this problem does not appear but is very prevalent on Volume charts. How to fix?

              Only plotting from BIP=0 which should be fine as there are BasePrime=5 times more iterations if COBC=true.

              I switched to a volume chart because it needs to work on all underlying period types, not just time. That's why the x-axis is screwed, which is also why I need these working so we can get the correct indicator calcs w/o putting both bar series on the chart and screwing it.
              Attached Files

              Comment


                #8
                Lost Trader,

                Unfortunately you lost me. What exactly do you feel isn't working? I am not sure what you are trying to highlight in your screenshots. Also, what do you mean by "the x-axis is screwed"? Thanks for the clarification.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Look at the red circles on the volume chart. They show multiple colors on one bar. This is not correct.

                  The bars overall are no longer equidistant, hence screwed. I know y'all will not fix this as you did it deliberately. Focus on the histogram issue please.

                  Comment


                    #10
                    Sorry? Why do you feel it is multiple colors on the same bar? It is just overlapping values from the non-equidistant spacing. This is expected and accurate behavior.

                    Adding this line at the end of OnBarUpdate() will show exactly where each of your bar's values are.
                    DrawText(CurrentBar.ToString(), Values[1][0].ToString(), 0, Values[1][0], Color.Black);

                    Please see the attached screenshot. There are many bars in there all having the exact same timestamp. With the exact same timestamp means they will all be plotted on top of each other in a non-equidistant chart. When you use such small volume charts it is very common to have many bars with the exact same timestamp and the end result is as seen where things overlap. In the screenshot you can clearly see that each bar in the top 2 panels = 1 second spaced, but within that 1 second there are actually many bars underneath there all stacked exactly on top of each other. You can see this breakdown very easily from all the text objects being drawn in panel 3.
                    Attached Files
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Now you can see why I hate the skewed x axis. I did not originally see the overlap on the candles, but taking a closer look, it is there too. Thank you.

                      It will make it harder to check equivalency visually, but I will keep at it.

                      Comment


                        #12
                        OK, given a working signal & histogram by calling external indicators, I now need to embed the indicator calculations. So I went back to the simpler Test2 and made a copy Test2a which embeds the wTSI code instead of calling the indicator. That's it.

                        It matches on BIP=0 but not on BIP=1.

                        Test2a embedded code:
                        Code:
                        mtm.Set(Inputs[x][0]-Inputs[x][1]);            
                        absmtm.Set(Math.Abs(Inputs[x][0]-Inputs[x][1]));
                                        
                        Value.Set(WMA(WMA(absmtm,period1),period2)[0] == 0 ? 0 :
                                            WMA(WMA(mtm,period1),period2)[0] / WMA(WMA(absmtm,period1),period2)[0]);  // wTSI formula
                        Test2 version =
                        Code:
                        Value.Set(wTSI(Inputs[x], period1, period2)[0] );
                        Attached Files

                        Comment


                          #13
                          Test2 and Test2a's logic are not equivalent. You will not be able to just copy paste over the code like that.

                          Test2 calls wTSI() and asks it to run off Inputs[x]. When you ask it to use BIP=1 it goes off and only processes calculations based on the bars of BIP=1.

                          In Test2a you added in wTSI()'s code, but you are processing it from a BIP=0 context and not BIP=1. All of the math is completely different now. BIP=0 has significantly more bars than BIP=1. This results in a bunch more values and a completely different input series for your calculations than versus Test2. If you want Test2a to be equivalent to Test2 you will need to ensure you are still using the same exact number of calculation points. This means your custom DataSeries objects needs to be synced to the secondary Bars series instead of the primary and your calculation logic needs to be driven off BIP=1 and not BIP=0.

                          Edit: Please find attached the fixed version of your code. Obviously this is not fully tested code, but it should give you an idea of how to proceed. Please review it along with code comments inside there. Please also review the procedure here on syncing DataSeries objects to secondary Bars if you are not familiar with it already: http://www.ninjatrader.com/support/f...ead.php?t=3572
                          Attached Files
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            OK, I get that. except you also tell me that NT can only plot on BIP=0.
                            But yet doing this results in a flat line at 0?

                            Code:
                            if (BarsInProgress == x) 
                            {
                                        mtm.Set(Inputs[x][0]-Inputs[x][1]);            
                                        absmtm.Set(Math.Abs(Inputs[x][0]-Inputs[x][1]));
                            }    
                            if (BarsInProgress == 0) 
                                         Value.Set(WMA(WMA(absmtm,period1),period2)[0] == 0 ? 0 :
                                                WMA(WMA(mtm,period1),period2)[0] / WMA(WMA(absmtm,period1),period2)[0]);  // wTSI formula

                            Comment


                              #15
                              Please see my attached example in my prior post. There are caveats that can be used to plot otherwise as long as you fully understand your objective so plotting only from BIP0 is more a rule of thumb as it only generally makes sense to plot from there. For simplicity, you can do what I had in my code a different way too and still plot only from BIP0. Just store the calculated value into a variable to be set in BIP0.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rjbtrade1, 11-30-2023, 04:38 PM
                              2 responses
                              75 views
                              0 likes
                              Last Post DavidHP
                              by DavidHP
                               
                              Started by Stanfillirenfro, Today, 07:23 AM
                              3 responses
                              12 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by FitSpressoHonest, Today, 09:14 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post FitSpressoHonest  
                              Started by Davide999, 05-18-2023, 03:55 AM
                              4 responses
                              557 views
                              1 like
                              Last Post kcwasher  
                              Started by rexsole, Today, 08:39 AM
                              2 responses
                              8 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Working...
                              X