0% found this document useful (0 votes)
469 views3 pages

Range Filter

This document contains the source code for a Pine Script trading strategy. The strategy uses a range filter on a 5-minute chart of the BTCUSDC currency pair to identify potential buy and sell signals. It calculates a smoothed average range over a sampling period and uses this to filter price action and plot target bands. Color coding and alerts are used to identify breakouts above or below the filter for entering long or short positions.

Uploaded by

toengsaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
469 views3 pages

Range Filter

This document contains the source code for a Pine Script trading strategy. The strategy uses a range filter on a 5-minute chart of the BTCUSDC currency pair to identify potential buy and sell signals. It calculates a smoothed average range over a sampling period and uses this to filter price action and plot target bands. Color coding and alerts are used to identify breakouts above or below the filter for entering long or short positions.

Uploaded by

toengsaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//@version=4

//Original Script > @DonovanWall

// Actual Version > @guikroth

//////////////////////////////////////////////////////////////////////////
// Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters
//////////////////////////////////////////////////////////////////////////

study(title="Range Filter 5min", overlay=true)

// Source

src = input(defval=close, title="Source")

// Sampling Period
// Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters

per = input(defval=100, minval=1, title="Sampling Period")

// Range Multiplier

mult = input(defval=3.0, minval=0.1, title="Range Multiplier")

// Smooth Average Range

smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ema(abs(x - x[1]), t)
smoothrng = ema(avrng, wper) * m
smoothrng
smrng = smoothrng(src, per, mult)

// Range Filter

rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r
:
x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
rngfilt
filt = rngfilt(src, smrng)

// Filter Direction

upward = 0.0
upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 :
nz(downward[1])

// Target Bands

hband = filt + smrng


lband = filt - smrng
// Colors

filtcolor = upward > 0 ? [Link] : downward > 0 ? [Link] : [Link]


barcolor = src > filt and src > src[1] and upward > 0 ? [Link] :
src > filt and src < src[1] and upward > 0 ? [Link] :
src < filt and src < src[1] and downward > 0 ? [Link] :
src < filt and src > src[1] and downward > 0 ? [Link] : [Link]

filtplot = plot(filt, color=filtcolor, linewidth=3, title="Range Filter")

// Target

hbandplot = plot(hband, color=[Link], transp=100, title="High Target")


lbandplot = plot(lband, color=[Link], transp=100, title="Low Target")

// Fills

fill(hbandplot, filtplot, color=[Link], title="High Target Range")


fill(lbandplot, filtplot, color=[Link], title="Low Target Range")

// Bar Color

barcolor(barcolor)

// Break Outs

longCond = bool(na)
shortCond = bool(na)
longCond := src > filt and src > src[1] and upward > 0 or
src > filt and src < src[1] and upward > 0
shortCond := src < filt and src < src[1] and downward > 0 or
src < filt and src > src[1] and downward > 0

CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1

//Alerts

plotshape(longCondition, title="Buy Signal", text="BUY", textcolor=[Link],


style=[Link], size=[Link], location=[Link],
color=[Link], transp=0)
plotshape(shortCondition, title="Sell Signal", text="SELL", textcolor=[Link],
style=[Link], size=[Link], location=[Link],
color=[Link], transp=0)

alertcondition(longCondition, title="Buy Alert", message="BUY")


alertcondition(shortCondition, title="Sell Alert", message="SELL")

//For use like Strategy,

//1. Change the word "study" for "strategy" at the top


//2. Remove the "//" below

//[Link]( id = "Long", long = true, when = longCondition )


//[Link]( id = "Long", when = shortCondition )

You might also like