/////////////////////////////////////////////////////// // // SaherElm IT Center ATR StopLoss Indicator // --------------------------------------------- // saherelm implementation of above indicator ... // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// // //@version=5 indicator(title="SaherElm Range Filter Buy Sell Indicator", shorttitle = "XS_RFBS_IND", overlay = true) // // START Inputs .... // // Source RFBSSrc = input.source(defval = close, title = "Source") // // Sampling Period RFBSPer = input.int(defval = 41, minval = 1, title = "Sampling Period") // // Range Multiplier ... RFBSMult = input.float(defval = 3.0, minval = 0.1, title = "Range Multiplier") // // END Inputs .... // // // START Functions .... // // Smooth Average Range smoothAverageRange(x, t, m) => wper = t * 2 - 1 avrng = ta.ema(math.abs(x - x[1]), t) result = ta.ema(avrng, wper) * m result // // Range Filter ... rangeFilter(x, r) => result = x result := x > nz(result[1]) ? x - r < nz(result[1]) ? nz(result[1]) : x - r : x + r > nz(result[1]) ? nz(result[1]) : x + r result // // END Functions .... // // // START Calculations .... // // // Color variables ... RFBSUpColor = color.green RFBSMidColor = color.blue RFBSDownColor = color.red // RFBSSmrng = smoothAverageRange(RFBSSrc, RFBSPer, RFBSMult) RFBSFilt = rangeFilter(RFBSSrc, RFBSSmrng) // // Filter UP Direction ... RFBSUpward = 0.0 RFBSUpward := RFBSFilt > RFBSFilt[1] ? nz(RFBSUpward[1]) + 1 : RFBSFilt < RFBSFilt[1] ? 0 : nz(RFBSUpward[1]) // // Filter DOWN Direction ... RFBSDownward = 0.0 RFBSDownward := RFBSFilt < RFBSFilt[1] ? nz(RFBSDownward[1]) + 1 : RFBSFilt > RFBSFilt[1] ? 0 : nz(RFBSDownward[1]) // // Target Bands RFBSHband = RFBSFilt + RFBSSmrng RFBSLband = RFBSFilt - RFBSSmrng // // Colors RFBSFiltcolor = RFBSUpward > 0 ? RFBSUpColor : RFBSDownward > 0 ? RFBSDownColor : RFBSMidColor RFBSBarcolor = RFBSSrc > RFBSFilt and RFBSSrc > RFBSSrc[1] and RFBSUpward > 0 ? RFBSUpColor : RFBSSrc > RFBSFilt and RFBSSrc < RFBSSrc[1] and RFBSUpward > 0 ? RFBSUpColor : RFBSSrc < RFBSFilt and RFBSSrc < RFBSSrc[1] and RFBSDownward > 0 ? RFBSDownColor : RFBSSrc < RFBSFilt and RFBSSrc > RFBSSrc[1] and RFBSDownward > 0 ? RFBSDownColor : RFBSMidColor // // Break Outs RFBSLongCond = bool(na) RFBSShortCond = bool(na) RFBSLongCond := RFBSSrc > RFBSFilt and RFBSSrc > RFBSSrc[1] and RFBSUpward > 0 or RFBSSrc > RFBSFilt and RFBSSrc < RFBSSrc[1] and RFBSUpward > 0 RFBSShortCond := RFBSSrc < RFBSFilt and RFBSSrc < RFBSSrc[1] and RFBSDownward > 0 or RFBSSrc < RFBSFilt and RFBSSrc > RFBSSrc[1] and RFBSDownward > 0 // RFBSCondIni = 0 RFBSCondIni := RFBSLongCond ? 1 : RFBSShortCond ? -1 : RFBSCondIni[1] RFBSLongCondition = RFBSLongCond and RFBSCondIni[1] == -1 RFBSShortCondition = RFBSShortCond and RFBSCondIni[1] == 1 // // END Calculations .... // // // START Plots .... // // Range Filter ... RFBSFiltPlot = plot(series = RFBSFilt, color = RFBSFiltcolor, linewidth = 2, title = "RFBS > Range Filter") // // Target ... RFBSHbandPlot = plot(series = RFBSHband, color = color.new(RFBSUpColor, 70), title = "RFBS > High Target") RFBSLbandPlot = plot(series = RFBSLband, color = color.new(RFBSDownColor, 70), title = "RFBS > Low Target") // // Fills fill(RFBSHbandPlot, RFBSFiltPlot, color = color.new(RFBSUpColor, 90), title = "RFBS > High Target Range") fill(RFBSLbandPlot, RFBSFiltPlot, color = color.new(RFBSDownColor, 90), title = "RFBS > Low Target Range") // // Bar Color barcolor(RFBSBarcolor) // // Plot Signal Labels ... plotshape(series = RFBSLongCondition, title = "RFBS > Buy Signal", text = "Buy", textcolor = color.white, style = shape.labelup, size = size.small, location = location.belowbar, color = color.new(RFBSUpColor, 20)) plotshape(series = RFBSShortCondition, title = "RFBS > Sell Signal", text = "Sell", textcolor = color.white, style = shape.labeldown, size = size.small, location = location.abovebar, color = color.new(RFBSDownColor, 20)) // // END Plots .... // // // START Alerts ... // // // END Alerts ... // ////////////////////////////////////////////////////// // TODOS: // ------- // - [] //////////////////////////////////////////////////////