This is the TradingView Trend Trader Strategy
https://usethinkscript.com/threads/convert-tradingview-trend-trader-strategy.10941/
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: