Aroon Trend Trail [BackQuant] For ThinkOrSwim

Typegod

New member
aFDGJpr.png


Author states:
Aroon Trend Trail is a trend overlay that uses the relative recency of recent highs and lows to determine direction, then plots an ATR-based trailing rail whose width changes with the strength of the Aroon bias.

The indicator has two separate parts:
  • Aroon state: determines whether the trend is bullish or bearish.
  • Trend rail: provides a ratcheting lower or upper boundary based on ATR.
The rail itself does not determine trend changes. Bullish and bearish flips come from the Aroon bias crossing the selected Bias Threshold.

original Tradingview script: https://www.tradingview.com/script/30BBpKLx-Aroon-Trend-Trail-BackQuant/
Code:
# Aroon Trend Trail [BackQuant]
# Converted to ThinkScript = W. Kalvin

# Aroon Trend Trail is a trend overlay that uses the relative recency of recent highs and lows to determine direction, then plots an ATR-based trailing rail whose width changes with the strength of the Aroon bias.

# The indicator has two separate parts:

# • Aroon state: determines whether the trend is bullish or bearish.
# • Trend rail: provides a ratcheting lower or upper boundary based on ATR.

# The rail itself does not determine trend changes. Bullish and bearish flips come from the Aroon bias crossing the selected Bias Threshold.


# Inputs
input aroonLen = 25;
input flipThreshold = 0.15;
input atrLen = 14;
input atrFactor = 1.8;
input strongWidth = 0.65;
input weakWidth = 1.25;
input breakOnFlip = yes;

input lineW = 3;
input showFill = yes;
input showGlow = yes;
input showAroon = no;
input paintCandles = yes;

# Aroon Calculations using explicit type casting
def sinceHigh = (GetMaxValueOffset(high, aroonLen));
def sinceLow = (GetMinValueOffset(low, aroonLen));

def aroonUp = 100.0 * (aroonLen - AbsValue(sinceHigh)) / aroonLen;
def aroonDown = 100.0 * (aroonLen - AbsValue(sinceLow)) / aroonLen;

def aroonBias = (aroonUp - aroonDown) / 100.0;
def aroonStrength = Min(AbsValue(aroonBias), 1.0);

# Trend State Logic
rec trend = if IsNaN(trend[1]) then (if aroonBias >= 0.0 then 1 else -1)
else if trend[1] == 0 then (if aroonBias >= 0.0 then 1 else -1)
else if trend[1] != 1 and aroonBias > flipThreshold then 1
else if trend[1] != -1 and aroonBias < -flipThreshold then -1
else trend[1];

def bullFlip = (trend == 1) and (trend[1] == -1);
def bearFlip = (trend == -1) and (trend[1] == 1);
def trendFlip = bullFlip or bearFlip;
def isBull = trend == 1;

# Adaptive Rail Width
def atr = WildersAverage(TrueRange(high, close, low), atrLen);
def widthScale = weakWidth + (strongWidth - weakWidth) * aroonStrength;
def railWidth = atr * atrFactor * widthScale;

def rawLower = hl2 - railWidth;
def rawUpper = hl2 + railWidth;

# Ratcheting Rail
rec lowerRail = if IsNaN(lowerRail[1]) then rawLower
else if trend == 1 then (if bullFlip then rawLower else Max(lowerRail[1], rawLower))
else rawLower;

rec upperRail = if IsNaN(upperRail[1]) then rawUpper
else if trend == -1 then (if bearFlip then rawUpper else Min(upperRail[1], rawUpper))
else rawUpper;

def activeRail = if isBull then lowerRail else upperRail;
def plottedRail = if breakOnFlip and trendFlip then Double.NaN else activeRail;

# Plots
plot TrendRail = plottedRail;
TrendRail.SetLineWeight(lineW);
TrendRail.AssignValueColor(if isBull then Color.GREEN else Color.RED);

# Optional Fill Clouds
plot UpperRef = if showFill then activeRail + (railWidth * 0.5) else Double.NaN;
plot LowerRef = if showFill then activeRail - (railWidth * 0.5) else Double.NaN;

plot BullUpper = if showFill and isBull then UpperRef else Double.NaN;
plot BullLower = if showFill and isBull then LowerRef else Double.NaN;
AddCloud(BullUpper, BullLower, Color.DARK_GREEN, Color.DARK_GREEN);

plot BearUpper = if showFill and !isBull then UpperRef else Double.NaN;
plot BearLower = if showFill and !isBull then LowerRef else Double.NaN;
AddCloud(BearUpper, BearLower, Color.DARK_RED, Color.DARK_RED);

# Candle Coloring
AssignPriceColor(if paintCandles then (if isBull then Color.GREEN else Color.RED) else Color.CURRENT);

# Alerts
Alert(bullFlip, "Aroon Trend Rail turned bullish", Alert.BAR, Sound.Chimes);
Alert(bearFlip, "Aroon Trend Rail turned bearish", Alert.BAR, Sound.Bell);
 
Last edited by a moderator:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
1619 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