OPEN-SOURCE SCRIPT
MAGIC TRADER RANGE BOX 2.0

//version=6
indicator("MAGIC TRADER RANGE BOX 2.0", overlay=false
// ===== PARAMÈTRES =====
rangeLen = input.int(20, "Longueur Range H1", minval=5)
atrLen = input.int(14, "ATR H1")
atrFactor = input.float(1.0, "Facteur ATR", step=0.1)
maLen = input.int(20, "MA H1")
slopeLimit = input.float(0.05, "Tolérance direction", step=0.01)
// 🎨 STYLE BOÎTE
boxColor = input.color(color.gray, "Couleur de la boîte")
opacity = input.int(85, "Opacité (0-100)", minval=0, maxval=100)
borderColor = input.color(color.gray, "Couleur du contour")
// ===== DONNÉES H1 =====
[h1High, h1Low, h1Close] = request.security(
syminfo.tickerid,
"60",
[high, low, close]
)
h1HH = request.security(syminfo.tickerid, "60", ta.highest(high, rangeLen))
h1LL = request.security(syminfo.tickerid, "60", ta.lowest(low, rangeLen))
h1ATR = request.security(syminfo.tickerid, "60", ta.atr(atrLen))
h1MA = request.security(syminfo.tickerid, "60", ta.sma(close, maLen))
h1Slope = math.abs(h1MA - h1MA[1])
// ===== CONDITIONS RANGE H1 =====
lowVol = (h1HH - h1LL) < h1ATR * atrFactor
noDir = h1Slope < slopeLimit
isH1Range = lowVol and noDir
// ===== BOÎTE =====
var box h1Box = na
if isH1Range and na(h1Box)
h1Box := box.new(
left = bar_index,
right = bar_index,
top = h1HH,
bottom = h1LL,
bgcolor = color.new(boxColor, opacity),
border_color = borderColor
)
if isH1Range and not na(h1Box)
box.set_right(h1Box, bar_index)
box.set_top(h1Box, h1HH)
box.set_bottom(h1Box, h1LL)
if not isH1Range and not na(h1Box)
h1Box := na
// ===== ALERTES =====
alertcondition(isH1Range,
title="Range H1 détecté",
message="📦 RANGE H1 détecté sur {{ticker}}")
alertcondition(close > h1HH,
title="Breakout H1 Haussier",
message="🚀 Breakout HAUSSIER du range H1 sur {{ticker}}")
alertcondition(close < h1LL,
title="Breakout H1 Baissier",
message="🔻 Breakout BAISSIER du range H1 sur {{ticker}}")
indicator("MAGIC TRADER RANGE BOX 2.0", overlay=false
// ===== PARAMÈTRES =====
rangeLen = input.int(20, "Longueur Range H1", minval=5)
atrLen = input.int(14, "ATR H1")
atrFactor = input.float(1.0, "Facteur ATR", step=0.1)
maLen = input.int(20, "MA H1")
slopeLimit = input.float(0.05, "Tolérance direction", step=0.01)
// 🎨 STYLE BOÎTE
boxColor = input.color(color.gray, "Couleur de la boîte")
opacity = input.int(85, "Opacité (0-100)", minval=0, maxval=100)
borderColor = input.color(color.gray, "Couleur du contour")
// ===== DONNÉES H1 =====
[h1High, h1Low, h1Close] = request.security(
syminfo.tickerid,
"60",
[high, low, close]
)
h1HH = request.security(syminfo.tickerid, "60", ta.highest(high, rangeLen))
h1LL = request.security(syminfo.tickerid, "60", ta.lowest(low, rangeLen))
h1ATR = request.security(syminfo.tickerid, "60", ta.atr(atrLen))
h1MA = request.security(syminfo.tickerid, "60", ta.sma(close, maLen))
h1Slope = math.abs(h1MA - h1MA[1])
// ===== CONDITIONS RANGE H1 =====
lowVol = (h1HH - h1LL) < h1ATR * atrFactor
noDir = h1Slope < slopeLimit
isH1Range = lowVol and noDir
// ===== BOÎTE =====
var box h1Box = na
if isH1Range and na(h1Box)
h1Box := box.new(
left = bar_index,
right = bar_index,
top = h1HH,
bottom = h1LL,
bgcolor = color.new(boxColor, opacity),
border_color = borderColor
)
if isH1Range and not na(h1Box)
box.set_right(h1Box, bar_index)
box.set_top(h1Box, h1HH)
box.set_bottom(h1Box, h1LL)
if not isH1Range and not na(h1Box)
h1Box := na
// ===== ALERTES =====
alertcondition(isH1Range,
title="Range H1 détecté",
message="📦 RANGE H1 détecté sur {{ticker}}")
alertcondition(close > h1HH,
title="Breakout H1 Haussier",
message="🚀 Breakout HAUSSIER du range H1 sur {{ticker}}")
alertcondition(close < h1LL,
title="Breakout H1 Baissier",
message="🔻 Breakout BAISSIER du range H1 sur {{ticker}}")
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.