Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bug in ATR, TEMA, Lin Reg, and/or Indicator Initialization

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

    #16
    More Charts That Display The TEMA/ATR Problem

    Ray,

    I did not see my reply post to you from last night here, but I promised to submit more samples of the problem I am trying to explain to you. I basically said that the way NT calculates the Indicators is way off in the beginning of any chart or trading strategy. The way TradeStation, LTT, and ACM software calculates the Indicators, they are very accurate from the 1st requested bar. They all either use common sense in calculating the indicators before the proper number of bars can be obtained, or they load a ton of bars before the requested 1st bar to insure that the indicators are proper. NT does not do this at all. The indicators submitted below display clearly, that these values are way off. NT just asks the customer to throw away X bars at the beginning of the chart/trading system. It is up to the customer to calculate ahead of time, how many additional bars are required to be loaded before getting to the desired/requested starting bar. If this number is calculated/guessed properly, then the 1st bar might be close to the desired starting bar. This is completely impossible for the customer to do dynamically during a backtest or optimization...because the number of bars changes dramatically...as will the starting bar.

    NT-Bug16.Jpg:
    There are about 4 problems here. This is a the ES Mini & the price is around 1200.
    On the 2nd bar:
    **The ATR is 36.21...not possible, the ATR should be about 2-4.
    **I was told that you need at least a series of High and Low prices to pass to ATR, or it will fail...There was NO warning, error, etc. An error should have been issued.
    **The TEMA of the LinReg is 527.35...it should be around 1205. The Main Problem here is that EMAs keep adjusting values. It will take tons of bars to work this out of its calculations. In NT-Bug17.Jpg, it shows that the values finally come together and are close around Noon or so The Next Day.
    **The other ATR is 187.38...Again, it should be around 2-4.

    NT-Bug17.Jpg:
    This one shows basically 2 problems:
    ** The Tema is 1768...It should be around 1160. This is only a couple bars from where you start charting & trading.
    **Notice that IT TOOK A FULL DAY to work out the bad EMA calculations. Somewhere around 11:00 to 11:30 On The Next Day, the TEMA and LinReg finally came close to each other. The TEMA and LinReg are still off by about 20-25 points at the end of the 1st day. They start getting closer around Noon-12:30 the next day.

    NT-Bug18.Jpg:
    This screen dump shows the problem very clearly. When you don't have enough bars to do proper calculations, the indicators are way off.
    The Top chart uses the Exact Same Indicators as the bottom, Except, I ran the chart for several months. I displayed the Data Box on both charts as of 6/10. If the indicators have been calculated properly, the indicator values should be the same!

    Notice: The Top Chart: The indicator values look proper.
    The LinReg is 1062.97
    The TEMA is 1063.30

    Notice: The Bottom Chart: The Indicators Are Not Even Close
    The LinReg is 1154.28
    The TEMA is 1768.94
    Attached Files

    Comment


      #17
      ChuckAllen,

      For sure there is no dispute that you will require enough loaded bars for indicator caclulations to be stable. I see your point and I have this on my list as an item to review after we release NT7 into production which is my current priority.

      I did compare TradeStation 200 EMA against our 200 EMA on identical data set (exported from TS and imported in NT) and the output results are identical. Both show the exact same EMA value on the 4th bar (the first bar where their EMA plot was visible). I mention this since you stated that TS does not have this issue. I am not debating that they don't but merely pointing out that at a surface glance, they exhibit the same results.

      I do appreciate the time you have taken to clearly explain the situation to me. For now, you will have to manually ensure that you have enough bars in your backtests to filter out the unstable period.
      RayNinjaTrader Customer Service

      Comment


        #18
        Quick Workaround To The Problem

        I also answered via email...sorry. Here's the post.

        If there is Any way to accomplish something like the following in code while we are waiting for a fix, please let me know.

        A very quick fix would be to allow us to enter 2 dates...

        * Date 1...when to start loading bars
        * Date 2...when to actually start the test/trading/charting, etc.

        Comment


          #19
          Date 1 is already determined by your UI settings.
          Date 2 can be done through a time/date filter like the one shown in this reference sample: http://www.ninjatrader.com/support/f...ead.php?t=3226

          Instead of using a time filter, use a date filter. Please use ToDay() instead of ToTime(). The concept would be the same as the reference sample though.
          Josh P.NinjaTrader Customer Service

          Comment


            #20
            Thanks for the workaround

            I will try this later tonight & let you know.

            Comment


              #21
              kDoren,

              But this should really be determined by the indicator. If all you are doing is plotting an indicator, you could set "BarsRequired" as appropriate in the indicator code (i.e., in Initialize() for SMA you could put "BarsRequired = Period;", for TEMA you could put something like "BarsRequired = 3 * Period;").
              Yummy. So simple, yet I didn't think of it. I was constantly adjusting. It did not dawn on me to use such an eloquent solution. It's much better than getting no object issues.

              Thank you.

              Comment


                #22
                If anyone could post a nice example of some simple error checking for this very issue and as it relates to nested indicators, I would be mighty grateful.

                Comment


                  #23
                  r2kTrader,

                  Unfortunately I am not sure what exactly you are looking for by error checking. All you need to do is ensure you have enough bars through BarsRequired.

                  For example, calling an SMA(10) on SMA(10) requires 20 bars before it will have enough bars. SMA(10) on SMA(10) on SMA(10) would require 30 bars. You would just need to do the math for the parameters you are using to determine how many bars is needed.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #24
                    Partial Agreement

                    I completely agree with the major part of your solution. It is very easy to code this WITH the indicators inside NT. It is also easy to code this with nested indicators. It definitely makes more sense to put this within the indicator in NT instead of each customer having to code their own. It is also easy to Estimate the value of the indicator when enough bars do not exist. It is a little more difficult to load enough data (behind the scenes) to do proper calculations and not let the customer see it...so its there for calculations, but not charting.

                    Another Big Problem...is with the combination of data periods...24/7, 24/5, regular trading hours, required bars, etc. I have attempted to backtest using the various periods...and please try this yourself...I did not keep any screen dumps.

                    For example: If you want to trade from 9:30 to 4:00, and you set the data to Regular Trading Hours, and you use 10 minute bars and you have some type of EMA or nested EMAs in your code, you might not trade until the afternoon! If you request Regular Trading Hours, the data outside those hours seems to be thrown away & the indicators are recalculated based on a possible dramatic gap, instead of smoothed and recalculated during the evening. Look at a chart where the Previous Close & Today's Open are dramatically different...The Indicators Should Also be dramatically different...
                    If the EMA(LinReg) closed at 1200 and the Open is around 1100,..The EMA(LinReg) should have been calculated during the evening & open with a similar gap somewhere around 1100...depending on when the drops happened. On the charts, and trading, it Opens around 1200 and then retreats fairly fast. In reality, the indicator should Close around 1200 and be accurate @ 9:30 somewhere around 1100. Its as if the overnight drop of 100 points happened right at 9:30 instead of through the night hours.

                    What I am trying right now is to request a full month of data before I actually want to start trading. Then in code throw away the leading month, and also restrict the time from 9:30 to 4:00.

                    Comment


                      #25
                      ChuckAllen,

                      If you trade regular hours and that is the session template you use it will definitely ignore all bars outside of that session template. This is expected behavior. If you are trying to just allow for trading during certain hours, but use full extended hours data you will need to use a session template that contains those hours and simply limit the trading via a time filter like the one shown here in this reference sample: http://www.ninjatrader.com/support/f...ead.php?t=3226

                      Just like how you can use ToDay() to limit the dates you actually trade on, you can use ToTime() to limit the times you actually trade on.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #26
                        Chuck:

                        NT currently has a limitation, that you can only have bars for the session you set up the chart for. Any new bar-series you add inside the strategy/indicator will also use the session template for the main chart series.

                        This is the what you see is what you get approach which NT uses. There are no additional layers to help you through. This does take some time getting used to, but is the best in the long run since you have complete control of what you will get.

                        The one big limitation this imposes is that if you have a strategy where you want some indicators running on 24 hours data and some on RTH only, you will have to use a 24 hours chart, filter the incoming bars to create your own RTH only data-series, and then all the calculations natively in the strategy, since the existing indicators require a data-structure which you can not create with your sampled RTH only bar-series.
                        Last edited by aviat72; 06-28-2010, 07:25 PM.

                        Comment


                          #27
                          aviat72,

                          That is not exactly how it behaves. This is how it works for secondary instruments added via Add() in code.

                          - If the primary instrument on the chart (selected via UI) uses "Use instrument settings" as the session template then any secondary instruments you add via Add() will also use "Use instrument settings" for the their instrument as well. This is NOT to say they are using the same session template. They will both use whatever session template is defined as their default respective session templates in the Instrument Manager.

                          - If your primary instrument was set to use a specific session template like "CME US Index Futures RTH" then any secondary instruments you add via Add() will also use "CME US Index Futures RTH".

                          - If you want some as RTH and some as ETH to do so you will need to use the session template of "Use instrument settings" on your primary instrument and then set the RTH or the ETH as the defaults into the Instrument Manager for the particular instruments.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #28
                            I totally agree with the logic you outlined...as far as ignoring the overnight data. That is the problem. I have backtested several systems and wondered why there were so many incorrect trades at the beginning of the day. Then I noticed that there is a Big gap in price, but No gap in the indicators I was using. That means that if you want to trade 9-4, you really have to set the data to 24/7, load at least a month more than where you really want the chart & trading to start, and then use the Day & Time limiting code you mentioned. Then the trades are pretty close.

                            Comment


                              #29
                              Hi Josh:

                              Thanks for the clarification on what is used. I had this discussion some time ago on these threads:

                              IDataSeries - Can we implement and pass to NT methods/functions?
                              Strategy with Bars From Different Sessions?

                              So suppose I want to have two sets of indicators running for an instrument, one based on 24/7 data, and the other based on RTH only.

                              I can then create two instruments, with the same underlying instrument mapping, with different sessions as the default.

                              (a) ES => The regular ES which maps to the RTH as its default
                              (b) ES24 => Another instrument, which maps to the ES symbol but uses a 24/7 (or equivalent for that instrument) as its default session template.

                              I start the chart on the ES24, and then add another set of bars for ES in the strategy. So these are two bars with different sessions.

                              -> I can then have indicators running on both these set of bars. I can then reuse the existing infrastructure for indicators for these bars.
                              -> The callbacks OnBarUpdate() will be called appropriately, i.e. twice during RTH and once during O/N. OnMarketData() will also called twice since we now have two different logical instruments.

                              Please do confirm.
                              Last edited by aviat72; 06-28-2010, 07:23 PM.

                              Comment


                                #30
                                aviat72,

                                No, you will not be able to create two instruments with the same mapping to ES. What you can do is create a duplicate instrument mapped to something else and just import the same data into that instrument.

                                If you want one version to run on 24/7 and one to run on RTH you would want to make two versions of the indicator instead. One version being with a time filter to limit logic to only process on RTH and another version to just be standard and process on every single bar available on the chart.
                                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
                                601 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                347 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                103 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                559 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                558 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X