本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ICT Multi-Strat — RDRB (Redelivered Rebalanced) Gris étendu jusqu'au contact d'une bougie
//@version=6
indicator("ICT RDRB (Redelivered Rebalanced)", shorttitle="RDRB", overlay=true, max_boxes_count=500, max_lines_count=500)
// ============================================================================
// 1. PARAMETRES
// ============================================================================
grpVis = "Apparence RDRB (Gris en évidence)"
i_showBull = input.bool(true, "Afficher RDRB Haussier (Bullish)", group=grpVis)
i_showBear = input.bool(true, "Afficher RDRB Baissier (Bearish)", group=grpVis)
i_colBg = input.color(color.new(#9ca3af, 70), "Couleur fond RDRB (Gris)", group=grpVis)
i_colBorder = input.color(color.new(#d1d5db, 15), "Couleur bordure RDRB", group=grpVis)
i_borderW = input.int(1, "Épaisseur bordure", minval=0, maxval=4, group=grpVis)
i_showMid = input.bool(true, "Afficher ligne médiane (50%)", group=grpVis)
i_colMid = input.color(color.new(#e5e7eb, 35), "Couleur ligne médiane", group=grpVis)
grpDet = "Détection & Extension"
i_useMinW = input.bool(false, "Hauteur minimale RDRB", inline="minw", group=grpDet)
i_minW = input.float(0.0, "", inline="minw", group=grpDet)
i_minWMethod = input.string("Points", "", options=["Points", "%", "ATR"], inline="minw", group=grpDet)
i_keepHist = input.bool(true, "Garder les RDRB arrêtés au point de contact", group=grpDet)
i_maxDone = input.int(200, "Max anciens RDRB gardés", minval=20, maxval=350, group=grpDet)
i_maxActive = input.int(120, "Max RDRB actifs simultanés", minval=10, maxval=250, group=grpDet)
// ============================================================================
// 2. DETECTION RDRB (REDELIVERED REBALANCED)
// ============================================================================
float atr200 = ta.atr(200)
f_widthOk(float _top, float _bot) =>
if not i_useMinW
true
else
float _dist = _top - _bot
i_minWMethod == "Points" ? _dist > i_minW : i_minWMethod == "%" ? (_bot != 0 ? _dist / _bot * 100.0 > i_minW : false) : _dist > atr200 * i_minW
// Bullish RDRB :
// - Les 3 bougies [2], [1], [0] sont haussieres (close > open) et progression (close[1] > close[2])
// - Zero FVG / imbalance : high[2] >= low[0]
// - La meche haute de [2] remplit le corps de [1] a 100% : high[2] >= close[1]
// - Zone = [close[2], low[0]] (gauche uniquement dans la meche de [2], droite zero meche de [0] dedans)
bool bullAllUp = bar_index >= 2 and close[2] > open[2] and close[1] > open[1] and close[0] > open[0]
bool bullRdrb = i_showBull and bullAllUp and close[1] > close[2] and high[2] >= close[1] and high[2] >= low[0] and low[0] > close[2] and f_widthOk(low[0], close[2])
// Bearish RDRB :
// - Les 3 bougies [2], [1], [0] sont baissieres (close < open) et progression (close[1] < close[2])
// - Zero FVG / imbalance : low[2] <= high[0]
// - La meche basse de [2] remplit le corps de [1] a 100% : low[2] <= close[1]
// - Zone = [high[0], close[2]] (gauche uniquement dans la meche de [2], droite zero meche de [0] dedans)
bool bearAllDn = bar_index >= 2 and close[2] < open[2] and close[1] < open[1] and close[0] < open[0]
bool bearRdrb = i_showBear and bearAllDn and close[1] < close[2] and low[2] <= close[1] and low[2] <= high[0] and high[0] < close[2] and f_widthOk(close[2], high[0])
// ============================================================================
// 3. STOCKAGE & EXTENSION JUSQU'AU CONTACT D'UNE BOUGIE
// ============================================================================
var array<box> actBoxes = array.new<box>(0)
var array<line> actMids = array.new<line>(0)
var array<float> actTops = array.new<float>(0)
var array<float> actBots = array.new<float>(0)
var array<bool> actIsBull = array.new<bool>(0)
var array<int> actBirth = array.new<int>(0)
var array<box> doneBoxes = array.new<box>(0)
var array<line> doneMids = array.new<line>(0)
f_archiveRdrb(box _b, line _m) =>
if i_keepHist
array.push(doneBoxes, _b)
array.push(doneMids, _m)
if array.size(doneBoxes) > i_maxDone
box.delete(array.shift(doneBoxes))
line.delete(array.shift(doneMids))
else
box.delete(_b)
line.delete(_m)
f_addRdrb(float _top, float _bot, bool _isBull) =>
if barstate.isconfirmed and not na(_top) and not na(_bot) and _top > _bot
int _x1 = math.max(0, bar_index - 2)
int _x2 = bar_index
box _b = box.new(left=_x1, top=_top, right=_x2, bottom=_bot, xloc=xloc.bar_index, border_color=i_colBorder, border_width=i_borderW, bgcolor=i_colBg)
float _midY = math.avg(_top, _bot)
line _m = i_showMid ? line.new(x1=_x1, y1=_midY, x2=_x2, y2=_midY, xloc=xloc.bar_index, color=i_colMid, style=line.style_dotted, width=1) : line(na)
array.push(actBoxes, _b)
array.push(actMids, _m)
array.push(actTops, _top)
array.push(actBots, _bot)
array.push(actIsBull, _isBull)
array.push(actBirth, bar_index)
if array.size(actBoxes) > i_maxActive
box.delete(array.shift(actBoxes))
line.delete(array.shift(actMids))
array.shift(actTops)
array.shift(actBots)
array.shift(actIsBull)
array.shift(actBirth)
if bullRdrb
f_addRdrb(low[0], close[2], true)
if bearRdrb
f_addRdrb(close[2], high[0], false)
// ============================================================================
// 4. MISE A JOUR : ETENDRE A DROITE TANT QUE NON TOUCHE, ARRETER AU CONTACT
// ============================================================================
int nAct = array.size(actBoxes)
if nAct > 0
for i = nAct - 1 to 0
box _b = array.get(actBoxes, i)
line _m = array.get(actMids, i)
float _top = array.get(actTops, i)
float _bot = array.get(actBots, i)
bool _isBull = array.get(actIsBull, i)
int _birth = array.get(actBirth, i)
bool _tapped = bar_index > _birth and (_isBull ? low <= _top : high >= _bot)
if _tapped
box.set_right(_b, bar_index - 1)
if not na(_m)
line.set_x2(_m, bar_index - 1)
array.remove(actBoxes, i)
array.remove(actMids, i)
array.remove(actTops, i)
array.remove(actBots, i)
array.remove(actIsBull, i)
array.remove(actBirth, i)
f_archiveRdrb(_b, _m)
else
box.set_right(_b, bar_index)
if not na(_m)
line.set_x2(_m, bar_index)