AMD Range 1h and 4h [Badr Edge]

kh_badrr · study · 77 行 · 点赞 9 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
// AMD Range 1h and 4h [Badr Edge] · v1.0.0
// Educational chart-marking tool. Markers show what happened on a bar. They are not trade signals.
indicator("AMD Range 1h and 4h [Badr Edge]", shorttitle = "BE AMD", overlay = true, max_labels_count = 200)
const color GOLD = #D9B46C
const color TEAL = #4FB8A0
const color ROSE = #E07A6C
const color GREY = #8F939B
const string G_R = "Range"
htf = input.timeframe("240", "Range candle", options = ["60", "240"], group = G_R, tooltip = "The high and low of the last completed 1-hour or 4-hour candle form the range. It is fixed for the whole of the next candle.")
const string G_V = "Visuals"
showMid   = input.bool(true, "Midline", group = G_V)
showSweep = input.bool(true, "Sweep labels", group = G_V, tooltip = "A small \"sweep\" label on the first candle that trades beyond the range high or low.")
showMarks = input.bool(true, "Reclaim markers", group = G_V, tooltip = "A small triangle when price has traded beyond one side of the range and a candle then closes back inside. A marker shows what happened. It is not a trade signal.")
const string G_Y = "Style"
colRange = 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 reclaim", 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() < timeframe.in_seconds(htf)
[pH, pL, hT] = request.security(syminfo.tickerid, htf, [high[1], low[1], time], lookahead = barmerge.lookahead_on)
newRange = hT != hT[1]
 
var bool sweptHi = false
var bool sweptLo = false
var bool upDone  = false
var bool dnDone  = false
bool up = false
bool dn = false
bool firstHi = false
bool firstLo = false
if newRange
    sweptHi := false
    sweptLo := false
    upDone  := false
    dnDone  := false
if tfOK and barstate.isconfirmed and not na(pH)
    if high > pH and not sweptHi
        sweptHi := true
        firstHi := true
    if low < pL and not sweptLo
        sweptLo := true
        firstLo := true
    dn := sweptHi and close < pH and close > pL and not dnDone
    up := sweptLo and close > pL and close < pH and not upDone
    if dn
        dnDone := true
    if up
        upDone := true
 
if showSweep and firstHi
    label.new(bar_index, high, "sweep", style = label.style_label_down, color = color.new(color.black, 100), textcolor = color.new(GREY, 10), size = size.tiny)
if showSweep and firstLo
    label.new(bar_index, low, "sweep", style = label.style_label_up, color = color.new(color.black, 100), textcolor = color.new(GREY, 10), size = size.tiny)
 
float rH = tfOK and not newRange ? pH : na
float rL = tfOK and not newRange ? pL : na
p1 = plot(rH, "Range high", color.new(colRange, 15), 1, plot.style_linebr)
p2 = plot(rL, "Range low", color.new(colRange, 15), 1, plot.style_linebr)
fill(p1, p2, color.new(colRange, 95), "Range")
plot(showMid ? (rH + rL) / 2 : na, "Range midline", color.new(colRange, 65), 1, plot.style_linebr)
plotshape(showMarks and up, "Reclaim after a sweep of the low", shape.triangleup, location.belowbar, color.new(TEAL, 0), size = size.tiny)
plotshape(showMarks and dn, "Reclaim after a sweep of the high", shape.triangledown, location.abovebar, color.new(ROSE, 0), size = size.tiny)
plot(firstHi ? 1 : firstLo ? -1 : 0, "First sweep of the range (1 high, -1 low)", display = display.data_window)
 
if useAlerts and up
    alert(syminfo.ticker + " swept the prior candle low " + str.tostring(pL, format.mintick) + " and closed back inside the range", alert.freq_once_per_bar_close)
if useAlerts and dn
    alert(syminfo.ticker + " swept the prior candle high " + str.tostring(pH, format.mintick) + " and closed back inside the range", 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, "Use a chart timeframe below the range candle.", text_color = GOLD, bgcolor = color.new(color.black, 20), text_size = size.small)

← 返回列表