- Platform
-
- Thinkorswim
Ruby:
# Follow Line Indicator
# Coverted to ToS from TV by bigboss. Original © Dreadblitz
# Added PaintBars by NPTechs
input BbPeriod = 21;
input BbDeviations = 1;
input UseAtrFilter = yes;
input AtrPeriod = 5;
input HideArrows = no;
def BBUpper=SimpleMovingAvg(close,BBperiod)+stdev(close, BBperiod)*BBdeviations;
def BBLower=SimpleMovingAvg(close,BBperiod)-stdev(close, BBperiod)*BBdeviations;
def BBSignal = if close>BBUpper then 1 else if close<BBLower then -1 else 0;
def TrendLine =
if BBSignal == 1 and UseATRfilter == 1 then
max(low-atr(ATRperiod),TrendLine[1])
else if BBSignal == -1 and UseATRfilter == 1 then
min(high+atr(ATRperiod),TrendLine[1])
else if BBSignal == 0 and UseATRfilter == 1 then
TrendLine[1]
else if BBSignal == 1 and UseATRfilter == 0 then
max(low,TrendLine[1])
else if BBSignal == -1 and UseATRfilter == 0 then
min(high,TrendLine[1])
else if BBSignal == 0 and UseATRfilter == 0 then
TrendLine[1]
else TrendLine[1];
def iTrend = if TrendLine>TrendLine[1] then 1 else if TrendLine < TrendLine[1] then -1 else iTrend[1];
plot buy = if iTrend[1]==-1 and iTrend==1 and !HideArrows then TrendLine else Double.NaN;
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy.SetDefaultColor(Color.GREEN);
buy.SetLineWeight(3);
plot sell = if iTrend[1]==1 and iTrend==-1 and !HideArrows then TrendLine else Double.NaN;
sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sell.SetDefaultColor(Color.RED);
sell.SetLineWeight(3);
plot tline = TrendLine;
tline.AssignValueColor(if iTrend > 0 then CreateColor(33,150,243) else CreateColor(255,82,82));
tline.SetLineWeight(2);
input PaintBars = Yes;
AssignPriceColor (if !PaintBars then Color.CURRENT else if iTrend > 0 then Color.GREEN else Color.RED);