- Platform
-
- Thinkorswim

Range Filter converted from TV.
https://fr.tradingview.com/script/vkyFo1sQ/
Rich (BB 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