//@version=5 strategy("Sneaky Pivot Reversal Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, currency=currency.USD) // Inputs threshold_pct = input.float(0.15, title="Level Touch Threshold (%)", minval=0.0, step=0.05) / 100 lookback_days = input.int(5, title="Swing High/Low Lookback (Days)", minval=2, maxval=10) // Daily levels prev_high = request.security(syminfo.tickerid, "D", high[1], barmerge.gaps_off, barmerge.lookahead_off) prev_low = request.security(syminfo.tickerid, "D", low[1], barmerge.gaps_off, barmerge.lookahead_off) highest_lookback = request.security(syminfo.tickerid, "D", ta.highest(high, lookback_days)[2], barmerge.gaps_off, barmerge.lookahead_off) lowest_lookback = request.security(syminfo.tickerid, "D", ta.lowest(low, lookback_days)[2], barmerge.gaps_off, barmerge.lookahead_off) // Swing levels swing_high = highest_lookback > prev_high ? highest_lookback : prev_high * 1.01 swing_low = lowest_lookback < prev_low ? lowest_lookback : prev_low * 0.99 // Plot levels plot(prev_high, title="Range High (PDH)", color=color.red, linewidth=1) plot(prev_low, title="Range Low (PDL)", color=color.green, linewidth=1) plot(swing_high, title="Swing High", color=color.maroon, linewidth=1) plot(swing_low, title="Swing Low", color=color.navy, linewidth=1) // Support function near_support(val) => support1 = val <= prev_low * (1 + threshold_pct) and val >= prev_low * (1 - threshold_pct) support2 = val <= swing_low * (1 + threshold_pct) and val >= swing_low * (1 - threshold_pct) support1 or support2 // Resistance function near_resistance(val) => resistance1 = val <= prev_high * (1 + threshold_pct) and val >= prev_high * (1 - threshold_pct) resistance2 = val <= swing_high * (1 + threshold_pct) and val >= swing_high * (1 - threshold_pct) resistance1 or resistance2 // Candle 1 - Test candle c1_low_test = near_support(low[2]) c1_high_test = near_resistance(high[2]) // Candle 2 - Rejection candle c2_bullish = close[1] > open[1] and low[1] >= low[2] c2_bearish = close[1] < open[1] and high[1] <= high[2] // Candle 3 - Trigger candle long_trigger = ta.crossover(high, high[1]) short_trigger = ta.crossunder(low, low[1]) // Trade variables var float long_sl = na var float long_tp = na var float short_sl = na var float short_tp = na // Long entry long_condition = c1_low_test and c2_bullish and long_trigger and strategy.position_size == 0 if long_condition long_sl := math.min(low[1], low[2]) long_tp := prev_high strategy.entry("Sneaky Long", strategy.long) // Long exit if strategy.position_size > 0 strategy.exit("Exit Long", "Sneaky Long", stop=long_sl, limit=long_tp) // Short entry short_condition = c1_high_test and c2_bearish and short_trigger and strategy.position_size == 0 if short_condition short_sl := math.max(high[1], high[2]) short_tp := prev_low strategy.entry("Sneaky Short", strategy.short) // Short exit if strategy.position_size < 0 strategy.exit("Exit Short", "Sneaky Short", stop=short_sl, limit=short_tp) // Plot trade levels plot(strategy.position_size > 0 ? long_sl : na, title="Long SL", color=color.red, style=plot.style_circles) plot(strategy.position_size > 0 ? long_tp : na, title="Long TP", color=color.green, style=plot.style_circles) plot(strategy.position_size < 0 ? short_sl : na, title="Short SL", color=color.red, style=plot.style_circles) plot(strategy.position_size < 0 ? short_tp : na, title="Short TP", color=color.green, style=plot.style_circles)