• Get $40 off VIP by signing up for a free account! Sign Up

Range Filter Buy & Sell 5 min for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
awebsxn.png


Range Filter converted from TV.
https://fr.tradingview.com/script/vkyFo1sQ/

Code:
#//Original Script > @DonovanWall
#// Actual Version > @guikroth
#https://fr.tradingview.com/script/vkyFo1sQ/
#// Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters
#study(title="Range Filter  5min", overlay=true)
# Converted by Sam4Cok @ 07/2022

input ShowTarget = yes;
input BarColor   = yes;
input ShowBubble = yes;
input src  = close; #, title="Source")
input RFLength   = 100; #, minval=1, title="Sampling Period")
input RangeMulti = 3.0;#, minval=0.1, title="Range Multiplier")

def na = Double.NaN;
########## Colors ########
DefineGlobalColor("lime"    , CreateColor(0,230,118));
DefineGlobalColor("red"     , CreateColor(247,12,24));
DefineGlobalColor("aqua"    , CreateColor(4,93,95));
DefineGlobalColor("maroon"  , CreateColor(132,0,0));
DefineGlobalColor("green"   , CreateColor(22,96,69));
DefineGlobalColor("orange"  , CreateColor(255,152,0));
DefineGlobalColor("fuchsia" , CreateColor(140,5,79));
############
script nz {
    input data  = 0;
    input data1 = 0;
    def ret_val = if isNaN(data) then data1 else data;
    plot return = ret_val;
}
#// Smooth Average Range
#smoothrng(x, t, m)
script smoothrng {
input src  = close;
input per  = 100;
input mult = 3;
def wper = per * 2 - 1;
def avrng = ExpAverage(AbsValue(src - src[1]), per);
def smoothrng = ExpAverage(avrng, wper) * mult;
    plot result = smoothrng;
}
#// Range Filter
#rngfilt(x, r) =>
script rngfilt {
input x  = close;
input r  = 0;
def  rngfilt = if x > nz(rngfilt[1]) then if x - r < nz(rngfilt[1]) then nz(rngfilt[1]) else x - r else
               if x + r > nz(rngfilt[1]) then nz(rngfilt[1]) else x + r;
 plot result = rngfilt;
}
#########
def smrng = smoothrng(src, RFLength, RangeMulti);
def filt  = rngfilt(src, smrng);
#// Filter Direction
def upward   = if filt > filt[1] then nz(upward[1])   + 1 else if filt < filt[1] then 0 else nz(upward[1]);
def downward = if filt < filt[1] then nz(downward[1]) + 1 else if filt > filt[1] then 0 else nz(downward[1]);

#// Colors & plot
def filtcolor = if upward > 0 then 1 else if downward > 0 then -1 else 0;

plot filtplot = nz(filt, close); #"Range Filter"
filtplot.AssignValueColor( if filtcolor > 0 then GlobalColor("lime") else
                           if filtcolor < 0 then GlobalColor("red") else GlobalColor("orange"));
filtplot.SetLineWeight(2);
filtplot.HideTitle();

#// Target Bands
def hband = filt + smrng;
def lband = filt - smrng;
#// Target
def hbandplot = hband;
def lbandplot = lband;

#// Break Outs
def longCond = src > filt and src > src[1] and upward > 0 or
               src > filt and src < src[1] and upward > 0;
def shortCond = src < filt and src < src[1] and downward > 0 or
                src < filt and src > src[1] and downward > 0;
def CondIni = if longCond then 1 else if !shortCond then -1 else CondIni[1];
def longCondition = filtcolor > 0 and filtcolor[1] < 0;
def shortCondition = filtcolor < 0 and filtcolor[1] > 0;

#//Alerts & Fills
Addcloud(if ShowTarget then hbandplot else na, filtplot, GlobalColor("aqua"), GlobalColor("aqua"), no);
Addcloud(if ShowTarget then lbandplot else na, filtplot, GlobalColor("fuchsia"), GlobalColor("fuchsia"), no);

AssignPriceColor(if BarColor then if src > filt and src > src[1] and upward > 0 then GlobalColor("lime") else
   if src > filt and src < src[1] and upward > 0 then GlobalColor("green") else
   if src < filt and src < src[1] and downward > 0 then GlobalColor("red") else
   if src < filt and src > src[1] and downward > 0 then GlobalColor("maroon") else
        GlobalColor("orange") else Color.CURRENT);

AddChartBubble(if ShowBubble then longCondition else na, low, "BUY", GlobalColor("green"), no);
AddChartBubble(if ShowBubble then shortCondition else na, high, "SELL", GlobalColor("red"), yes);

#### END
 
awebsxn.png


Range Filter converted from TV.
https://fr.tradingview.com/script/vkyFo1sQ/

Code:
#//Original Script > @DonovanWall
#// Actual Version > @guikroth
#https://fr.tradingview.com/script/vkyFo1sQ/
#// Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters
#study(title="Range Filter  5min", overlay=true)
# Converted by Sam4Cok @ 07/2022

input ShowTarget = yes;
input BarColor   = yes;
input ShowBubble = yes;
input src  = close; #, title="Source")
input RFLength   = 100; #, minval=1, title="Sampling Period")
input RangeMulti = 3.0;#, minval=0.1, title="Range Multiplier")

def na = Double.NaN;
########## Colors ########
DefineGlobalColor("lime"    , CreateColor(0,230,118));
DefineGlobalColor("red"     , CreateColor(247,12,24));
DefineGlobalColor("aqua"    , CreateColor(4,93,95));
DefineGlobalColor("maroon"  , CreateColor(132,0,0));
DefineGlobalColor("green"   , CreateColor(22,96,69));
DefineGlobalColor("orange"  , CreateColor(255,152,0));
DefineGlobalColor("fuchsia" , CreateColor(140,5,79));
############
script nz {
    input data  = 0;
    input data1 = 0;
    def ret_val = if isNaN(data) then data1 else data;
    plot return = ret_val;
}
#// Smooth Average Range
#smoothrng(x, t, m)
script smoothrng {
input src  = close;
input per  = 100;
input mult = 3;
def wper = per * 2 - 1;
def avrng = ExpAverage(AbsValue(src - src[1]), per);
def smoothrng = ExpAverage(avrng, wper) * mult;
    plot result = smoothrng;
}
#// Range Filter
#rngfilt(x, r) =>
script rngfilt {
input x  = close;
input r  = 0;
def  rngfilt = if x > nz(rngfilt[1]) then if x - r < nz(rngfilt[1]) then nz(rngfilt[1]) else x - r else
               if x + r > nz(rngfilt[1]) then nz(rngfilt[1]) else x + r;
 plot result = rngfilt;
}
#########
def smrng = smoothrng(src, RFLength, RangeMulti);
def filt  = rngfilt(src, smrng);
#// Filter Direction
def upward   = if filt > filt[1] then nz(upward[1])   + 1 else if filt < filt[1] then 0 else nz(upward[1]);
def downward = if filt < filt[1] then nz(downward[1]) + 1 else if filt > filt[1] then 0 else nz(downward[1]);

#// Colors & plot
def filtcolor = if upward > 0 then 1 else if downward > 0 then -1 else 0;

plot filtplot = nz(filt, close); #"Range Filter"
filtplot.AssignValueColor( if filtcolor > 0 then GlobalColor("lime") else
                           if filtcolor < 0 then GlobalColor("red") else GlobalColor("orange"));
filtplot.SetLineWeight(2);
filtplot.HideTitle();

#// Target Bands
def hband = filt + smrng;
def lband = filt - smrng;
#// Target
def hbandplot = hband;
def lbandplot = lband;

#// Break Outs
def longCond = src > filt and src > src[1] and upward > 0 or
               src > filt and src < src[1] and upward > 0;
def shortCond = src < filt and src < src[1] and downward > 0 or
                src < filt and src > src[1] and downward > 0;
def CondIni = if longCond then 1 else if !shortCond then -1 else CondIni[1];
def longCondition = filtcolor > 0 and filtcolor[1] < 0;
def shortCondition = filtcolor < 0 and filtcolor[1] > 0;

#//Alerts & Fills
Addcloud(if ShowTarget then hbandplot else na, filtplot, GlobalColor("aqua"), GlobalColor("aqua"), no);
Addcloud(if ShowTarget then lbandplot else na, filtplot, GlobalColor("fuchsia"), GlobalColor("fuchsia"), no);

AssignPriceColor(if BarColor then if src > filt and src > src[1] and upward > 0 then GlobalColor("lime") else
   if src > filt and src < src[1] and upward > 0 then GlobalColor("green") else
   if src < filt and src < src[1] and downward > 0 then GlobalColor("red") else
   if src < filt and src > src[1] and downward > 0 then GlobalColor("maroon") else
        GlobalColor("orange") else Color.CURRENT);

AddChartBubble(if ShowBubble then longCondition else na, low, "BUY", GlobalColor("green"), no);
AddChartBubble(if ShowBubble then shortCondition else na, high, "SELL", GlobalColor("red"), yes);

#### END

Thank you for giving us yet another excellent stock indictor. This resembles the "follow line" indicator that I now use

# Follow Line Indicator
# Coverted to ToS from TV by bigboss. Original © Dreadblitz
# Added PaintBars by NPTechs

input BbPeriod = 6;
input BbDeviations = 0.1;
input UseAtrFilter = yes;
input AtrPeriod = 5;
input HideArrows = no;
#addlabel (yes, " ", color.black);
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);

Alert(buy, "follow_the_line-buy ", Alert.Bar, Sound.ring);

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

Alert(sell, "follow_the_line-short ", Alert.Bar, Sound.ring);

plot tline = TrendLine;
tline.AssignValueColor(if iTrend > 0 then COLOR.cyan else COLOR.magenta);
tline.SetLineWeight(4);

AddLabel(yes, if iTrend > 0 then "Follow Line-Bullish " else
"Follow Line-Bearish" ,
if iTrend > 0 then Color.green else
Color.red );
#addlabel (yes, " ", color.black);
input PaintBars = Yes;
#AssignPriceColor (if !PaintBars then Color.CURRENT else if iTrend > 0 then Color.GREEN else Color.RED);
 
Thank you for giving us yet another excellent stock indictor. This resembles the "follow line" indicator that I now use

# Follow Line Indicator
# Coverted to ToS from TV by bigboss. Original © Dreadblitz
# Added PaintBars by NPTechs

input BbPeriod = 6;
input BbDeviations = 0.1;
input UseAtrFilter = yes;
input AtrPeriod = 5;
input HideArrows = no;
#addlabel (yes, " ", color.black);
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);

Alert(buy, "follow_the_line-buy ", Alert.Bar, Sound.ring);

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

Alert(sell, "follow_the_line-short ", Alert.Bar, Sound.ring);

plot tline = TrendLine;
tline.AssignValueColor(if iTrend > 0 then COLOR.cyan else COLOR.magenta);
tline.SetLineWeight(4);

AddLabel(yes, if iTrend > 0 then "Follow Line-Bullish " else
"Follow Line-Bearish" ,
if iTrend > 0 then Color.green else
Color.red );
#addlabel (yes, " ", color.black);
input PaintBars = Yes;
#AssignPriceColor (if !PaintBars then Color.CURRENT else if iTrend > 0 then Color.GREEN else Color.RED);
agree. multiple indicators for multiple flavors :)
 
awebsxn.png


Range Filter converted from TV.
https://fr.tradingview.com/script/vkyFo1sQ/

Code:
#//Original Script > @DonovanWall
#// Actual Version > @guikroth
#https://fr.tradingview.com/script/vkyFo1sQ/
#// Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters
#study(title="Range Filter  5min", overlay=true)
# Converted by Sam4Cok @ 07/2022

input ShowTarget = yes;
input BarColor   = yes;
input ShowBubble = yes;
input src  = close; #, title="Source")
input RFLength   = 100; #, minval=1, title="Sampling Period")
input RangeMulti = 3.0;#, minval=0.1, title="Range Multiplier")

def na = Double.NaN;
########## Colors ########
DefineGlobalColor("lime"    , CreateColor(0,230,118));
DefineGlobalColor("red"     , CreateColor(247,12,24));
DefineGlobalColor("aqua"    , CreateColor(4,93,95));
DefineGlobalColor("maroon"  , CreateColor(132,0,0));
DefineGlobalColor("green"   , CreateColor(22,96,69));
DefineGlobalColor("orange"  , CreateColor(255,152,0));
DefineGlobalColor("fuchsia" , CreateColor(140,5,79));
############
script nz {
    input data  = 0;
    input data1 = 0;
    def ret_val = if isNaN(data) then data1 else data;
    plot return = ret_val;
}
#// Smooth Average Range
#smoothrng(x, t, m)
script smoothrng {
input src  = close;
input per  = 100;
input mult = 3;
def wper = per * 2 - 1;
def avrng = ExpAverage(AbsValue(src - src[1]), per);
def smoothrng = ExpAverage(avrng, wper) * mult;
    plot result = smoothrng;
}
#// Range Filter
#rngfilt(x, r) =>
script rngfilt {
input x  = close;
input r  = 0;
def  rngfilt = if x > nz(rngfilt[1]) then if x - r < nz(rngfilt[1]) then nz(rngfilt[1]) else x - r else
               if x + r > nz(rngfilt[1]) then nz(rngfilt[1]) else x + r;
 plot result = rngfilt;
}
#########
def smrng = smoothrng(src, RFLength, RangeMulti);
def filt  = rngfilt(src, smrng);
#// Filter Direction
def upward   = if filt > filt[1] then nz(upward[1])   + 1 else if filt < filt[1] then 0 else nz(upward[1]);
def downward = if filt < filt[1] then nz(downward[1]) + 1 else if filt > filt[1] then 0 else nz(downward[1]);

#// Colors & plot
def filtcolor = if upward > 0 then 1 else if downward > 0 then -1 else 0;

plot filtplot = nz(filt, close); #"Range Filter"
filtplot.AssignValueColor( if filtcolor > 0 then GlobalColor("lime") else
                           if filtcolor < 0 then GlobalColor("red") else GlobalColor("orange"));
filtplot.SetLineWeight(2);
filtplot.HideTitle();

#// Target Bands
def hband = filt + smrng;
def lband = filt - smrng;
#// Target
def hbandplot = hband;
def lbandplot = lband;

#// Break Outs
def longCond = src > filt and src > src[1] and upward > 0 or
               src > filt and src < src[1] and upward > 0;
def shortCond = src < filt and src < src[1] and downward > 0 or
                src < filt and src > src[1] and downward > 0;
def CondIni = if longCond then 1 else if !shortCond then -1 else CondIni[1];
def longCondition = filtcolor > 0 and filtcolor[1] < 0;
def shortCondition = filtcolor < 0 and filtcolor[1] > 0;

#//Alerts & Fills
Addcloud(if ShowTarget then hbandplot else na, filtplot, GlobalColor("aqua"), GlobalColor("aqua"), no);
Addcloud(if ShowTarget then lbandplot else na, filtplot, GlobalColor("fuchsia"), GlobalColor("fuchsia"), no);

AssignPriceColor(if BarColor then if src > filt and src > src[1] and upward > 0 then GlobalColor("lime") else
   if src > filt and src < src[1] and upward > 0 then GlobalColor("green") else
   if src < filt and src < src[1] and downward > 0 then GlobalColor("red") else
   if src < filt and src > src[1] and downward > 0 then GlobalColor("maroon") else
        GlobalColor("orange") else Color.CURRENT);

AddChartBubble(if ShowBubble then longCondition else na, low, "BUY", GlobalColor("green"), no);
AddChartBubble(if ShowBubble then shortCondition else na, high, "SELL", GlobalColor("red"), yes);

#### END
do you guys never just add the complete script to cut and past into Toss? Thanks
 
This indicator is the best of all the stock indicators I've tried. I appreciate you sharing with us, Samer800. Although the indicator's heading says "5 min," I'm not sure why because it also performs well on other time frames (i am currently using on a 1 minute time frame)
 
This looks really good, I'm a tad confused is this the complete study as I see stuff about add lines or change things in code in other searches related to this for TOS. Also is there a way to get an alert for stocks in watchlist when these alerts fire. Thank You
 
This looks really good, I'm a tad confused is this the complete study as I see stuff about add lines or change things in code in other searches related to this for TOS. Also is there a way to get an alert for stocks in watchlist when these alerts fire. Thank You
I inserted the following code for alerts and labels


AddLabel(yes, if filtcolor > 0 then "RangeFilter-Bullish " else
if filtcolor < 0 then "RangeFilter-Bearish" else "",
if filtcolor > 0 then Color.green else
if filtcolor < 0 then Color.red else color.black);

Alert(filtcolor[1] < 0 and filtcolor > 0, "RangeFilter-Bullish ", Alert.Bar, Sound.ring);
Alert(filtcolor[1] > 0 and filtcolor < 0, "RangeFilter-Bearish ", Alert.Bar, Sound.ring);
 
I inserted the following code for alerts and labels


AddLabel(yes, if filtcolor > 0 then "RangeFilter-Bullish " else
if filtcolor < 0 then "RangeFilter-Bearish" else "",
if filtcolor > 0 then Color.green else
if filtcolor < 0 then Color.red else color.black);

Alert(filtcolor[1] < 0 and filtcolor > 0, "RangeFilter-Bullish ", Alert.Bar, Sound.ring);
Alert(filtcolor[1] > 0 and filtcolor < 0, "RangeFilter-Bearish ", Alert.Bar, Sound.ring);
Thank You - I am new at these scripts do I just insert this above the end line
 
Wow! This is definitely one of the better chart studies out there. Thank you Samer800 for converting it. I was hoping someone could convert this study into a watchlist custom column. I tried, but the " count " section of the script is wrong. Because it is generating an incorrect count. Here is the script that I came up with. Any help in correcting the "count" would be much appreciated. ( I have the aggregation set to 1hr).

#//Original Script > @DonovanWall
#// Actual Version > @guikroth
#https://fr.tradingview.com/script/vkyFo1sQ/
#// Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters
#study(title="Range Filter 5min", overlay=true)
# Converted by Sam4Cok @ 07/2022
## Additional global colors added by ZupDog
## Label added by ZupDog


#input BarColor = yes;
input Color_Candles = no;
input ShowLabel = no;
input ShowBubble = yes;
input ShowTarget = yes;
input src = close; #, title="Source")
input RFLength = 5; #, minval=1, title="Sampling Period")
input RangeMulti = 3.5;#, minval=0.1, title="Range Multiplier")

def na = Double.NaN;

########## Colors ########
DefineGlobalColor("white" , CreateColor(255,255,255));
DefineGlobalColor("cyan" , CreateColor(0,255,255));
DefineGlobalColor("lime" , CreateColor(0,230,118));
DefineGlobalColor("red" , CreateColor(247,12,24));
DefineGlobalColor("aqua" , CreateColor(4,93,95));
DefineGlobalColor("maroon" , CreateColor(132,0,0));
DefineGlobalColor("green" , CreateColor(22,96,69));
DefineGlobalColor("orange" , CreateColor(255,152,0));
DefineGlobalColor("fuchsia" , CreateColor(140,5,79));
DefineGlobalColor("yellow" , CreateColor(255,255,0));
DefineGlobalColor("pink" , CreateColor(255,102,204));
DefineGlobalColor("magenta" , CreateColor(255,0,255));
############

script nz {
input data = 0;
input data1 = 0;
def ret_val = if isNaN(data) then data1 else data;
plot return = ret_val;
}
#// Smooth Average Range
#smoothrng(x, t, m)
script smoothrng {
input src = close;
input per = 100;
input mult = 3;
def wper = per * 2 - 1;
def avrng = ExpAverage(AbsValue(src - src[1]), per);
def smoothrng = ExpAverage(avrng, wper) * mult;
plot result = smoothrng;
}
#// Range Filter
#rngfilt(x, r) =>
script rngfilt {
input x = close;
input r = 0;
def rngfilt = if x > nz(rngfilt[1]) then if x - r < nz(rngfilt[1]) then nz(rngfilt[1]) else x - r else
if x + r > nz(rngfilt[1]) then nz(rngfilt[1]) else x + r;
plot result = rngfilt;
}
#########
def smrng = smoothrng(src, RFLength, RangeMulti);
def filt = rngfilt(src, smrng);
#// Filter Direction
def upward = if filt > filt[1] then nz(upward[1]) + 1 else if filt < filt[1] then 0 else nz(upward[1]);
def downward = if filt < filt[1] then nz(downward[1]) + 1 else if filt > filt[1] then 0 else nz(downward[1]);

#// Colors & plot
def filtcolor = if upward > 0 then 1 else if downward > 0 then -1 else 0;

plot filtplot = nz(filt, close); #"Range Filter"
#filtplot.AssignValueColor( if filtcolor > 0 then GlobalColor("cyan") else
# if filtcolor < 0 then GlobalColor("yellow") else GlobalColor("orange"));

filtplot.SetLineWeight(2);
filtplot.HideTitle();

#// Target Bands
def hband = filt + smrng;
def lband = filt - smrng;
#// Target
def hbandplot = hband;
def lbandplot = lband;

#// Break Outs
def longCond = src > filt and src > src[1] and upward > 0 or
src > filt and src < src[1] and upward > 0;
def shortCond = src < filt and src < src[1] and downward > 0 or
src < filt and src > src[1] and downward > 0;
def CondIni = if longCond then 1 else if !shortCond then -1 else CondIni[1];
def longCondition = filtcolor > 0 and filtcolor[1] < 0;
def shortCondition = filtcolor < 0 and filtcolor[1] > 0;

#//Alerts & Fills
#Addcloud(if ShowTarget then hbandplot else na, filtplot, GlobalColor("aqua"), GlobalColor("aqua"), no);
#Addcloud(if ShowTarget then lbandplot else na, filtplot, GlobalColor("fuchsia"), GlobalColor("fuchsia"), no);

#AssignPriceColor(if BarColor then if src > filt and src > src[1] and upward > 0 then GlobalColor("lime") else
# if src > filt and src < src[1] and upward > 0 then GlobalColor("green") else
# if src < filt and src < src[1] and downward > 0 then GlobalColor("red") else
# if src < filt and src > src[1] and downward > 0 then GlobalColor("maroon") else
# GlobalColor("orange") else Color.CURRENT);

assignbackgroundColor(if filtcolor > 0 then Color.BLUE else color.DARK_RED);

rec countup = if filtcolor > 0 then countup[1] + 1 else 0;
rec countdn = if filtcolor < 0 then countdn[1] - 1 else 0;

AddLabel(ShowLabel, Concat("UTS_RangeFilter ", if filtcolor > 0 then countup else countdn), if filtcolor > 0 then Color.CYAN else if filtcolor < 0 then Color.YELLOW else Color.WHITE );



#AssignPriceColor( if filtcolor > 0 then Color.BLUE else
# if filtcolor < 0 then Color.DARK_RED else GlobalColor("orange"));

#AssignPriceColor(if !Color_Candles
# then Color.CURRENT else if filtcolor > 0 then Color.BLUE else if filtcolor < 0 then Color.DARK_RED else GlobalColor("orange"));


#### END
 
Really like what you added going to play around and see how it does before taking any trades. Thank you!!!
i just combined Range filter with Follow line into one study

CSS:
#//Original Script > @DonovanWall
#// Actual Version > @guikroth
#https://fr.tradingview.com/script/vkyFo1sQ/
#// Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters
#study(title="Range Filter  5min", overlay=true)
# Converted by Sam4Cok @ 07/2022
# Combined Range Filter and Follow Line by Sam4COK @ Samer800 - 08/2022
input ShowTarget = yes;
input BarColor   = no;
input ShowLabel  = yes;
input filterLine = yes;
input MALines    = no;
input ShowBubble = yes;
input Source  = close; #, title="Source")
input RFLength   = 100; #, minval=1, title="Sampling Period")
input RangeMulti = 3.0;#, minval=0.1, title="Range Multiplier")
input MAFilter   = yes;
input AverageType   = AverageType.EXPONENTIAL;
input fastMALength = 20;
input slowMALength = 50;

def na = Double.NaN;
########## Colors ########
DefineGlobalColor("lime"    , CreateColor(0,230,118));
DefineGlobalColor("red"     , CreateColor(247,12,24));
DefineGlobalColor("aqua"    , CreateColor(4,93,95));
DefineGlobalColor("maroon"  , CreateColor(132,0,0));
DefineGlobalColor("green"   , CreateColor(22,96,69));
DefineGlobalColor("orange"  , CreateColor(255,152,0));
DefineGlobalColor("fuchsia" , CreateColor(140,5,79));
DefineGlobalColor("yellow"  , CreateColor(231,190,0));
############
script nz {
    input data  = 0;
    input data1 = 0;
    def ret_val = if isNaN(data) then data1 else data;
    plot return = ret_val;
}
#// Smooth Average Range
#smoothrng(x, t, m)
script smoothrng {
input src  = close;
input per  = 100;
input mult = 3;
def wper = per * 2 - 1;
def avrng = ExpAverage(AbsValue(src - src[1]), per);
def smoothrng = ExpAverage(avrng, wper) * mult;
    plot result = smoothrng;
}
###### EMAs #########
def FastEMA = MovingAverage(AverageType, Source, fastMALength);
def SlowEMA = MovingAverage(AverageType, Source, slowMALength);

plot FastMA = FastEMA;
FastMA.SetDefaultColor(Color.WHITE);
FastMA.SetHiding(!MALines);
plot SlowMA = SlowEMA;
SlowMA.SetDefaultColor(GlobalColor("yellow"));
SlowMA.SetHiding(!MALines);

#// Range Filter
#rngfilt(x, r) =>
script rngfilt {
input x  = close;
input r  = 0;
def  rngfilt = if x > nz(rngfilt[1]) then if x - r < nz(rngfilt[1]) then nz(rngfilt[1]) else x - r else
               if x + r > nz(rngfilt[1]) then nz(rngfilt[1]) else x + r;
 plot result = rngfilt;
}
#########
def smrng = smoothrng(Source, RFLength, RangeMulti);
def filt  = rngfilt(Source, smrng);
#// Filter Direction
def upward   = if filt > filt[1] then nz(upward[1])   + 1 else if filt < filt[1] then 0 else nz(upward[1]);
def downward = if filt < filt[1] then nz(downward[1]) + 1 else if filt > filt[1] then 0 else nz(downward[1]);

#// Colors & plot
def filtcolor = if upward > 0 then 1 else if downward > 0 then -1 else 0;

plot filtplot = if filterLine then nz(filt, close) else na; #"Range Filter"
filtplot.AssignValueColor( if filtcolor > 0 then GlobalColor("GREEN") else
                           if filtcolor < 0 then GlobalColor("orange") else GlobalColor("orange"));
filtplot.SetLineWeight(2);
filtplot.HideTitle();

#// Target Bands
def hband = filt + smrng;
def lband = filt - smrng;
#// Target
def hbandplot = hband;
def lbandplot = lband;

#// Break Outs
def longCond = Source > filt and Source > Source[1] and upward > 0 or
               Source > filt and Source < Source[1] and upward > 0;
def shortCond = Source < filt and Source < Source[1] and downward > 0 or
                Source < filt and Source > Source[1] and downward > 0;
def CondIni = if longCond then 1 else if !shortCond then -1 else CondIni[1];
def longCondition = filtcolor > 0 and filtcolor[1] < 0;
def shortCondition = filtcolor < 0 and filtcolor[1] > 0;
def BullEMA = FastEMA > SlowEMA;
def SellEMA = FastEMA < SlowEMA;

#//Alerts & Fills
Addcloud(if ShowTarget then hbandplot else na, filtplot, GlobalColor("aqua"), GlobalColor("aqua"), no);
Addcloud(if ShowTarget then lbandplot else na, filtplot, GlobalColor("fuchsia"), GlobalColor("fuchsia"), no);

AssignPriceColor(if BarColor then
   if Source > filt and Source > Source[1] and upward > 0 then GlobalColor("lime") else
   if Source > filt and Source < Source[1] and upward > 0 then GlobalColor("green") else
   if Source < filt and Source < Source[1] and downward > 0 then GlobalColor("red") else
   if Source < filt and Source > Source[1] and downward > 0 then GlobalColor("maroon") else
        GlobalColor("orange") else Color.CURRENT);

AddChartBubble(if ShowBubble then if MAFilter then longCondition and BullEMA else longCondition else na, low, "BUY", GlobalColor("lime"), no);
AddChartBubble(if ShowBubble then if MAFilter then shortCondition and SellEMA else shortCondition else na, high, "SELL", GlobalColor("red"), yes);

AddLabel(ShowLabel, if filtcolor > 0 then "RangeFilter-Bullish " else
if filtcolor < 0 then "RangeFilter-Bearish" else "",
if filtcolor > 0 then Color.green else
if filtcolor < 0 then Color.red else color.black);


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

input BbPeriod1      = 21;
input BbDeviations1  = 1;
input UseAtrFilter1  = yes;
input AtrPeriod1     = 5;
input HideArrows1    = no;

def BBUpper1=SimpleMovingAvg(close,BbPeriod1)+stdev(close, BbPeriod1)*BbDeviations1;
def BBLower1=SimpleMovingAvg(close,BbPeriod1)-stdev(close, BbPeriod1)*BbDeviations1;

def BBSignal1 = if close>BBUpper1 then 1 else if close<BBLower1 then -1 else 0;

def TrendLine1 =
    if BBSignal1 == 1 and UseAtrFilter1 == 1 then
        max(low-atr(AtrPeriod1),TrendLine1[1])
    else if BBSignal1 == -1 and UseAtrFilter1 == 1 then
        min(high+atr(AtrPeriod1),TrendLine1[1])
    else if BBSignal1 == 0 and UseAtrFilter1 == 1 then
        TrendLine1[1]
    else if BBSignal1 == 1 and UseAtrFilter1 == 0 then
        max(low,TrendLine1[1])
    else if BBSignal1 == -1 and UseAtrFilter1 == 0 then
        min(high,TrendLine1[1])
    else if BBSignal1 == 0 and UseAtrFilter1 == 0 then
        TrendLine1[1]
    else TrendLine1[1];

def iTrend1 = if TrendLine1>TrendLine1[1] then 1 else if TrendLine1 < TrendLine1[1] then -1 else iTrend1[1];
 
plot buy = if iTrend1[1]==-1 and iTrend1==1 and !HideArrows1 then TrendLine1 else Double.NaN;
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy.SetDefaultColor(Color.GREEN);
buy.SetLineWeight(3);

plot sell = if iTrend1[1]==1 and iTrend1==-1 and !HideArrows1 then  TrendLine1 else Double.NaN;
sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sell.SetDefaultColor(Color.RED);
sell.SetLineWeight(3);

plot tline1 = TrendLine1;
tline1.AssignValueColor(if iTrend1 > 0 then CreateColor(33,150,243) else CreateColor(255,82,82));
tline1.SetLineWeight(2);

# 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(5);

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


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


########### Alerts


Alert(buy_arrow, "Time to buy!", Alert.Bar, Sound.Chimes);
Alert(sell_arrow, "Time to sell!", Alert.Bar, Sound.Bell);
 
i just combined Range filter with Follow line into one study

CSS:
#//Original Script > @DonovanWall
#// Actual Version > @guikroth
#https://fr.tradingview.com/script/vkyFo1sQ/
#// Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters
#study(title="Range Filter  5min", overlay=true)
# Converted by Sam4Cok @ 07/2022
# Combined Range Filter and Follow Line by Sam4COK @ Samer800 - 08/2022
input ShowTarget = yes;
input BarColor   = no;
input ShowLabel  = yes;
input filterLine = yes;
input MALines    = no;
input ShowBubble = yes;
input Source  = close; #, title="Source")
input RFLength   = 100; #, minval=1, title="Sampling Period")
input RangeMulti = 3.0;#, minval=0.1, title="Range Multiplier")
input MAFilter   = yes;
input AverageType   = AverageType.EXPONENTIAL;
input fastMALength = 20;
input slowMALength = 50;

def na = Double.NaN;
########## Colors ########
DefineGlobalColor("lime"    , CreateColor(0,230,118));
DefineGlobalColor("red"     , CreateColor(247,12,24));
DefineGlobalColor("aqua"    , CreateColor(4,93,95));
DefineGlobalColor("maroon"  , CreateColor(132,0,0));
DefineGlobalColor("green"   , CreateColor(22,96,69));
DefineGlobalColor("orange"  , CreateColor(255,152,0));
DefineGlobalColor("fuchsia" , CreateColor(140,5,79));
DefineGlobalColor("yellow"  , CreateColor(231,190,0));
############
script nz {
    input data  = 0;
    input data1 = 0;
    def ret_val = if isNaN(data) then data1 else data;
    plot return = ret_val;
}
#// Smooth Average Range
#smoothrng(x, t, m)
script smoothrng {
input src  = close;
input per  = 100;
input mult = 3;
def wper = per * 2 - 1;
def avrng = ExpAverage(AbsValue(src - src[1]), per);
def smoothrng = ExpAverage(avrng, wper) * mult;
    plot result = smoothrng;
}
###### EMAs #########
def FastEMA = MovingAverage(AverageType, Source, fastMALength);
def SlowEMA = MovingAverage(AverageType, Source, slowMALength);

plot FastMA = FastEMA;
FastMA.SetDefaultColor(Color.WHITE);
FastMA.SetHiding(!MALines);
plot SlowMA = SlowEMA;
SlowMA.SetDefaultColor(GlobalColor("yellow"));
SlowMA.SetHiding(!MALines);

#// Range Filter
#rngfilt(x, r) =>
script rngfilt {
input x  = close;
input r  = 0;
def  rngfilt = if x > nz(rngfilt[1]) then if x - r < nz(rngfilt[1]) then nz(rngfilt[1]) else x - r else
               if x + r > nz(rngfilt[1]) then nz(rngfilt[1]) else x + r;
 plot result = rngfilt;
}
#########
def smrng = smoothrng(Source, RFLength, RangeMulti);
def filt  = rngfilt(Source, smrng);
#// Filter Direction
def upward   = if filt > filt[1] then nz(upward[1])   + 1 else if filt < filt[1] then 0 else nz(upward[1]);
def downward = if filt < filt[1] then nz(downward[1]) + 1 else if filt > filt[1] then 0 else nz(downward[1]);

#// Colors & plot
def filtcolor = if upward > 0 then 1 else if downward > 0 then -1 else 0;

plot filtplot = if filterLine then nz(filt, close) else na; #"Range Filter"
filtplot.AssignValueColor( if filtcolor > 0 then GlobalColor("GREEN") else
                           if filtcolor < 0 then GlobalColor("orange") else GlobalColor("orange"));
filtplot.SetLineWeight(2);
filtplot.HideTitle();

#// Target Bands
def hband = filt + smrng;
def lband = filt - smrng;
#// Target
def hbandplot = hband;
def lbandplot = lband;

#// Break Outs
def longCond = Source > filt and Source > Source[1] and upward > 0 or
               Source > filt and Source < Source[1] and upward > 0;
def shortCond = Source < filt and Source < Source[1] and downward > 0 or
                Source < filt and Source > Source[1] and downward > 0;
def CondIni = if longCond then 1 else if !shortCond then -1 else CondIni[1];
def longCondition = filtcolor > 0 and filtcolor[1] < 0;
def shortCondition = filtcolor < 0 and filtcolor[1] > 0;
def BullEMA = FastEMA > SlowEMA;
def SellEMA = FastEMA < SlowEMA;

#//Alerts & Fills
Addcloud(if ShowTarget then hbandplot else na, filtplot, GlobalColor("aqua"), GlobalColor("aqua"), no);
Addcloud(if ShowTarget then lbandplot else na, filtplot, GlobalColor("fuchsia"), GlobalColor("fuchsia"), no);

AssignPriceColor(if BarColor then
   if Source > filt and Source > Source[1] and upward > 0 then GlobalColor("lime") else
   if Source > filt and Source < Source[1] and upward > 0 then GlobalColor("green") else
   if Source < filt and Source < Source[1] and downward > 0 then GlobalColor("red") else
   if Source < filt and Source > Source[1] and downward > 0 then GlobalColor("maroon") else
        GlobalColor("orange") else Color.CURRENT);

AddChartBubble(if ShowBubble then if MAFilter then longCondition and BullEMA else longCondition else na, low, "BUY", GlobalColor("lime"), no);
AddChartBubble(if ShowBubble then if MAFilter then shortCondition and SellEMA else shortCondition else na, high, "SELL", GlobalColor("red"), yes);

AddLabel(ShowLabel, if filtcolor > 0 then "RangeFilter-Bullish " else
if filtcolor < 0 then "RangeFilter-Bearish" else "",
if filtcolor > 0 then Color.green else
if filtcolor < 0 then Color.red else color.black);


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

input BbPeriod1      = 21;
input BbDeviations1  = 1;
input UseAtrFilter1  = yes;
input AtrPeriod1     = 5;
input HideArrows1    = no;

def BBUpper1=SimpleMovingAvg(close,BbPeriod1)+stdev(close, BbPeriod1)*BbDeviations1;
def BBLower1=SimpleMovingAvg(close,BbPeriod1)-stdev(close, BbPeriod1)*BbDeviations1;

def BBSignal1 = if close>BBUpper1 then 1 else if close<BBLower1 then -1 else 0;

def TrendLine1 =
    if BBSignal1 == 1 and UseAtrFilter1 == 1 then
        max(low-atr(AtrPeriod1),TrendLine1[1])
    else if BBSignal1 == -1 and UseAtrFilter1 == 1 then
        min(high+atr(AtrPeriod1),TrendLine1[1])
    else if BBSignal1 == 0 and UseAtrFilter1 == 1 then
        TrendLine1[1]
    else if BBSignal1 == 1 and UseAtrFilter1 == 0 then
        max(low,TrendLine1[1])
    else if BBSignal1 == -1 and UseAtrFilter1 == 0 then
        min(high,TrendLine1[1])
    else if BBSignal1 == 0 and UseAtrFilter1 == 0 then
        TrendLine1[1]
    else TrendLine1[1];

def iTrend1 = if TrendLine1>TrendLine1[1] then 1 else if TrendLine1 < TrendLine1[1] then -1 else iTrend1[1];
 
plot buy = if iTrend1[1]==-1 and iTrend1==1 and !HideArrows1 then TrendLine1 else Double.NaN;
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy.SetDefaultColor(Color.GREEN);
buy.SetLineWeight(3);

plot sell = if iTrend1[1]==1 and iTrend1==-1 and !HideArrows1 then  TrendLine1 else Double.NaN;
sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sell.SetDefaultColor(Color.RED);
sell.SetLineWeight(3);

plot tline1 = TrendLine1;
tline1.AssignValueColor(if iTrend1 > 0 then CreateColor(33,150,243) else CreateColor(255,82,82));
tline1.SetLineWeight(2);

# 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(5);

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


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


########### Alerts


Alert(buy_arrow, "Time to buy!", Alert.Bar, Sound.Chimes);
Alert(sell_arrow, "Time to sell!", Alert.Bar, Sound.Bell);
Great (Combining two powerful stock indicators into one). Many thanks
 
Range Filter Buy and Sell code--- I want an alert when the stock price/close pulls back and touches the "filtplot" line/plot since that is when I want to buy. I've been trying to code, but I've had no luck. Would someone kindly help?. Thank you
 
i just combined Range filter with Follow line into one study

CSS:
#//Original Script > @DonovanWall
#// Actual Version > @guikroth
#https://fr.tradingview.com/script/vkyFo1sQ/
#// Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters
#study(title="Range Filter  5min", overlay=true)
# Converted by Sam4Cok @ 07/2022
# Combined Range Filter and Follow Line by Sam4COK @ Samer800 - 08/2022
input ShowTarget = yes;
input BarColor   = no;
input ShowLabel  = yes;
input filterLine = yes;
input MALines    = no;
input ShowBubble = yes;
input Source  = close; #, title="Source")
input RFLength   = 100; #, minval=1, title="Sampling Period")
input RangeMulti = 3.0;#, minval=0.1, title="Range Multiplier")
input MAFilter   = yes;
input AverageType   = AverageType.EXPONENTIAL;
input fastMALength = 20;
input slowMALength = 50;

def na = Double.NaN;
########## Colors ########
DefineGlobalColor("lime"    , CreateColor(0,230,118));
DefineGlobalColor("red"     , CreateColor(247,12,24));
DefineGlobalColor("aqua"    , CreateColor(4,93,95));
DefineGlobalColor("maroon"  , CreateColor(132,0,0));
DefineGlobalColor("green"   , CreateColor(22,96,69));
DefineGlobalColor("orange"  , CreateColor(255,152,0));
DefineGlobalColor("fuchsia" , CreateColor(140,5,79));
DefineGlobalColor("yellow"  , CreateColor(231,190,0));
############
script nz {
    input data  = 0;
    input data1 = 0;
    def ret_val = if isNaN(data) then data1 else data;
    plot return = ret_val;
}
#// Smooth Average Range
#smoothrng(x, t, m)
script smoothrng {
input src  = close;
input per  = 100;
input mult = 3;
def wper = per * 2 - 1;
def avrng = ExpAverage(AbsValue(src - src[1]), per);
def smoothrng = ExpAverage(avrng, wper) * mult;
    plot result = smoothrng;
}
###### EMAs #########
def FastEMA = MovingAverage(AverageType, Source, fastMALength);
def SlowEMA = MovingAverage(AverageType, Source, slowMALength);

plot FastMA = FastEMA;
FastMA.SetDefaultColor(Color.WHITE);
FastMA.SetHiding(!MALines);
plot SlowMA = SlowEMA;
SlowMA.SetDefaultColor(GlobalColor("yellow"));
SlowMA.SetHiding(!MALines);

#// Range Filter
#rngfilt(x, r) =>
script rngfilt {
input x  = close;
input r  = 0;
def  rngfilt = if x > nz(rngfilt[1]) then if x - r < nz(rngfilt[1]) then nz(rngfilt[1]) else x - r else
               if x + r > nz(rngfilt[1]) then nz(rngfilt[1]) else x + r;
 plot result = rngfilt;
}
#########
def smrng = smoothrng(Source, RFLength, RangeMulti);
def filt  = rngfilt(Source, smrng);
#// Filter Direction
def upward   = if filt > filt[1] then nz(upward[1])   + 1 else if filt < filt[1] then 0 else nz(upward[1]);
def downward = if filt < filt[1] then nz(downward[1]) + 1 else if filt > filt[1] then 0 else nz(downward[1]);

#// Colors & plot
def filtcolor = if upward > 0 then 1 else if downward > 0 then -1 else 0;

plot filtplot = if filterLine then nz(filt, close) else na; #"Range Filter"
filtplot.AssignValueColor( if filtcolor > 0 then GlobalColor("GREEN") else
                           if filtcolor < 0 then GlobalColor("orange") else GlobalColor("orange"));
filtplot.SetLineWeight(2);
filtplot.HideTitle();

#// Target Bands
def hband = filt + smrng;
def lband = filt - smrng;
#// Target
def hbandplot = hband;
def lbandplot = lband;

#// Break Outs
def longCond = Source > filt and Source > Source[1] and upward > 0 or
               Source > filt and Source < Source[1] and upward > 0;
def shortCond = Source < filt and Source < Source[1] and downward > 0 or
                Source < filt and Source > Source[1] and downward > 0;
def CondIni = if longCond then 1 else if !shortCond then -1 else CondIni[1];
def longCondition = filtcolor > 0 and filtcolor[1] < 0;
def shortCondition = filtcolor < 0 and filtcolor[1] > 0;
def BullEMA = FastEMA > SlowEMA;
def SellEMA = FastEMA < SlowEMA;

#//Alerts & Fills
Addcloud(if ShowTarget then hbandplot else na, filtplot, GlobalColor("aqua"), GlobalColor("aqua"), no);
Addcloud(if ShowTarget then lbandplot else na, filtplot, GlobalColor("fuchsia"), GlobalColor("fuchsia"), no);

AssignPriceColor(if BarColor then
   if Source > filt and Source > Source[1] and upward > 0 then GlobalColor("lime") else
   if Source > filt and Source < Source[1] and upward > 0 then GlobalColor("green") else
   if Source < filt and Source < Source[1] and downward > 0 then GlobalColor("red") else
   if Source < filt and Source > Source[1] and downward > 0 then GlobalColor("maroon") else
        GlobalColor("orange") else Color.CURRENT);

AddChartBubble(if ShowBubble then if MAFilter then longCondition and BullEMA else longCondition else na, low, "BUY", GlobalColor("lime"), no);
AddChartBubble(if ShowBubble then if MAFilter then shortCondition and SellEMA else shortCondition else na, high, "SELL", GlobalColor("red"), yes);

AddLabel(ShowLabel, if filtcolor > 0 then "RangeFilter-Bullish " else
if filtcolor < 0 then "RangeFilter-Bearish" else "",
if filtcolor > 0 then Color.green else
if filtcolor < 0 then Color.red else color.black);


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

input BbPeriod1      = 21;
input BbDeviations1  = 1;
input UseAtrFilter1  = yes;
input AtrPeriod1     = 5;
input HideArrows1    = no;

def BBUpper1=SimpleMovingAvg(close,BbPeriod1)+stdev(close, BbPeriod1)*BbDeviations1;
def BBLower1=SimpleMovingAvg(close,BbPeriod1)-stdev(close, BbPeriod1)*BbDeviations1;

def BBSignal1 = if close>BBUpper1 then 1 else if close<BBLower1 then -1 else 0;

def TrendLine1 =
    if BBSignal1 == 1 and UseAtrFilter1 == 1 then
        max(low-atr(AtrPeriod1),TrendLine1[1])
    else if BBSignal1 == -1 and UseAtrFilter1 == 1 then
        min(high+atr(AtrPeriod1),TrendLine1[1])
    else if BBSignal1 == 0 and UseAtrFilter1 == 1 then
        TrendLine1[1]
    else if BBSignal1 == 1 and UseAtrFilter1 == 0 then
        max(low,TrendLine1[1])
    else if BBSignal1 == -1 and UseAtrFilter1 == 0 then
        min(high,TrendLine1[1])
    else if BBSignal1 == 0 and UseAtrFilter1 == 0 then
        TrendLine1[1]
    else TrendLine1[1];

def iTrend1 = if TrendLine1>TrendLine1[1] then 1 else if TrendLine1 < TrendLine1[1] then -1 else iTrend1[1];
 
plot buy = if iTrend1[1]==-1 and iTrend1==1 and !HideArrows1 then TrendLine1 else Double.NaN;
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy.SetDefaultColor(Color.GREEN);
buy.SetLineWeight(3);

plot sell = if iTrend1[1]==1 and iTrend1==-1 and !HideArrows1 then  TrendLine1 else Double.NaN;
sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sell.SetDefaultColor(Color.RED);
sell.SetLineWeight(3);

plot tline1 = TrendLine1;
tline1.AssignValueColor(if iTrend1 > 0 then CreateColor(33,150,243) else CreateColor(255,82,82));
tline1.SetLineWeight(2);

# 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(5);

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


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


########### Alerts


Alert(buy_arrow, "Time to buy!", Alert.Bar, Sound.Chimes);
Alert(sell_arrow, "Time to sell!", Alert.Bar, Sound.Bell);

I created a study that combines "follow line" with a share purchase budget study & many more. So it tells you how much of a profit or loss you would have made if you bought at the green arrow.

https://tos.mx/mzksK79

This is my all time favorite study because it lets me flip around quickly between diffrent stocks to judge the likelihood of reaching a profit goal with each stock.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
360 Online
Create Post

Similar threads

Similar threads

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