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

KAMA coding error?

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

    KAMA coding error?

    My KAMA plots look a little unusual compared to a friend who is using TradeStation. I've done some research on the calculation and most people seem to calculate it differently than the NT 6.5 version.

    Current NT 6.5 version:
    Value.Set(Value[1] + smooth * (Close[1] - Value[1]));

    Other references that I have looked at would be:
    Value.Set(Value[1] + smooth * (Close[0] - Value[1]));

    I would appreciate some opinions on this before I modify it. If I am correct then are there any other changes that I should make for this indicator. I want to make sure that I have a correct version of this indicator.
    Thanks.
    Last edited by higler; 11-02-2009, 11:31 AM.

    #2
    We'll look into.

    Comment


      #3
      Hi higler !

      You are right ! Using Close[0] value as you suggested it is correct.

      This is fixed in our KAMA indicator, and the fix will be available with the next update of NinjaTrader.

      Thanks for lettings us know,
      Christian
      ChristianSenior Software Developer

      Comment


        #4
        KAMA coding error

        Higler,

        I noticed with interest your suggestion about the KAMA code in NT 6.5. I too had noticed it as different from my use of it in TS 8.3.

        However, after changing the code as you suggested, I was disappointed to find it is still different for me in the @YM anyway. Of course, TS data for the YM at least is known to be suspect, so I'm not ruling that out.

        Any thoughts? I only made the change in one spot in the code where I could find your exact line. Did I miss anything? I'm not a programmer at all, so I'm somewhat out of my depth messing with code. - )

        Eliot

        Comment


          #5
          Originally posted by romulus View Post
          However, after changing the code as you suggested, I was disappointed to find it is still different for me in the @YM anyway. Of course, TS data for the YM at least is known to be suspect, so I'm not ruling that out.Eliot
          If you use the TS KAMA code from John Ehlers' TradeStationWorld 2005 presentation, the calculation use (H+L)/2 as price. The present KAMA implementation even with the correction, uses Close, that is the main source of discrepancy.





          There is also a minor error in the original TS code which did not altered the plot very much :
          FYI the code for !TSWrld05_KAMA has an error. The line...
          For count = 0 to Len begin
          ...should be...
          For count = 0 to Len-1 begin
          Last edited by thrunner; 05-22-2008, 11:19 PM.

          Comment


            #6
            Do you have a link to the "official" definition of the KAMA so we could check out? Thanks

            Comment


              #7
              Kama Coding Error etc.

              thrunner,

              Thanks for your input!

              Not sure the source of my TS 8.3 indicator, the EL has the usual Tradestation default indicator "signature".

              Unfortunately, I've been using the AMA in TS using "close". And the identical inputs in NT 6.5 gives different plots at times. Not always, but with some frequency. I agree that it appears the NT KAMA also appears to be using close.

              Oddly, this morning, when I plotted the AMA in TS using (high+low)/2, it more closely matches my NT 6.5 corrected code. And here too, it's not an exact match, but closer than using the close. Very odd indeed.

              Not sure what else to make of this aside from data or data handling discrepencies between Ninja and TS, unless there's other differences in the two codes. Not being a coder, I won't attempt a conjecture here.

              I will note that I've already done all I can think of in both apps to make my YM sessions identical (start and end times).

              Any other ideas would certainly be welcome!

              Eliot

              Comment


                #8
                I've been trying to compare my YM bars and KAMA plots to a friend who is running TS. My data bars do not match his exactly and I don't know how much that will account for remaining differences. I've looked around online and it is not unusual for KAMA to be calculated based on the close although I don't know which is "correct" since you can find so much conflicting stuff on the internet. My friend is emailing me the EasyLanguage code for KAMA. It has been a while since I have programmed in EL but I am going to try and decipher it and do a comparison of the calculation logic. This certainly doesn't imply that I think that TS is more correct than NT. I would just like to understand why there might be a discrepancy. Just looking at my friend's plots looks like his are "smoothed" more than my NT plots.

                Comment


                  #9
                  higler, et al

                  At the bottom of this well, there lies a reality of trading which is that no matter how precisely we match up these two indicators (and I do want this to occur as much as reasonably possible), there will likely always be a divergence between their plots due to the data each package receives, and/or the handling it goes through with each supplier.

                  Having said this, hopefully we can come to grips with any number of differences within the two codes. As to close vs H+L/2, I think it's user preference. I use the close, but, in the past, I've used the less "biased" H+L/2. At the moment, I see some purpose in having the AMA "cheat" in the direction the trend.

                  Additionally your astute observation and correction to the code is obviously a considerable alignment.

                  But, as we narrow the variables, it MAY come down to the data. The two are somewhat close now, but do still diverge in some instances, and enough to keep me wondering if one of the codes is still harboring a difference I'm not skilled enough to see.

                  If anyone doubts the veracity of data/data supplier variability, and wants to see some evidence of this, I'll be happy to supply it in a few snaps. My own NT data comes from Mirus, my broker, and my TS data is TS's own of course. I have wondered if perhaps a DTN, or eSignal might provide more reliable NT data. And as I've stated already earlier, TS has several issues with their data plant at least in terms of the YM, unfortunately.

                  Eliot

                  Comment


                    #10
                    I'm beginning to think that there might be some differences in the underlying data between TS and my Zen-Fire data feed causing the occaisional divergences. I tried "unwinding" the NT and and TS algorithms and they looked essentially the same execept for a possible minor variation when the "noise" equals zero which I think would be very rare and even then I think the value difference would be very small. I tried rewriting the TS algorithm into NinjaScipt and the charts overlayed exactly. I don't care for EasyLanguage and I have concerns about TS data under high volume. Sometimes some TS plots look overly smoothed even when no smoothing is selected. Anyway, I much prefer NinjaScript(C#) because I think that it is more explicit. Based upon my latest comparisons I think that that the "fixed" KAMA with the Zen-Fire data feed is more accurate than TS unless there is a hidden bug in one of the methods, which I don't think is the case. The only other possible change that I could see doing is rewriting it to make it PriceTypeSelectable, but that doesn't affect me since I am using it with Close anyway. I was a previous TS customer and I feel more confident with NT.

                    Comment


                      #11
                      I am certainly not an authority on KAMA at all, but it appeared that Kaufman's used Close as price in his book, however, Ehler used (H+L)/2 in a few of his indicators.

                      Kaufman's Adaptive Moving Average (KAMA)

                      Description
                      The "Adaptive Moving Average" was presented in 1998 by Perry J. Kaufman in his book "Trading Systems and Methods, 3rd Edition". Kaufman modified the conventional Moving Average with the aid of an "adaptive" approach. The intention here is to make the Moving Average more trend-efficient.
                      Calculation
                      The current value of the KAMA is calculated by first forming "sc". Then "sc" is multiplied with the expression [Price - KAMA (of the previous day)]. Finally, the KAMA (of the previous day) is added to this value.

                      Formula
                      Parameters
                      The adjustable period length can be chosen from 1 to 500. The most common settings will have a period length ranging from 8 to 100.

                      Interpretation
                      The KAMA shows an upwards or downwards trend by rising or falling, whilst a sideways trend is exhibited through a KAMA running almost horizontally. If the KAMA runs sideways, it may be worthwhile applying proven oscillators.
                      Ehler's Tradestation code for KAMA : !TSWrld05_KAMAc (using (H+L)/2 as price and corrected for Len-1):
                      Code:
                      Inputs: Price((H+L)/2), Len(10),FastLen(2), SlowLen(30);
                      Vars: count(0), Num(0), Denom(0),ER(0), Fastest(0), Slowest(0), alpha(0), Filt(0);
                      Num = AbsValue(Price - Price[Len]);
                      Denom = 0;
                      For count = 0 to Len -1 begin
                       Denom = Denom + AbsValue(Price[count] - Price[count + 1]);
                      End;
                      If Denom <> 0 then ER = Num / Denom;
                      Fastest = 2 / (FastLen + 1);
                      Slowest = 2 / (SlowLen + 1);
                      alpha = Square(ER*(Fastest - Slowest) + Slowest);
                      Filt = alpha*Price + (1 - alpha)*Filt[1];
                      If CurrentBar = 1 then Filt = Price;
                      Plot1(Filt, "KAMA");
                      {FYI the code for !TSWrld05_KAMA has an error. The line... 
                      For count = 0 to Len begin 
                      ...should be... 
                      For count = 0 to Len-1 begin 
                      }

                      Comment


                        #12
                        Thanks for feedback. So we could savely assume that NTs interpretation if matching Kaufmanns definition but not Ehlers...

                        Comment


                          #13
                          TS vs. Ninja for KAMA

                          I was also interested to get the AMA from TS working in Ninja, and I also noticed a fairly substantial difference in the response of the TS AMA compared to Ninja's KAMA even though they are both supposed to be implementations of the Kaufman Adaptive Moving Average. As a result I opened excel and ported the code from each indicator into a spreadsheet. I used Close for price. A separate column in the spreadsheet was used for each variable in the code with a final column used to calculate the AMA from the data in the other columns. I then copied the closing price from a section of a ninja chart (using print command in a strategy and copied from output window) and added it to the spreadsheet to see if my spreadsheet calculated the same KAMA as the chart--it did. Likewise the TradeStation AMA checked out good.
                          I replaced the column of the TS closing prices with Ninja closing prices and compared the results calculated using the TS code with the results from the Ninja chart. The were very close always falling within a tick of one another (typically not differing more than .1 point)

                          So the point is that the difference in the data accounts for the different behavior of the KAMA vs. TradeStation AMA. I think some people already came to this conclusion, but I wasn't convinced--until now.

                          rsi77

                          Comment


                            #14
                            Thanks for posted your detailed report here rsi77!
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              Kama Coder

                              The website at kama coder has no link to access their contact section or anything else. Do you have any sggestions?
                              Thanks
                              Jerry

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by TraderBCL, Today, 04:38 AM
                              2 responses
                              8 views
                              0 likes
                              Last Post TraderBCL  
                              Started by martin70, 03-24-2023, 04:58 AM
                              14 responses
                              105 views
                              0 likes
                              Last Post martin70  
                              Started by Radano, 06-10-2021, 01:40 AM
                              19 responses
                              606 views
                              0 likes
                              Last Post Radano
                              by Radano
                               
                              Started by KenneGaray, Today, 03:48 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post KenneGaray  
                              Started by thanajo, 05-04-2021, 02:11 AM
                              4 responses
                              471 views
                              0 likes
                              Last Post tradingnasdaqprueba  
                              Working...
                              X