Adaptive Moving Average (AMA) Signals For ThinkOrSwim

apdusp

Active member
VIP
The author states:
The Adaptive Moving Average (AMA) Signals indicator, enhances the classic concept of moving averages by making them adaptive to the market's volatility. This adaptability makes the AMA particularly useful in identifying market trends with varying degrees of volatility.

The core of the AMA's adaptability lies in its Efficiency Ratio (ER), which measures the directionality of the market over a given period. The ER is calculated by dividing the absolute change in price over a period by the sum of the absolute differences in daily prices over the same period.

⚪ Why It's Useful
The AMA Signals indicator is particularly useful because of its adaptability to changing market conditions. Unlike static moving averages, it dynamically adjusts, providing more relevant signals that can help traders capture trends earlier or identify reversals with greater accuracy. Its configurability makes it suitable for various trading strategies and timeframes, from day trading to swing trading.

How It Works
The AMA Signals indicator operates on the principle of adapting to market efficiency through the calculation of the Efficiency Ratio (ER), which measures the directionality of the market over a specified period. By comparing the net price change to total price movements, the AMA adjusts its sensitivity, becoming faster during trending markets and slower during sideways markets. This adaptability is enhanced by a gamma parameter that filters signals for either trend continuation or reversal, making it versatile across different market conditions.

change = math.abs(close - close[n])
volatility = math.sum(math.abs(close - close[1]), n)
ER = change / volatility

  • Efficiency Ratio (ER) Calculation: The AMA begins with the computation of the Efficiency Ratio (ER), which measures the market's directionality over a specified period. The ER is a ratio of the net price change to the total price movements, serving as a measure of the efficiency of price movements.
  • Adaptive Smoothing: Based on the ER, the indicator calculates the smoothing constants for the fastest and slowest Exponential Moving Averages (EMAs). These constants are then used to compute a Scaled Smoothing Coefficient (SC) that adapts the moving average to the market's efficiency, making it faster during trending periods and slower in sideways markets.
  • Signal Generation: The AMA applies a filter, adjusted by a "gamma" parameter, to identify trading signals. This gamma influences the sensitivity towards trend or reversal signals, with options to adjust for focusing on either trend-following or counter-trend signals.

How to Use
Trend Identification:
Use the AMA to identify the direction of the trend. An upward moving AMA indicates a bullish trend, while a downward moving AMA suggests a bearish trend.

Reversal Trading: Set the gamma to a positive value to focus on reversal signals, identifying potential market turnarounds.

Settings
  • Period for ER calculation: Defines the lookback period for calculating the Efficiency Ratio, affecting how quickly the AMA responds to changes in market efficiency.
  • Fast EMA Length and Slow EMA Length: Determine the responsiveness of the AMA to recent price changes, allowing traders to fine-tune the indicator to their trading style.
  • Signal Gamma: Adjusts the sensitivity of the filter applied to the AMA, with the ability to focus on trend signals or reversal signals based on its value.
  • AMA Candles: An innovative feature that plots candles based on the AMA calculation, providing visual cues about the market trend and potential reversals.
IJtXaDd.png


https://www.tradingview.com/script/ZSyG0zv6-Adaptive-Moving-Average-AMA-Signals-Zeiierman/

please
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

check the below:

CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0
#// ~~ © Zeiierman {
#indicator("Adaptive Moving Average (AMA) Signals (Zeiierman)", shorttitle="AMA Signals (Zeiierman)", overlay=true)
#// ~~ Tooltips
#Hint effRatioLength: Defines the lookback period for calculating the Efficiency Ratio (ER), which measures the market's efficiency. A higher value smoothens the ER curve but may delay detection of market trends.
#Hint fastLength: Sets the length of the fast Exponential Moving Average (EMA) used in calculating the Adaptive Moving Average (AMA). Decreasing this value makes the AMA more sensitive to recent price changes, potentially increasing trading signals.
#Hint slowLength: Sets the length of the slow EMA used in calculating the AMA. Increasing this length makes the AMA less sensitive to recent price movements, potentially reducing noise but also delaying signal generation."
#Hint SignalGamma: "Signal gamma influences the sensitivity of the filter applied to the AMA, which impacts the generation of signals. \n A negative value targets trend signals (detected only within trends). \n A positive value seeks reversal signals (detected against the trend). \n A lower negative value means signals are less sensitive and filter out more trend signals. \n Conversely, a higher positive value means signals are less sensitive and filter out more reversal signals.
#Hint amaCandleslength: Determines the responsiveness of the structure for AMA candles. A higher value may result in smoother but less responsive candles, potentially leading to delayed recognition of price movements.

# Converted by Sam4Cok@Samer800    - 03/2024

input mode = {default KAMA, AMA};
input price = close;
input effRatioLength = 15; #, title="Period for ER calculation", group="AMA", inline="", tooltip=t1)
input fastLength = 5; #, title="Fast EMA Length", group="AMA", inline="", tooltip=t2)
input slowLength = 50; #, title="Slow EMA Length", group="AMA", inline="", tooltip=t3)
input SignalGamma = 0.15; #, step=0.1, title="Signal Gamma", group="Trend & Reversal Signals", inline="", tooltip=t4)
input colorCandle = no; #, "AMA Candles", inline="Candles", group="AMA Candles", tooltip="")
input amaCandleslength = 50; #, minval=1,title="", inline="Candles", group="AMA Candles", tooltip=t5)

def na = Double.NaN;
def hh = Highest(high, effRatioLength);
def ll = Lowest(low, effRatioLength);
#// ~~  AMA calculation {
#// ~~  Calculate the Efficiency Ratio (ER)

Assert(fastLength > 0, "'fast length' must be positive: " + fastLength);
Assert(slowLength > 0, "'slow length' must be positive: " + slowLength);

def direction;
def volatility;
def ER;

switch (mode) {
case AMA:
    direction = Double.NaN;
    volatility = Double.NaN;
    ER = AbsValue((price - ll) - (hh - price)) / (hh - ll);
Default:
    direction = AbsValue(price - price[effRatioLength]);
    volatility = Sum(AbsValue(price - price[1]), effRatioLength);
    ER = if volatility != 0 then direction / volatility else 0;
}
#// ~~  Calculate the smoothing constants for the fastest and slowest EMA
def fastest = 2 / (fastLength + 1);
def slowest = 2 / (slowLength + 1);
#// ~~  Calculate the Scaled Smoothing Coefficient (SC)
def sc = Sqr(ER * (fastest - slowest) + slowest);
#// ~~ Calculate the AMA
def AMA = CompoundValue(1, AMA[1] + sc * (price - AMA[1]), price);

#// ~~  Apply the filter to the AMA
def sigma  = stdev(ama, effRatioLength);
def filter = SignalGamma * sigma;
#// ~~ Condition Function {
Script conditionloop {
input cond_ = close;
    def conditionMet = fold i = 1 to 20 with p = yes do
        if (cond_[i]) then no else p;
    plot out = conditionMet  ;
}
#// ~~  AMA CandleFunction {
Script AMACandles {
input high_ = high;
input low_ = low;
input src_ = close;
input factor_ = yes;
input length_ = 50;
    def Don_High = highest(high_,length_);
    def Don_Low  = lowest(low_,length_);
    def Norm     = ((close - Don_Low) / (Don_High - Don_Low));
    def initial  = (Norm * close + ((1 - Norm*2)) * if(initial[1]!=0, initial[1], close));
    def Factor   = (if factor_ then  (1 - Norm*2) else (1 - Norm/2)) * if(initial[1]!=0, initial[1], src_);
    def output   = (Norm * src_)  + Factor;
    plot out = output;
}
def Up = highest(high + sigma,5);
def Dn = lowest(low - sigma,5);
#/ ~~ Return Trend Candles
def O = if colorCandle then ExpAverage(AMACandles(Up,Dn,open ,yes,amaCandleslength),2) else na;
def H = if colorCandle then ExpAverage(AMACandles(Up,Dn,high ,no ,amaCandleslength),2) else na;
def L = if colorCandle then ExpAverage(AMACandles(Up,Dn,low  ,no ,amaCandleslength),2) else na;
def C = if colorCandle then ExpAverage(AMACandles(Up,Dn,close,yes,amaCandleslength),2) else na;

def cond_open  = (H > open);
def cond_high  = (H > high);
def cond_low   = (H > low);
def cond_close = (H > close);
def sign       = (cond_open or cond_high or cond_low or cond_close); #?color.lime:color.red
#// ~~  Trading rules {
def longCondition  = Crosses(ama,ama[1] - filter, CrossingDirection.ABOVE);
def shortCondition = Crosses(ama,ama[1] + filter, CrossingDirection.BELOW);
def SignalUp       = longCondition and conditionloop(longCondition);
def SignalDn       = shortCondition and conditionloop(shortCondition);

#// ~~  Plot AMA Average & Signals {
def pos    = ama>ama[1] and close>ama;
def neg    = ama<ama[1] and close<ama;
def col = if pos then 1 else if neg then -1 else 0;

plot amaLine = if ama then ama else na; # "AMA"
amaLine.SetLineWeight(2);
amaLine.AssignValueColor(if col > 0 then Color.VIOLET else
                         if col < 0 then Color.PLUM else Color.GRAY);
AddChartBubble(SignalUp, low,  "Buy", Color.CYAN, no);
AddChartBubble(SignalDn, high, "Sell", Color.MAGENTA);

AssignPriceColor(if !colorCandle then Color.CURRENT else
                 if sign then Color.GREEN else Color.RED);

#-- END of CODE
 

If you use it, I would be interested in your feedback. AMA is standard on my trading platform, so I use it occasionally. For me, it's most useful as a chop indicator when it flatlines. It seems more useful when paired with an EMA. I look for price to be above/below both EMA and AMA rather than an EMA-AMA crossover.

But maybe I'm missing something, therefore I welcome your perceptions ... thanks in advance :)
 
Last edited by a moderator:
check the below:

CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0
#// ~~ © Zeiierman {
#indicator("Adaptive Moving Average (AMA) Signals (Zeiierman)", shorttitle="AMA Signals (Zeiierman)", overlay=true)
#// ~~ Tooltips
#Hint effRatioLength: Defines the lookback period for calculating the Efficiency Ratio (ER), which measures the market's efficiency. A higher value smoothens the ER curve but may delay detection of market trends.
#Hint fastLength: Sets the length of the fast Exponential Moving Average (EMA) used in calculating the Adaptive Moving Average (AMA). Decreasing this value makes the AMA more sensitive to recent price changes, potentially increasing trading signals.
#Hint slowLength: Sets the length of the slow EMA used in calculating the AMA. Increasing this length makes the AMA less sensitive to recent price movements, potentially reducing noise but also delaying signal generation."
#Hint SignalGamma: "Signal gamma influences the sensitivity of the filter applied to the AMA, which impacts the generation of signals. \n A negative value targets trend signals (detected only within trends). \n A positive value seeks reversal signals (detected against the trend). \n A lower negative value means signals are less sensitive and filter out more trend signals. \n Conversely, a higher positive value means signals are less sensitive and filter out more reversal signals.
#Hint amaCandleslength: Determines the responsiveness of the structure for AMA candles. A higher value may result in smoother but less responsive candles, potentially leading to delayed recognition of price movements.

# Converted by Sam4Cok@Samer800    - 03/2024

input mode = {default KAMA, AMA};
input price = close;
input effRatioLength = 15; #, title="Period for ER calculation", group="AMA", inline="", tooltip=t1)
input fastLength = 5; #, title="Fast EMA Length", group="AMA", inline="", tooltip=t2)
input slowLength = 50; #, title="Slow EMA Length", group="AMA", inline="", tooltip=t3)
input SignalGamma = 0.15; #, step=0.1, title="Signal Gamma", group="Trend & Reversal Signals", inline="", tooltip=t4)
input colorCandle = no; #, "AMA Candles", inline="Candles", group="AMA Candles", tooltip="")
input amaCandleslength = 50; #, minval=1,title="", inline="Candles", group="AMA Candles", tooltip=t5)

def na = Double.NaN;
def hh = Highest(high, effRatioLength);
def ll = Lowest(low, effRatioLength);
#// ~~  AMA calculation {
#// ~~  Calculate the Efficiency Ratio (ER)

Assert(fastLength > 0, "'fast length' must be positive: " + fastLength);
Assert(slowLength > 0, "'slow length' must be positive: " + slowLength);

def direction;
def volatility;
def ER;

switch (mode) {
case AMA:
    direction = Double.NaN;
    volatility = Double.NaN;
    ER = AbsValue((price - ll) - (hh - price)) / (hh - ll);
Default:
    direction = AbsValue(price - price[effRatioLength]);
    volatility = Sum(AbsValue(price - price[1]), effRatioLength);
    ER = if volatility != 0 then direction / volatility else 0;
}
#// ~~  Calculate the smoothing constants for the fastest and slowest EMA
def fastest = 2 / (fastLength + 1);
def slowest = 2 / (slowLength + 1);
#// ~~  Calculate the Scaled Smoothing Coefficient (SC)
def sc = Sqr(ER * (fastest - slowest) + slowest);
#// ~~ Calculate the AMA
def AMA = CompoundValue(1, AMA[1] + sc * (price - AMA[1]), price);

#// ~~  Apply the filter to the AMA
def sigma  = stdev(ama, effRatioLength);
def filter = SignalGamma * sigma;
#// ~~ Condition Function {
Script conditionloop {
input cond_ = close;
    def conditionMet = fold i = 1 to 20 with p = yes do
        if (cond_[i]) then no else p;
    plot out = conditionMet  ;
}
#// ~~  AMA CandleFunction {
Script AMACandles {
input high_ = high;
input low_ = low;
input src_ = close;
input factor_ = yes;
input length_ = 50;
    def Don_High = highest(high_,length_);
    def Don_Low  = lowest(low_,length_);
    def Norm     = ((close - Don_Low) / (Don_High - Don_Low));
    def initial  = (Norm * close + ((1 - Norm*2)) * if(initial[1]!=0, initial[1], close));
    def Factor   = (if factor_ then  (1 - Norm*2) else (1 - Norm/2)) * if(initial[1]!=0, initial[1], src_);
    def output   = (Norm * src_)  + Factor;
    plot out = output;
}
def Up = highest(high + sigma,5);
def Dn = lowest(low - sigma,5);
#/ ~~ Return Trend Candles
def O = if colorCandle then ExpAverage(AMACandles(Up,Dn,open ,yes,amaCandleslength),2) else na;
def H = if colorCandle then ExpAverage(AMACandles(Up,Dn,high ,no ,amaCandleslength),2) else na;
def L = if colorCandle then ExpAverage(AMACandles(Up,Dn,low  ,no ,amaCandleslength),2) else na;
def C = if colorCandle then ExpAverage(AMACandles(Up,Dn,close,yes,amaCandleslength),2) else na;

def cond_open  = (H > open);
def cond_high  = (H > high);
def cond_low   = (H > low);
def cond_close = (H > close);
def sign       = (cond_open or cond_high or cond_low or cond_close); #?color.lime:color.red
#// ~~  Trading rules {
def longCondition  = Crosses(ama,ama[1] - filter, CrossingDirection.ABOVE);
def shortCondition = Crosses(ama,ama[1] + filter, CrossingDirection.BELOW);
def SignalUp       = longCondition and conditionloop(longCondition);
def SignalDn       = shortCondition and conditionloop(shortCondition);

#// ~~  Plot AMA Average & Signals {
def pos    = ama>ama[1] and close>ama;
def neg    = ama<ama[1] and close<ama;
def col = if pos then 1 else if neg then -1 else 0;

plot amaLine = if ama then ama else na; # "AMA"
amaLine.SetLineWeight(2);
amaLine.AssignValueColor(if col > 0 then Color.VIOLET else
                         if col < 0 then Color.PLUM else Color.GRAY);
AddChartBubble(SignalUp, low,  "Buy", Color.CYAN, no);
AddChartBubble(SignalDn, high, "Sell", Color.MAGENTA);

AssignPriceColor(if !colorCandle then Color.CURRENT else
                 if sign then Color.GREEN else Color.RED);

#-- END of CODE
Thanks a lot @samer800 , as always 👋 👋 👋
 
The author states:
The Adaptive Moving Average (AMA) Signals indicator, enhances the classic concept of moving averages by making them adaptive to the market's volatility. This adaptability makes the AMA particularly useful in identifying market trends with varying degrees of volatility.

The core of the AMA's adaptability lies in its Efficiency Ratio (ER), which measures the directionality of the market over a given period. The ER is calculated by dividing the absolute change in price over a period by the sum of the absolute differences in daily prices over the same period.

⚪ Why It's Useful
The AMA Signals indicator is particularly useful because of its adaptability to changing market conditions. Unlike static moving averages, it dynamically adjusts, providing more relevant signals that can help traders capture trends earlier or identify reversals with greater accuracy. Its configurability makes it suitable for various trading strategies and timeframes, from day trading to swing trading.

How It Works
The AMA Signals indicator operates on the principle of adapting to market efficiency through the calculation of the Efficiency Ratio (ER), which measures the directionality of the market over a specified period. By comparing the net price change to total price movements, the AMA adjusts its sensitivity, becoming faster during trending markets and slower during sideways markets. This adaptability is enhanced by a gamma parameter that filters signals for either trend continuation or reversal, making it versatile across different market conditions.

change = math.abs(close - close[n])
volatility = math.sum(math.abs(close - close[1]), n)
ER = change / volatility

  • Efficiency Ratio (ER) Calculation: The AMA begins with the computation of the Efficiency Ratio (ER), which measures the market's directionality over a specified period. The ER is a ratio of the net price change to the total price movements, serving as a measure of the efficiency of price movements.
  • Adaptive Smoothing: Based on the ER, the indicator calculates the smoothing constants for the fastest and slowest Exponential Moving Averages (EMAs). These constants are then used to compute a Scaled Smoothing Coefficient (SC) that adapts the moving average to the market's efficiency, making it faster during trending periods and slower in sideways markets.
  • Signal Generation: The AMA applies a filter, adjusted by a "gamma" parameter, to identify trading signals. This gamma influences the sensitivity towards trend or reversal signals, with options to adjust for focusing on either trend-following or counter-trend signals.

How to Use
Trend Identification:
Use the AMA to identify the direction of the trend. An upward moving AMA indicates a bullish trend, while a downward moving AMA suggests a bearish trend.

Reversal Trading: Set the gamma to a positive value to focus on reversal signals, identifying potential market turnarounds.

Settings
  • Period for ER calculation: Defines the lookback period for calculating the Efficiency Ratio, affecting how quickly the AMA responds to changes in market efficiency.
  • Fast EMA Length and Slow EMA Length: Determine the responsiveness of the AMA to recent price changes, allowing traders to fine-tune the indicator to their trading style.
  • Signal Gamma: Adjusts the sensitivity of the filter applied to the AMA, with the ability to focus on trend signals or reversal signals based on its value.
  • AMA Candles: An innovative feature that plots candles based on the AMA calculation, providing visual cues about the market trend and potential reversals.
IJtXaDd.png


https://www.tradingview.com/script/ZSyG0zv6-Adaptive-Moving-Average-AMA-Signals-Zeiierman/

please
apdusp Where can I find the tos script?
 
What time frame do you use this on?

Moving averages are used on all aggregations.
You can fine-tune the settings, if needed, to better fit your timeframe and strategy.

The OP states:
#Hint effRatioLength: Defines the lookback period for calculating the Efficiency Ratio (ER), which measures the market's efficiency. A higher value smoothens the ER curve but may delay detection of market trends.

#Hint fastLength: Sets the length of the fast Exponential Moving Average (EMA) used in calculating the Adaptive Moving Average (AMA). Decreasing this value makes the AMA more sensitive to recent price changes, potentially increasing trading signals.

#Hint slowLength: Sets the length of the slow EMA used in calculating the AMA. Increasing this length makes the AMA less sensitive to recent price movements, potentially reducing noise but also delaying signal generation."

#Hint SignalGamma: "Signal gamma influences the sensitivity of the filter applied to the AMA, which impacts the generation of signals. \n A negative value targets trend signals (detected only within trends). \n A positive value seeks reversal signals (detected against the trend). \n A lower negative value means signals are less sensitive and filter out more trend signals. \n Conversely, a higher positive value means signals are less sensitive and filter out more reversal signals.

#Hint amaCandleslength: Determines the responsiveness of the structure for AMA candles. A higher value may result in smoother but less responsive candles, potentially leading to delayed recognition of price movements.
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
401 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top