Follow Line Indicator

NPTechs

New member
Platform
  1. 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);
 

barbaros

Administrator
Staff member
OhiABCh.png
 
Would some kind soul help me with a scan for the Follow Line indicator signals. I have tried everything, and at my wits end, especially since I am a coding moron. I have tried all the scannable components of the Follow Line indicator, tried equal, greater then, true, etc to no avail. I don't know this a s a fact, but I assume a snippet of code needs to be added to the indicator to make it scannable. Any help is greatly appreciated.
 

barbaros

Administrator
Staff member
Would some kind soul help me with a scan for the Follow Line indicator signals. I have tried everything, and at my wits end, especially since I am a coding moron. I have tried all the scannable components of the Follow Line indicator, tried equal, greater then, true, etc to no avail. I don't know this a s a fact, but I assume a snippet of code needs to be added to the indicator to make it scannable. Any help is greatly appreciated.
Here is a scanner with simplified code. I haven’t tested. Look for buy is true or sell is true.

Code:
# Follow Line Indicator Scanner
# Coverted to ToS from TV by bigboss. Original © Dreadblitz
# Added PaintBars by NPTechs
# barbaros, simplified for scanner

input BbPeriod      = 21;
input BbDeviations  = 1;
input UseAtrFilter  = yes;
input AtrPeriod     = 5;

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 = iTrend[1]==-1 and iTrend==1;

plot sell = iTrend[1]==1 and iTrend==-1;
 
Last edited:
@barbaros Thank you for your quick response. I have a question. Do I load this code as an indicator, then make a scan from it, or do I just copy the code into the ThinkScript Editor side of the scan maker. The reason I ask is that I tried copying directly into scan maker on the Thinkscript Editor side and it doesn't seem to work. I get a message saying "exactly one plot expected" and I am unable to click OK to create the scan. Any thoughts, and thank you for taking the time to help me.

Update- I tried putting your code in as an indicator and then scanning for Buy or Sell is true. No luck. Doesn't return anything.
 
Last edited:

barbaros

Administrator
Staff member
@barbaros Thank you for your quick response. I have a question. Do I load this code as an indicator, then make a scan from it, or do I just copy the code into the ThinkScript Editor side of the scan maker. The reason I ask is that I tried copying directly into scan maker on the Thinkscript Editor side and it doesn't seem to work. I get a message saying "exactly one plot expected" and I am unable to click OK to create the scan. Any thoughts, and thank you for taking the time to help me.
You should save as a study and then use it in your scanner.
 
See update note above. I tried that, but it didn't work. Any additional ideas? Also, if it matters, I am trying to use a 15 min aggregation
 

barbaros

Administrator
Staff member
See update note above. I tried that, but it didn't work. Any additional ideas? Also, if it matters, I am trying to use a 15 min aggregation
Small update. I don't see an issue with the script.
Code:
# Follow Line Indicator Scanner
# Coverted to ToS from TV by bigboss. Original © Dreadblitz
# Added PaintBars by NPTechs
# barbaros, simplified for scanner

input BbPeriod      = 21;
input BbDeviations  = 1;
input UseAtrFilter  = yes;
input AtrPeriod     = 5;

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 = iTrend crosses above 0;
plot sell = iTrend crosses below 0;
 
@barbaros - still no luck. I tried both Buy and sell and I tried both 15 min and daily on both. Also tried within 10 bars on both and still nothing. Sorry this is becoming more of a chore to figure out.
 

barbaros

Administrator
Staff member
@barbaros - still no luck. I tried both Buy and sell and I tried both 15 min and daily on both. Also tried within 10 bars on both and still nothing. Sorry this is becoming more of a chore to figure out.
Here is how you can double check that script is working. If you load the script on your chart as a lower indicator, spiked will be the buy and sell signals. If you can find one that just spiked, it should show on your scanner. if you cannot, then scanner won't show anything.

A99oAZb.png
 
I tried what you said and moved indicator to lower and I see the spikes. but the scanner still returns nothing for Buy or Sell on daily or 15 min. Can you get it to work on your computer. I have tried within 10 bars to catch more signals but still nothing.
 

barbaros

Administrator
Staff member
I tried what you said and moved indicator to lower and I see the spikes. but the scanner still returns nothing for Buy or Sell on daily or 15 min. Can you get it to work on your computer. I have tried within 10 bars to catch more signals but still nothing.
I'll look at it when I get a chance. ToS scanner sometimes acts goofy.
 

barbaros

Administrator
Staff member
I'll look at it when I get a chance. ToS scanner sometimes acts goofy.
Ok, try this...Do not save it as a study. Paste it directly into the scanner custom script window. You can comment out buy or sell, and adjust within how many bars.

Code:
# Follow Line Indicator Scanner
# Coverted to ToS from TV by bigboss. Original © Dreadblitz
# Added PaintBars by NPTechs
# barbaros, simplified for scanner

input BbPeriod      = 21;
input BbDeviations  = 1;
input UseAtrFilter  = yes;
input AtrPeriod     = 5;

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 = iTrend crosses above 0 within 50 bars;
#plot sell = iTrend crosses below 0 within 50 bars;
 
@barbaros - That did the trick- Looks like it works perfect. You are my HERO, and also many thanks for your assistance. I have been fooling with this for ages. I never would have been able to figure it out.
 
Top