Trend Trader Strategy For ThinkOrSwim

bvaikunth

New member
This is the TradingView Trend Trader Strategy
https://usethinkscript.com/threads/convert-tradingview-trend-trader-strategy.10941/
Ruby:
#////////////////////////////////////////////////////////////
#//  Copyright by HPotter v1.0 21/01/2021
#// This is plots the indicator developed by Andrew Abraham
#// in the Trading the Trend article of TASC September 1998
#////////////////////////////////////////////////////////////
#study(title="Trend Trader Strategy", overlay = true)
#ported by @bvaikunth 6/2022
#requested by @kls06541
input Length = 21;
input AtrMult = 3.0;
input AvgType = AverageType.simple;
def atr = MovingAverage(avgtype, TrueRange(high, close, low), 1);
def avgTR = WMA(atr, Length);
def highestC = Highest(high,Length);
def lowestC = Lowest(low, Length);
def UP = highestC[1] - (avgTR[1] * AtrMult);
def DN = lowestC[1] + (avgTR[1] * AtrMult);

script nz {
input data = 0;
input data2 = close;
def ret_val = if IsNaN(data) then data else data2;
plot return = ret_val;
}
def ret = if close > UP and close > DN then UP else if close < DN and close < UP then DN else nz(ret[1], close);
def pos = if close > ret then 1 else if close < ret then -1 else nz(pos[1], 0);

plot trend = ret;

trend.assignvaluecolor ( if pos ==-1 then color.red else if pos ==1 then color.green else color.blue);
 
Last edited by a moderator:

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

Note: I learned that this version repaints on TV. not sure about TOS but good to keep in mind.

I believe to fix this, this line needs to be updated to below: hPotter has it in other scripts.
avgTR = WMA(atr[1], Length);
 
Last edited:
just modified it to visualize it better.

#////////////////////////////////////////////////////////////
#// Copyright by HPotter v1.0 21/01/2021
#// This is plots the indicator developed by Andrew Abraham
#// in the Trading the Trend article of TASC September 1998
#////////////////////////////////////////////////////////////
#study(title="Trend Trader Strategy", overlay = true)
#ported by @bvaikunth 6/2022
#requested by @kls06541
# Mod by SAM4COK 6/2022

input Length = 20;
input AtrMult = 3.0;
input PriceColor = yes;

def avgTR = WMA(ATR(1), Length);
def highestC = Highest(high);
def lowestC = Lowest(low);
def UP = highestC[1] - (avgTR[1] * AtrMult);
def DN = lowestC[1] + (avgTR[1] * AtrMult);

script nz {
input data = 0;
input data2 = close;
def ret_val = if IsNaN(data) then data else data2;
plot return = ret_val;
}
def ret = if close > UP and close > DN then UP else if close < DN and close < UP then DN else ret[1];
def pos = if close > ret then 1 else if close < ret then -1 else pos[1];

def Barret = if close > UP and close > DN then UP else if close < DN and close < UP then DN else nz(Barret[1], close);
def BarColor = if close > Barret then 1 else if close < Barret then -1 else nz(BarColor[1], 0);

plot trend = SimpleMovingAvg((UP + DN) / 2, Length);
trend.AssignValueColor ( if pos == -1 then CreateColor(255, 82, 82) else if pos == 1 then CreateColor(33, 150, 243) else Color.GRAY);

AssignPriceColor ( if pricecolor then if BarColor == -1 then color.red else if BarColor == 1 then color.green else Color.gray else color.current);
 
unless you intended to make this into a trend line if you look at the, trading the Trend article of TASC September 1998. it clearly showing an upper and lower band not a signal line.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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