Follow Line Indicator For ThinkOrSwim

Hi @JP782 - Here is the follow line indicator implemented in thinkscript. I'm curious to hear your thoughts on the strategy!

Code:
# Follow Line Indicator
# Coverted to ToS from TV by bigboss. Original © Dreadblitz

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);
 
Wow thank you!
Strategy looks too easy you know!? Im gonna use OnDemand and see how it all works on some old gappers that ran... Im always open to anything new or a piece of one strategy with another. !
Hi @JP782 - Here is the follow line indicator implemented in thinkscript. I'm curious to hear your thoughts on the strategy!

Code:
# Follow Line Indicator
# Coverted to ToS from TV by bigboss. Original © Dreadblitz

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);
Thank you , it helped me to get into profitable trades in SPX today and avoid false signals. I will continue to test.
 
Wow thank you!
Strategy looks too easy you know!? Im gonna use OnDemand and see how it all works on some old gappers that ran... Im always open to anything new or a piece of one strategy with another. !
Here is an MTF version
Code:
# Follow Line Indicator MTF
# Coverted to ToS from TV by bigboss. Original © Dreadblitz
input period        = AggregationPeriod.FIFTEEN_MIN;
input BbPeriod      = 21;
input BbDeviations  = 1;
input UseAtrFilter  = yes;
input AtrPeriod     = 5;
input HideArrows    = no;

def h = high(period=period);
def l = low(period=period);
def c = close(period=period);

def ATR = MovingAverage(AverageType.WILDERS, TrueRange(h, c, l), AtrPeriod);


def BBUpper=SimpleMovingAvg(c,BBperiod)+stdev(c, BBperiod)*BBdeviations;
def BBLower=SimpleMovingAvg(c,BBperiod)-stdev(c, BBperiod)*BBdeviations;

def BBSignal = if c>BBUpper then 1 else if c<BBLower then -1 else 0;

def TrendLine =
    if BBSignal == 1 and UseATRfilter == 1 then
        max(l-ATR,TrendLine[1])
    else if BBSignal == -1 and UseATRfilter == 1 then
        min(h+ATR,TrendLine[1])
    else if BBSignal == 0 and UseATRfilter == 1 then
        TrendLine[1]
    else if BBSignal == 1 and UseATRfilter == 0 then
        max(l,TrendLine[1])
    else if BBSignal == -1 and UseATRfilter == 0 then
        min(h,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);
 
Here is an MTF version
Code:
# Follow Line Indicator MTF
# Coverted to ToS from TV by bigboss. Original © Dreadblitz
input period        = AggregationPeriod.FIFTEEN_MIN;
input BbPeriod      = 21;
input BbDeviations  = 1;
input UseAtrFilter  = yes;
input AtrPeriod     = 5;
input HideArrows    = no;

def h = high(period=period);
def l = low(period=period);
def c = close(period=period);

def ATR = MovingAverage(AverageType.WILDERS, TrueRange(h, c, l), AtrPeriod);


def BBUpper=SimpleMovingAvg(c,BBperiod)+stdev(c, BBperiod)*BBdeviations;
def BBLower=SimpleMovingAvg(c,BBperiod)-stdev(c, BBperiod)*BBdeviations;

def BBSignal = if c>BBUpper then 1 else if c<BBLower then -1 else 0;

def TrendLine =
    if BBSignal == 1 and UseATRfilter == 1 then
        max(l-ATR,TrendLine[1])
    else if BBSignal == -1 and UseATRfilter == 1 then
        min(h+ATR,TrendLine[1])
    else if BBSignal == 0 and UseATRfilter == 1 then
        TrendLine[1]
    else if BBSignal == 1 and UseATRfilter == 0 then
        max(l,TrendLine[1])
    else if BBSignal == -1 and UseATRfilter == 0 then
        min(h,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);
Whoa!! Dude your a machine, I wish I could "see" the code like so many of you
Im thinking 5m data on 1min chart will give better signals
 
Whoa!! Dude your a machine, I wish I could "see" the code like so many of you
Im thinking 5m data on 1min chart will give better signals
Just curious when do we MTF version compared to earlier version?. I mainly use for day trading.
 
When I backtested the buy and sell signals were different on both strategy and MTF versons.So I was just trying to clarify. Please do let me know your analysis too.
Did you try setting the MTF version to the timeframe your chart is set to? The non-MTF and MTF version should display identical.
 
Thank you for posting this indicator. I was curious so plotted it this morning and watched it during a trade. I prefer charts that aren't cluttered with so many lines, but this indicator did a great job showing the trend. Here it is plotted on a 5 minute micro crude chart with Consensus Candles.

Solid Line- FollowLine 5 minute
Long Dashed Line- FollowLine MTF (15 min)
Short Dashed Line- FollowLine MTF (30 min)
White Dashed Line- VWAP

Just after midnight, when price broke out of a squeeze at VWAP, the MACD BB confirmed a long entry. FollowLine was blue on 5, 15, 30 min intervals. If using the 5 min FollowLine as a stop loss, the trade would have scalped a small profit. If using the 15 min FollowLine as a stop loss, the trade would have been more profitable. If using the 30 min FollowLine as a stop loss, the trade would be ongoing*.

Price hit my profit target so I'm out, but it was interesting to watch this indicator during the trade. Thanks for posting it!

*NOT a trade recommendation!

 
I used same timeframe, I will test furthee and share the discrepancies.
Hi @Kitchasap - It's entirely possible I missed something when I coded up the MTF version. I compared 5 min FLI MTF on a 5 min chart to 5 min FLI non-MTF on a 5 minute chart and the signals were the same. If you can post an example of discrepancy I can figure out what's causing it.
 
Hi @Kitchasap - It's entirely possible I missed something when I coded up the MTF version. I compared 5 min FLI MTF on a 5 min chart to 5 min FLI non-MTF on a 5 minute chart and the signals were the same. If you can post an example of discrepancy I can figure out what's causing it.
It worked fine for me as well. I'm 99% sure Kitchasap isn't changing the MTF aggregation period to match their current chart timeframe.
 
I came across a study that I thought was cool but I felt like it could use small improvement tweaks such as displaying the buy & sell prices for a swing trade.

It seems like the 3 day - 15 minute chart - minus extended hours seems to be the best intraday settings.
Code:
# Follow Line Indicator
# Coverted to ToS from TV by bigboss. Original © Dreadblitz
#https://usethinkscript.com/threads/follow-line-indicator.9789/

input BbPeriod      = 9;
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_price = if iTrend[1]==-1 and iTrend==1 and !HideArrows then TrendLine else Double.NaN;
buy_price.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
buy_price.SetDefaultColor(Color.GREEN);
buy_price.SetLineWeight(3);

plot sell_price = if iTrend[1]==1 and iTrend==-1 and !HideArrows then  TrendLine else Double.NaN;
sell_price.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
sell_price.SetDefaultColor(Color.white);
sell_price.SetLineWeight(3);

plot buy_arrow = if iTrend[1]==-1 and iTrend==1 and !HideArrows then TrendLine else Double.NaN;
buy_arrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy_arrow.SetDefaultColor(Color.GREEN);
buy_arrow.SetLineWeight(3);

plot sell_arrow = if iTrend[1]==1 and iTrend==-1 and !HideArrows then  TrendLine else Double.NaN;
sell_arrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sell_arrow.SetDefaultColor(Color.RED);
sell_arrow.SetLineWeight(3);


plot tline = TrendLine;
tline.AssignValueColor(if iTrend > 0 then CreateColor(33,150,243) else CreateColor(255,82,82));
tline.SetPaintingStrategy(PaintingStrategy.DASHES);
tline.SetLineWeight(2);

https://tos.mx/NIJ9woa - this is my version.

Source for the original study. -
 
Last edited by a moderator:
Hi @JP782 - Here is the follow line indicator implemented in thinkscript. I'm curious to hear your thoughts on the strategy!

Code:
# Follow Line Indicator
# Coverted to ToS from TV by bigboss. Original © Dreadblitz

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);
Added color to bars

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);
 

Hey @Mr_Wheeler

I liked the addition of the price of the follow line on the trigger bar showing what the stop value should be. That was cool. Any way to add targets too, especially variable amount targets like 1:2, 1:2.5, etc. Either way, great addition to the script. Thank you
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
369 Online
Create Post

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