Professional Documents
Culture Documents
script
script
script
0 at
https://mozilla.org/MPL/2.0/
//@version=4
study(title="Range Filter - B&S Signals", shorttitle="RF - B&S Signals",
overlay=true)
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Functions
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
hi_band = rng_filt1 + r
lo_band = rng_filt1 - r
rng_filt = rng_filt1
[hi_band, lo_band, rng_filt]
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Inputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Range Source
rng_src = input(defval=close, type=input.source, title="Swing Source")
//Range Period
rng_per = input(defval=20, minval=1, title="Swing Period")
//Bar Colors
use_barcolor = input(defval=false, type=input.bool, title="Bar Colors On/Off")
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Definitions
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Direction Conditions
var fdir = 0.0
fdir := filt > filt[1] ? 1 : filt < filt[1] ? -1 : fdir
upward = fdir==1 ? 1 : 0
downward = fdir==-1 ? 1 : 0
//Trading Condition
longCond = rng_src > filt and rng_src > rng_src[1] and upward > 0 or rng_src > filt
and rng_src < rng_src[1] and upward > 0
shortCond = rng_src < filt and rng_src < rng_src[1] and downward > 0 or rng_src <
filt and rng_src > rng_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
//Colors
filt_color = upward ? #05ff9b : downward ? #ff0583 : #cccccc
bar_color = upward and (rng_src > filt) ? (rng_src > rng_src[1] ? #05ff9b :
#00b36b) :
downward and (rng_src < filt) ? (rng_src < rng_src[1] ? #ff0583 :
#b8005d) : #cccccc
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Outputs
//---------------------------------------------------------------------------------
--------------------------------------------------------------------------------
//Filter Plot
filt_plot = plot(filt, color=filt_color, transp=67, linewidth=3, title="Filter")
//Band Plots
h_band_plot = plot(h_band, color=color.new(#05ff9b, 100), title="High Band")
l_band_plot = plot(l_band, color=color.new(#ff0583, 100), title="Low Band")
//Band Fills
fill(h_band_plot, filt_plot, color=color.new(#00b36b, 92), title="High Band Fill")
fill(l_band_plot, filt_plot, color=color.new(#b8005d, 92), title="Low Band Fill")
//Bar Color
barcolor(use_barcolor ? bar_color : na)
//Alerts
alertcondition(longCondition, title="Buy Alert", message = "BUY")
alertcondition(shortCondition, title="Sell Alert", message = "SELL")