Last active
September 19, 2021 10:27
-
-
Save marketcalls/0dd94850053f65bcc407 to your computer and use it in GitHub Desktop.
Kaufman Moving Average Adaptive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //////////////////////////////////////////////////////////// | |
| // | |
| // Everyone wants a short-term, fast trading trend that works without large | |
| // losses. That combination does not exist. But it is possible to have fast | |
| // trading trends in which one must get in or out of the market quickly, but | |
| // these have the distinct disadvantage of being whipsawed by market noise | |
| // when the market is volatile in a sideways trending market. During these | |
| // periods, the trader is jumping in and out of positions with no profit-making | |
| // trend in sight. In an attempt to overcome the problem of noise and still be | |
| // able to get closer to the actual change of the trend, Kaufman developed an | |
| // indicator that adapts to market movement. This indicator, an adaptive moving | |
| // average (AMA), moves very slowly when markets are moving sideways but moves | |
| // swiftly when the markets also move swiftly, change directions or break out of | |
| // a trading range. | |
| //////////////////////////////////////////////////////////// | |
| study(title="Kaufman Moving Average Adaptive (KAMA)", shorttitle="Kaufman Moving Average Adaptive (KAMA)", overlay = true) | |
| Length = input(21, minval=1) | |
| xPrice = close | |
| xvnoise = abs(xPrice - xPrice[1]) | |
| nfastend = 0.666 | |
| nslowend = 0.0645 | |
| nsignal = abs(xPrice - xPrice[Length]) | |
| nnoise = sum(xvnoise, Length) | |
| nefratio = iff(nnoise != 0, nsignal / nnoise, 0) | |
| nsmooth = pow(nefratio * (nfastend - nslowend) + nslowend, 2) | |
| nAMA = nz(nAMA[1]) + nsmooth * (xPrice - nz(nAMA[1])) | |
| plot(nAMA, color=blue, title="KAMA") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment