本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// Asian Range Breakout [Badr Edge] · v1.0.0
// Educational chart-marking tool. Markers show what happened on a bar. They are not trade signals.
indicator("Asian Range Breakout [Badr Edge]", shorttitle = "BE Asia Range", overlay = true, max_boxes_count = 100, max_lines_count = 400, max_labels_count = 100)
const color GOLD = #D9B46C
const color TEAL = #4FB8A0
const color ROSE = #E07A6C
const color GREY = #8F939B
const string TZ = "America/New_York"
const string G_R = "Windows (New York time, daylight saving handled)"
rangeSess = input.session("1800-0200", "Asian range", group = G_R, tooltip = "The range is built from every bar inside this window.")
watchSess = input.session("0200-1200", "Breakout window", group = G_R, tooltip = "Range levels are extended and breakouts are marked only inside this window. The default covers London and the New York morning.")
const string G_V = "Visuals"
showMid = input.bool(true, "Midline", group = G_V)
showProj = input.bool(false, "1x range projections", group = G_V, tooltip = "Dotted lines one range width above the high and below the low. A measuring aid only.")
showMarks = input.bool(true, "Breakout markers", group = G_V, tooltip = "A small triangle on the first candle that closes outside the Asian range. A marker shows what happened. It is not a trade signal.")
oneSide = input.bool(true, "First breakout of the day only", group = G_V, tooltip = "Off: the first close above and the first close below are both marked.")
showWidth = input.bool(true, "Range width on the box", group = G_V)
const string G_Y = "Style"
colBox = input.color(GOLD, "Range", group = G_Y)
showWm = input.bool(true, "Watermark", group = G_Y)
const string G_A = "Alerts"
useAlerts = input.bool(true, "Alert on a close outside the Asian range", group = G_A, tooltip = "Create the alert with \"Any alert() function call\". Fires once, after the bar closes.")
tfOK = timeframe.isintraday and timeframe.in_seconds() <= 3600
inR = tfOK and not na(time(timeframe.period, rangeSess, TZ))
inW = tfOK and not na(time(timeframe.period, watchSess, TZ)) and not inR
var float hi = na
var float lo = na
var bool ready = false
var bool upDone = false
var bool dnDone = false
var box bx = na
var line lh = na
var line ll = na
var line lm = na
var line pu = na
var line pd = na
bool up = false
bool dn = false
if inR and not inR[1]
hi := high
lo := low
ready := false
upDone := false
dnDone := false
bx := box.new(bar_index, hi, bar_index, lo, border_color = color.new(colBox, 50), border_width = 1, bgcolor = color.new(colBox, 92), text = "ASIA", text_size = size.tiny, text_color = color.new(colBox, 25), text_halign = text.align_left, text_valign = text.align_top)
else if inR
hi := math.max(hi, high)
lo := math.min(lo, low)
bx.set_top(hi)
bx.set_bottom(lo)
bx.set_right(bar_index)
if not inR and inR[1] and not na(hi)
ready := true
float w = hi - lo
if showWidth
bx.set_text("ASIA " + str.tostring(w, format.mintick))
lh := line.new(bar_index - 1, hi, bar_index, hi, color = color.new(colBox, 15), width = 1)
ll := line.new(bar_index - 1, lo, bar_index, lo, color = color.new(colBox, 15), width = 1)
if showMid
lm := line.new(bar_index - 1, (hi + lo) / 2, bar_index, (hi + lo) / 2, color = color.new(colBox, 55), width = 1, style = line.style_dotted)
if showProj
pu := line.new(bar_index - 1, hi + w, bar_index, hi + w, color = color.new(GREY, 45), width = 1, style = line.style_dotted)
pd := line.new(bar_index - 1, lo - w, bar_index, lo - w, color = color.new(GREY, 45), width = 1, style = line.style_dotted)
if ready and inW
lh.set_x2(bar_index)
ll.set_x2(bar_index)
if showMid
lm.set_x2(bar_index)
if showProj
pu.set_x2(bar_index)
pd.set_x2(bar_index)
if barstate.isconfirmed
bool free = oneSide ? not upDone and not dnDone : true
up := close > hi and not upDone and free
dn := close < lo and not dnDone and free
if up
upDone := true
if dn
dnDone := true
plotshape(showMarks and up, "Close above Asian range", shape.triangleup, location.belowbar, color.new(TEAL, 0), size = size.tiny)
plotshape(showMarks and dn, "Close below Asian range", shape.triangledown, location.abovebar, color.new(ROSE, 0), size = size.tiny)
plot(inR or (ready and inW) ? hi : na, "Asian range high", display = display.data_window)
plot(inR or (ready and inW) ? lo : na, "Asian range low", display = display.data_window)
plot(inR ? 1 : 0, "In Asian range window", display = display.data_window)
if useAlerts and up
alert(syminfo.ticker + " closed above the Asian range high " + str.tostring(hi, format.mintick), alert.freq_once_per_bar_close)
if useAlerts and dn
alert(syminfo.ticker + " closed below the Asian range low " + str.tostring(lo, format.mintick), alert.freq_once_per_bar_close)
var table wm = table.new(position.bottom_right, 1, 1)
if barstate.islast and showWm
wm.cell(0, 0, "BADR EDGE", text_color = color.new(GREY, 72), text_size = size.small)
var table note = table.new(position.top_right, 1, 1)
if barstate.islast and not tfOK
note.cell(0, 0, "Asian Range Breakout works on 1m to 1h charts.", text_color = GOLD, bgcolor = color.new(color.black, 20), text_size = size.small)