OPEN-SOURCE SCRIPT
업데이트됨 Slope Adaptive Moving Average (MZ SAMA)

INTRODUCTION
This script is inspired from "Vitali Apirine (Stocks & Commodities V.36:5: Adaptive Moving Averages)" and a correction to Dynamic Volume Adaptive Moving Average (MZ DVAMA). I have used slope filtering in order to adapt trends more precisely for better trades.
Slope adaption makes it better for adaptive moving average to detect trend health; making it easier to make decisions based on market strong price momentums, consolidations or breakouts. This isn’t possible with only using simply Adaptive Moving Averages.
Adaptive Moving Averages curve doesn’t change its length based on Slope but it uses slope adaptive color for trend strength detection.
TREND DETECTION
DEFAULTS SETTINGS
ALERTS
Buy/Sell Alerts will follow on when slope is out of consolidation/choppiness area. Best entry is at absolute alerts timing but other trades can be started midway based on trend condition.
This script is inspired from "Vitali Apirine (Stocks & Commodities V.36:5: Adaptive Moving Averages)" and a correction to Dynamic Volume Adaptive Moving Average (MZ DVAMA). I have used slope filtering in order to adapt trends more precisely for better trades.
Slope adaption makes it better for adaptive moving average to detect trend health; making it easier to make decisions based on market strong price momentums, consolidations or breakouts. This isn’t possible with only using simply Adaptive Moving Averages.
Adaptive Moving Averages curve doesn’t change its length based on Slope but it uses slope adaptive color for trend strength detection.
TREND DETECTION
- Green Color:
Strong Uptrend with good price momentum. - Red Color:
Strong Downtrend. - Yellow Color:
Market is either choppy, sideways or consolidating. Better to avoid taking new positions and if trade is running then its good to carry it on.
DEFAULTS SETTINGS
- AMA length is 200 (Better for timeframes higher than 1H)
- Minor length is 6
- Major length is 14
- Slope period is set to 34 with 25 of initial range. Consolidation is always below 17.
ALERTS
Buy/Sell Alerts will follow on when slope is out of consolidation/choppiness area. Best entry is at absolute alerts timing but other trades can be started midway based on trend condition.
릴리즈 노트
- Converted the script to Pine Version 5
- Changed AMA and signal generation code into a function call for the script to work on Multi Timeframe (MTF)
릴리즈 노트
Buy / Sell signals are derived from dynamic coloring directly now.릴리즈 노트
AMA PHILOSOPHY [B]Hope everyone is getting benefits from 'SAMA'. Lately, I observed that many people were having difficulties understanding some basics of AMA so I decided to explain as much as I can.
MINOR AND MAJOR LENGTH
AMA adapts its length based on smoothing alpha calculations same as used in Exponential Moving Average. Here is the original Tradingview code for EMA calculations:
var result = float(na)
smoothing = 2.0
alpha = smoothing / (length + 1)
result := (src - nz(result[1])) * alpha + nz(result[1])
In case of AMA, Minor Length and Major Length would be used to calculate same type of alpha as used in EMA code above.
minAlpha = 2 / (minLength + 1)
majAlpha = 2 / (majLength + 1)
AMA uses the above alpha values in a certain way to place greater weight on price making the resulted MA more reactive to recent price changes. Method of placing weight on price is same as of EMA as decribed above only Alpha calculations with respect to smoothing vary in AMA code as described below.
final = mult * (minAlpha - majAlpha) + majAlpha
final_alpha = math.pow(final, 2) // Final Alpha calculated from Minor and Major length along with considering Multiplication factor calculated using Highest / Lowest value within provided AMA overall length
ama := (src - nz(ama[1])) * final_alpha + nz(ama[1]) //Same as EMA
More simply, AMA places weight of Highest and Lowest values on recent price changes and to detect these price changes AMA uses two Alphas or EMA with faster length resulting ultimately smoothing effect.
hh = ta.highest(length + 1)
ll = ta.lowest(length + 1)
mult = hh - ll != 0 ? math.abs(2 * src - ll - hh) / (hh - ll) : 0
USAGE
To my experience, best way to use AMA is to consider using higher AMA lengths such as 365, 200, 100 or more than 50 for keeping smoothness intact and for Minor and Major lengths within lower range. For example, EMA 6 to 14 are better and faster options to detect recent price changes so I used these two. Similarly, these two lengths can be changed if market is more volatile and you need AMA to react slowly with price volatility.
For same reason, I used Volume Adaptive Dynamic Major Length in DVAMA. Dynamic Volume Adaptive Moving Average (MZ DVAMA) uses adaptive major length within AMA code to make AMA more reliable with price volatility.
Following are some good combinations of AMA lengths for different timeframes that I found usefull:
Ticker : INDEX : BTCUSD , Timeframe : 4H , AMA Length : 200 , Minor Length : 14 , Major Length : 50
Ticker : INDEX : BTCUSD , Timeframe : 1H , AMA Length : 200 , Minor Length : 14 , Major Length : 50
Ticker : INDEX : BTCUSD , Timeframe : 15m , AMA Length : 200 , Minor Length : 14 , Major Length : 50
Although I wouldn't suggest using SAMA on lower timeframes without any prior backtesting and modifying Major / Minor Lengths with price volatility accordingly buy SAMA can be used along with other indicators such as RSI and another EMA.
릴리즈 노트
Added alert for "Reversal/Consolidation/Choppiness" yellow color as "Chop Zone"릴리즈 노트
Corrected Dynamic Coloring function and placement of signals on chart. Also updated the chart to latest오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.