OPEN-SOURCE SCRIPT
laurent

//version=5
indicator("Big Candle + Squeeze Dots (ATR + RSI + MACD + BB)", overlay=true, timeframe="", timeframe_gaps=true)
//---------------------------
// Inputs
//---------------------------
lenATR = input.int(14, "Période ATR")
multATR = input.float(2.5, "Grosse bougie : range > ATR * X", step=0.1)
lenBodyMA = input.int(20, "Période moyenne de corps")
useBodyMA = input.bool(true, "Filtrer par corps > moyenne")
// RSI / MACD
lenRSI = input.int(14, "Période RSI")
rsiOB = input.float(60, "RSI haussier min")
rsiOS = input.float(40, "RSI baissier max")
fastMACD = input.int(12, "MACD fast")
slowMACD = input.int(26, "MACD slow")
sigMACD = input.int(9, "MACD signal")
// Squeeze Bollinger
bbLen = input.int(20, "Période Bollinger")
bbMult = input.float(2.0, "Ecart-type Bollinger", step=0.1)
squeezeLen = input.int(20, "Période moyenne largeur BB")
squeezeMult = input.float(0.7, "Seuil squeeze (largeur BB < moyenne * X)", step=0.05)
// Filtres
requireMomentum = input.bool(true, "Exiger RSI + MACD")
requireSqueeze = input.bool(true, "Exiger un squeeze juste avant")
squeezeLookback = input.int(5, "Nb de bougies max depuis squeeze", minval=1, maxval=50)
//---------------------------
// Calculs de base
//---------------------------
atr = ta.atr(lenATR)
rangeC = high - low
body = math.abs(close - open)
// moyenne de corps
bodyMA = ta.sma(body, lenBodyMA)
// RSI
rsi = ta.rsi(close, lenRSI)
// MACD
macdVal = ta.ema(close, fastMACD) - ta.ema(close, slowMACD)
macdSig = ta.ema(macdVal, sigMACD)
macdHist = macdVal - macdSig
//---------------------------
// Bollinger Bands + Squeeze
//---------------------------
basis = ta.sma(close, bbLen)
dev = bbMult * ta.stdev(close, bbLen)
upper = basis + dev
lower = basis - dev
bbWidth = (upper - lower) / basis
bbWidthMA = ta.sma(bbWidth, squeezeLen)
// squeeze = largeur BB inférieure à une fraction de sa moyenne
isSqueeze = bbWidth < bbWidthMA * squeezeMult
// Nombre de barres depuis le dernier squeeze
barsSinceSqueeze = ta.barssince(isSqueeze)
// Condition : on considère qu'on sort d'une zone de squeeze récente
hadRecentSqueeze = barsSinceSqueeze >= 0 and barsSinceSqueeze <= squeezeLookback
//---------------------------
// Conditions Wide Range Candle
//---------------------------
// 1) Bougie large vs ATR
wideByATR = rangeC > atr * multATR
// 2) Bougie large vs moyenne de corps (optionnel)
wideByBody = useBodyMA ? body > bodyMA : true
wideCandle = wideByATR and wideByBody
//---------------------------
// Direction + momentum
//---------------------------
bullBody = close > open
bearBody = close < open
bullMomentum = (rsi > rsiOB) and (macdHist > 0)
bearMomentum = (rsi < rsiOS) and (macdHist < 0)
condMomentumBull = requireMomentum ? bullMomentum : true
condMomentumBear = requireMomentum ? bearMomentum : true
condSqueeze = requireSqueeze ? hadRecentSqueeze : true
bullCond = wideCandle and bullBody and condMomentumBull and condSqueeze
bearCond = wideCandle and bearBody and condMomentumBear and condSqueeze
//---------------------------
// Affichage des points discrets
//---------------------------
// Petit point vert sous la bougie = grosse bougie haussière
plotshape(bullCond, title="Big Bull Candle (Squeeze + Mom.)", style=shape.circle,
location=location.belowbar, color=color.new(color.lime, 0), size=size.tiny)
// Petit point rouge au-dessus de la bougie = grosse bougie baissière
plotshape(bearCond, title="Big Bear Candle (Squeeze + Mom.)", style=shape.circle,
location=location.abovebar, color=color.red, size=size.tiny)
indicator("Big Candle + Squeeze Dots (ATR + RSI + MACD + BB)", overlay=true, timeframe="", timeframe_gaps=true)
//---------------------------
// Inputs
//---------------------------
lenATR = input.int(14, "Période ATR")
multATR = input.float(2.5, "Grosse bougie : range > ATR * X", step=0.1)
lenBodyMA = input.int(20, "Période moyenne de corps")
useBodyMA = input.bool(true, "Filtrer par corps > moyenne")
// RSI / MACD
lenRSI = input.int(14, "Période RSI")
rsiOB = input.float(60, "RSI haussier min")
rsiOS = input.float(40, "RSI baissier max")
fastMACD = input.int(12, "MACD fast")
slowMACD = input.int(26, "MACD slow")
sigMACD = input.int(9, "MACD signal")
// Squeeze Bollinger
bbLen = input.int(20, "Période Bollinger")
bbMult = input.float(2.0, "Ecart-type Bollinger", step=0.1)
squeezeLen = input.int(20, "Période moyenne largeur BB")
squeezeMult = input.float(0.7, "Seuil squeeze (largeur BB < moyenne * X)", step=0.05)
// Filtres
requireMomentum = input.bool(true, "Exiger RSI + MACD")
requireSqueeze = input.bool(true, "Exiger un squeeze juste avant")
squeezeLookback = input.int(5, "Nb de bougies max depuis squeeze", minval=1, maxval=50)
//---------------------------
// Calculs de base
//---------------------------
atr = ta.atr(lenATR)
rangeC = high - low
body = math.abs(close - open)
// moyenne de corps
bodyMA = ta.sma(body, lenBodyMA)
// RSI
rsi = ta.rsi(close, lenRSI)
// MACD
macdVal = ta.ema(close, fastMACD) - ta.ema(close, slowMACD)
macdSig = ta.ema(macdVal, sigMACD)
macdHist = macdVal - macdSig
//---------------------------
// Bollinger Bands + Squeeze
//---------------------------
basis = ta.sma(close, bbLen)
dev = bbMult * ta.stdev(close, bbLen)
upper = basis + dev
lower = basis - dev
bbWidth = (upper - lower) / basis
bbWidthMA = ta.sma(bbWidth, squeezeLen)
// squeeze = largeur BB inférieure à une fraction de sa moyenne
isSqueeze = bbWidth < bbWidthMA * squeezeMult
// Nombre de barres depuis le dernier squeeze
barsSinceSqueeze = ta.barssince(isSqueeze)
// Condition : on considère qu'on sort d'une zone de squeeze récente
hadRecentSqueeze = barsSinceSqueeze >= 0 and barsSinceSqueeze <= squeezeLookback
//---------------------------
// Conditions Wide Range Candle
//---------------------------
// 1) Bougie large vs ATR
wideByATR = rangeC > atr * multATR
// 2) Bougie large vs moyenne de corps (optionnel)
wideByBody = useBodyMA ? body > bodyMA : true
wideCandle = wideByATR and wideByBody
//---------------------------
// Direction + momentum
//---------------------------
bullBody = close > open
bearBody = close < open
bullMomentum = (rsi > rsiOB) and (macdHist > 0)
bearMomentum = (rsi < rsiOS) and (macdHist < 0)
condMomentumBull = requireMomentum ? bullMomentum : true
condMomentumBear = requireMomentum ? bearMomentum : true
condSqueeze = requireSqueeze ? hadRecentSqueeze : true
bullCond = wideCandle and bullBody and condMomentumBull and condSqueeze
bearCond = wideCandle and bearBody and condMomentumBear and condSqueeze
//---------------------------
// Affichage des points discrets
//---------------------------
// Petit point vert sous la bougie = grosse bougie haussière
plotshape(bullCond, title="Big Bull Candle (Squeeze + Mom.)", style=shape.circle,
location=location.belowbar, color=color.new(color.lime, 0), size=size.tiny)
// Petit point rouge au-dessus de la bougie = grosse bougie baissière
plotshape(bearCond, title="Big Bear Candle (Squeeze + Mom.)", style=shape.circle,
location=location.abovebar, color=color.red, size=size.tiny)
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.