---Reversal Finder--- //@version=4 study("Reversal finder", overlay=true) // Inputs lookback = input(20, "Lookback period for highs and lows") malen = input(20, "SMA length for candles range") avrange = sma((high-low), malen) mult = input(1.5, "Range multiple", type=input.float) rangethreshold = input(50, "Range threshold (% of candle range)", maxval=99)/100 barcol = input(false, "Highlight signal bars?", type=input.bool) trackhilo = input(false, "Highlight highest high/lowest low?", type=input.bool) // Signal conditions longsig = (high-low)>=(avrange*mult) and ((low=(high-((high-low)*rangethreshold))) shortsig = (high-low)>=(avrange*mult) and ((high>highest(high[1], lookback))) and (close<=(low+((high-low)*rangethreshold))) // Plots for highest recent high/lowest recent low hiplot = trackhilo ? highest(high[1], lookback) : na loplot = trackhilo ? lowest(low[1],lookback) : na plot(loplot, title="Lowest low", color=#FF0000, transp=99, trackprice=true) plot(hiplot, title="Highest high", color=#00FF03, transp=99, trackprice=true) // Plots for signal occurrences plotshape(longsig, title="Long signal", style=shape.labelup, color=color.yellow, transp=1, location=location.belowbar, size=size.tiny) plotshape(shortsig, title="Short signal", style=shape.labeldown, color=color.yellow, transp=1, location=location.abovebar, size=size.tiny) plotshape((longsig and close>open), title="Long signal with up candle", style=shape.labelup, color=#00FF03, transp=1, location=location.belowbar, size=size.tiny) plotshape((shortsig and closeopen), title="Long signal with up candle", message="Reversal finder long signal with up candle") alertcondition((shortsig and close if smoothing == "RMA" rma(source, length) else if smoothing == "SMA" sma(source, length) else if smoothing == "EMA" ema(source, length) else wma(source, length) a = ma_function(tr(true), length) * m x = ma_function(tr(true), length) * m + src1 x2 = src2 - ma_function(tr(true), length) * m p1 = plot(x, title = "ATR Short Stop Loss", color= colshort, transp=20, trackprice = pline ? true : false) p2 = plot(x2, title = "ATR Long Stop Loss", color= collong, transp=20, trackprice = pline ? true : false) var table Table = table.new(position.bottom_center, 3, 1, border_width = 3) f_fillCell(_table, _column, _row, _value, _timeframe) => _cellText = _timeframe+ tostring(_value, "#.#") table.cell(_table, _column, _row, _cellText, text_color = col1) table.cell_set_text_color(Table, 1, 0, color.new(col3, transp = 0)) table.cell_set_text_color(Table, 2, 0, color.new(col2, transp = 0)) if barstate.islast f_fillCell(Table, 0, 0, a, "ATR: " ) f_fillCell(Table, 1, 0, x, "H: " ) f_fillCell(Table, 2, 0, x2, "L: " )