// Trend Trader Strategy (TTS)
//
// https://www.prorealcode.com/topic/converting-indicator-trend-trader-strategy/
//
// https://www.tradingview.com/script/j1etwXMQ-Trend-Trader-Strategy/
//
// @version=4
////////////////////////////////////////////////////////////
// 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
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
//ONCE Length = 21
//ONCE Multiplier = 3
length = max(1,min(999,length))
multiplier = max(0,min(999,multiplier))
MyATR = AverageTrueRange[1](close)
avgTR = average[Length,2](MyATR)
highestC = highest[Length](close)
lowestC = lowest[Length](close)
hilimit = highestC[1] - (avgTR[1] * Multiplier)
lolimit = lowestC[1] + (avgTR[1] * Multiplier)
//
ret = 0
pos = 0
//
IF (close > hilimit) AND (close > lolimit) THEN
ret = hilimit
ELSE
IF (close < lolimit) AND (close < hilimit) THEN
ret = lolimit
ELSE
//IF ret[1] = 0 THEN
ret = close
//ENDIF
ENDIF
ENDIF
//
IF close > ret THEN
pos = 1
ELSE
IF close < ret THEN
pos = -1
ELSE
pos = pos[1]
ENDIF
ENDIF
r = 0
g = 128
b = 0
t = 155
IF pos = -1 THEN
r = 255
g = 0
t = 255
ENDIF
DrawCandle(Open,High,Low,Close) coloured(r,g,b,t)
RETURN ret coloured(0,0,255,255) AS "Trend Trader Strategy"