OPEN-SOURCE SCRIPT

Small Caps - Range + Breakout (dernier seulement)

145
//version=5
indicator("Small Caps - Range + Breakout (dernier seulement)", overlay=true)

// -------------------
// Paramètres
// -------------------
lookback = input.int(50, "Période max du range (jours)")
minConsol = input.int(20, "Consolidation minimale (jours)")
volLen = input.int(20, "Période moyenne volume")
volMult = input.float(1.5, "Volume minimum (x moyenne)")
useRSI = input.bool(true, "Filtrer avec RSI > 55 ?")
rsiLength = input.int(14, "RSI période")

// -------------------
// Détection du Range
// -------------------
rangeHigh = ta.highest(high[1], lookback)
rangeLow = ta.lowest(low[1], lookback)

// Vérifier consolidation minimale
consolHigh = ta.highest(high[1], minConsol)
consolLow = ta.lowest(low[1], minConsol)
consolOk = (consolHigh <= rangeHigh) and (consolLow >= rangeLow)

// -------------------
// Conditions breakout
// -------------------
volMa = ta.sma(volume, volLen)
volOk = volume > volMult * volMa
rsi = ta.rsi(close, rsiLength)
rsiOk = useRSI ? rsi > 55 : true

breakoutUp = close > rangeHigh and volOk and rsiOk and consolOk
breakoutDown = close < rangeLow and volOk and rsiOk and consolOk

// -------------------
// Rectangle unique
// -------------------
var box rangeBox = na

if barstate.islast
if not na(rangeBox)
box.delete(rangeBox)

// Couleur par défaut (range gris)
rectColor = color.new(color.gray, 85)
borderCol = color.new(color.gray, 0)

// Modifier couleur si cassure
if breakoutUp
rectColor := color.new(color.green, 85)
borderCol := color.new(color.green, 0)
if breakoutDown
rectColor := color.new(color.red, 85)
borderCol := color.new(color.red, 0)

// Créer rectangle du range courant sur une seule ligne
rangeBox := box.new(left=bar_index - lookback, top=rangeHigh, right=bar_index, bottom=rangeLow, border_color=borderCol, border_width=1, bgcolor=rectColor)

// -------------------
// Flèches breakout
// -------------------
plotshape(breakoutUp, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.tiny)
plotshape(breakoutDown, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.tiny)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.