StockFetcher Forums · General Discussion · Kaufman Adaptive Moving Average (KAMA)<< >>Post Follow-up
snappyfrog
661 posts
msg #160564
Ignore snappyfrog
9/20/2023 8:26:06 AM

Would anyone like to try their hand at coding this? This is from stockcharts. I don't see that ToS offers it.

ER = Change/Volatility
Change = ABS(Close - Close (10 periods ago))
Volatility = Sum10(ABS(Close - Prior Close))
Volatility is the sum of the absolute value of the last ten price changes (Close - Prior Close).

SC = Smoothing Constant
SC = [ER x (fastest SC - slowest SC) + slowest SC]2
SC = [ER x (2/(2+1) - 2/(30+1)) + 2/(30+1)]2

Current KAMA = Prior KAMA + SC x (Price - Prior KAMA)

https://school.stockcharts.com/doku.php?id=technical_indicators:kaufman_s_adaptive_moving_average

sr7
107 posts
msg #160569
Ignore sr7
9/21/2023 3:54:03 PM

Actually, I think they tried twice --- 2 attempts at creating a scan here on the forums, way back then.
But it didn't look lik the KAMA on Stockcharts.com, plus you couldn't overlay it on the stock price.

I think the reason was because it's Adaptive, that's why it's called the Kaufman's Adaptive Moving Average (KAMA). I could be wrong about that...

..first attempt in 2006 --- 17 years ago:
A need for "smart" indicators


second attempt in 2007:
Adaptive Moving Average



styliten
280 posts
msg #160571
Ignore styliten
9/21/2023 8:15:32 PM

There are 3 issues with Kaufman:

Kaufman's Adaptive Moving Average (KAMA)

KAMA1


The values in the FAST and SLOW columns were incidentally switched:

FAST = 2 periods, = 2/(2+1) = 0.666667

SLOW = 30 periods, = 2/(30+1) = 0.064516

This is easy fix. The second issue is relatively minor:

"Step 3: KAMA
With the Efficiency Ratio (ER) and Smoothing Constant (SC), we are now ready to calculate Kaufman's Adaptive Moving Average (KAMA). Since we need an initial value to start the calculation, the first KAMA is just a simple moving average . The following calculations are based on the formula below."

The third issue is that SF filter can NOT be recursive, i.e.,

KAMA = KAMA 1 day ago + SC

is not allowed at all.

Hence, the closest thing SF would allow is this:

Fetcher[dow 30

set{Diff1, abs(close - close 1 day ago)}
set{Diff10, ABS(Close - Close 10 days ago)}
set{volat, Sum(Diff1, 10)}
set{ER, Diff10 / volat}

set{fast, 0.66667}
set{slow, 0.06452}
set{sc, fast - slow}

set{smooth1, ER * sc}
set{smooth2, smooth1 + slow}
set{smooth, pow(smooth2, 2)}

set{K0, close 1 day ago minus ema(10) 1 day ago}

set{kauf, smooth * K0}
set{KAMA, ema(10) 1 day ago + kauf}

draw KAMA on plot price
]



Due to limitation #3 above, ema(10) 1 day ago was the closest thing for KAMA 1 day ago .


Mactheriverrat
3,136 posts
msg #160572
Ignore Mactheriverrat
9/21/2023 10:18:29 PM

Thanks styliten!!!!!!

dtatu
143 posts
msg #160579
Ignore dtatu
modified
9/23/2023 4:17:43 PM

Sincerely,I think the KAMA is useless in practice.The entry and exit signal can only be taken once there is a horizontal breakout from a range ( which is reflected in the horizontal KAMA), so then, one should better use a range breakout tool (Donchian ,etc)

snappyfrog
661 posts
msg #160580
Ignore snappyfrog
9/23/2023 8:57:01 PM

Thanks sr7 and styliten.

styliten
280 posts
msg #160581
Ignore styliten
modified
9/23/2023 10:25:03 PM

@ all,

Made a slight modification to mimic the real KAMA more closely:

Fetcher[dow 30

chart-time is 12 months

set{Diff1, abs(close - close 1 day ago)}
set{Diff10, ABS(Close - Close 10 days ago)}
set{volat, Sum(Diff1, 10)}
set{ER, Diff10 / volat}

set{fast, 0.66667}
set{slow, 0.06452}
set{sc, fast - slow}

set{smooth1, ER * sc}
set{smooth2, smooth1 + slow}
set{smooth, pow(smooth2, 2)}

set{K0, close 1 day ago minus ema(10) 1 day ago}

set{kauf, smooth * K0}
set{KAMA, ema(10) 1 day ago + kauf}

draw sum(sum(KAMA, 5), 5) divided by 25 on plot price
]



due to SF limitations, can't declare another variable for the sum(sum(KAMA, 5), 5) divided by 25 part. As a result, no filter can be written on this in SF either.

(Feel free to do your own verification and adjust the parameters in the double SUM accordingly, such as:

sum(sum(KAMA, 6), 6) divided by 36
....

sum(sum(KAMA, 5), 10) divided by 50, etc., etc. )


DOW:

DOW-KAMA-2023-0923

SF KAMA on DOW:

DOW-SF-KAMA-2023-0923


HON:
HON-KAMA-2023-0923


SF KAMA on HON:
HON-SF-KAMA-2023-0923


StockFetcher Forums · General Discussion · Kaufman Adaptive Moving Average (KAMA)<< >>Post Follow-up

*** Disclaimer *** StockFetcher.com does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. StockFetcher.com does not recommend particular securities. StockFetcher.com, Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.


Copyright 2022 - Vestyl Software L.L.C.Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.