15-Min ORB Indicator with Breakout Targets

JWinters318 · study · 131 行 · 点赞 611 · TradingView 原页

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

Pine Script

//@version=6
indicator(title="15-Min ORB Indicator with Breakout Targets", shorttitle="15-Min ORB", overlay=true)
 
// === Inputs ===
enable15Min    = input.bool(true,  "Display 15-Minute Range", group="15-Minute Range")
label15Min     = input.bool(true,  "Show 15-Minute Labels",   group="15-Minute Range")
sessStartHour  = input.int(9,      "Range Start Hour",         minval=0, maxval=23, group="15-Minute Range")
sessStartMin   = input.int(30,     "Range Start Minute",       minval=0, maxval=59, group="15-Minute Range")
rangeColor     = input.color(color.purple, "15-Minute Range Color",  group="15-Minute Range")
rangeStyleOpt  = input.string("Solid","15-Minute Range Style", options=["Solid","Dashed","Dotted"], group="15-Minute Range")
rangeStyle     = rangeStyleOpt == "Dashed" ? line.style_dashed : (rangeStyleOpt == "Dotted" ? line.style_dotted : line.style_solid)
 
// TP expansion multiples
r1             = input.float(1.0,  "TP1 Expansion-Multiple", step=0.25, group="Targets")
r2             = input.float(2.0,  "TP2 Expansion-Multiple", step=0.25, group="Targets")
enableTP1Line  = input.bool(true,  "Show TP1 Level",          group="Targets")
enableTP2Line  = input.bool(true,  "Show TP2 Level",          group="Targets")
enableTP1Label = input.bool(true,  "Show TP1 Label",          group="Targets")
enableTP2Label = input.bool(true,  "Show TP2 Label",          group="Targets")
labelColorTP   = input.color(color.green, "TP Label Color",        group="Targets")
TPStyleOpt  = input.string("Solid","TP Style", options=["Solid","Dashed","Dotted"], group="")
TPStyle     = rangeStyleOpt == "Dashed" ? line.style_dashed : (rangeStyleOpt == "Dotted" ? line.style_dotted : line.style_solid)
 
 
// Label Horizontal Position
dlabelPos      = input.string("Right", "Labels Position", options=["Left","Right"], group="Labels")
labelXCoord    = dlabelPos == "Left" ? bar_index[2] : bar_index
 
// === State Variables ===
var float h15       = na
var float l15       = na
var line  lHigh     = na
var line  lLow      = na
var line  lTP1      = na
var line  lTP2      = na
var label lblHigh   = na
var label lblLow    = na
var label lblTP1    = na
var label lblTP2    = na
var bool  longTrig  = false
var bool  shortTrig = false
var float entryP    = na
var float distOut   = na
var float tp1       = na
var float tp2       = na
 
// === 15-Minute Range Calculation ===
inRange = hour == sessStartHour and minute >= sessStartMin and minute < sessStartMin + 15
if inRange and enable15Min
    h15 := na(h15) ? high : math.max(h15, high)
    l15 := na(l15) ? low  : math.min(l15, low)
    // delete previous range drawings
    line.delete(lHigh)
    line.delete(lLow)
    label.delete(lblHigh)
    label.delete(lblLow)
    // draw range high/low
    lHigh := line.new(bar_index[2], h15, bar_index,    h15, color=rangeColor, width=2, style=rangeStyle, extend=extend.right)
    lLow  := line.new(bar_index[2], l15, bar_index,    l15, color=rangeColor, width=2, style=rangeStyle, extend=extend.right)
    if label15Min
        lblHigh := label.new(labelXCoord, h15, text="15m High: " + str.tostring(h15, format.mintick), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_down, color=rangeColor, textcolor=color.white)
        lblLow  := label.new(labelXCoord, l15, text="15m Low:  " + str.tostring(l15, format.mintick), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_up,   color=rangeColor, textcolor=color.white)
 
// === Reset at Midnight ===
if hour == 0 and minute == 0
    h15 := na
    l15 := na
    longTrig  := false
    shortTrig := false
    // delete all drawings
    line.delete(lHigh)
    line.delete(lLow)
    line.delete(lTP1)
    line.delete(lTP2)
    label.delete(lblHigh)
    label.delete(lblLow)
    label.delete(lblTP1)
    label.delete(lblTP2)
 
// === Breakout Conditions ===
longBrk  = not longTrig  and close > h15
shortBrk = not shortTrig and close < l15
 
// === Entry & TP Plotting ===
if longBrk
    longTrig := true
    entryP   := close
    distOut  := entryP - l15
    tp1      := entryP + r1 * distOut
    tp2      := entryP + r2 * distOut
    // clear previous targets
    line.delete(lTP1)
    line.delete(lTP2)
    label.delete(lblTP1)
    label.delete(lblTP2)
    // draw TP1 & TP2 lines
    if enableTP1Line
        lTP1 := line.new(bar_index, tp1, bar_index + 1, tp1, color=color.green, style=line.style_solid, width=2, extend=extend.right)
    if enableTP2Line
        lTP2 := line.new(bar_index, tp2, bar_index + 1, tp2, color=color.green, style=line.style_solid, width=2, extend=extend.right)
    // draw TP labels
    if enableTP1Label and enableTP1Line
        lblTP1 := label.new(labelXCoord, tp1, text="TP1: " + str.tostring(tp1, format.mintick), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_down, color=labelColorTP, textcolor=color.white)
    if enableTP2Label and enableTP2Line
        lblTP2 := label.new(labelXCoord, tp2, text="TP2: " + str.tostring(tp2, format.mintick), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_down, color=labelColorTP, textcolor=color.white)
 
if shortBrk
    shortTrig := true
    entryP   := close
    distOut  := h15 - entryP
    tp1      := entryP - r1 * distOut
    tp2      := entryP - r2 * distOut
    // clear previous targets
    line.delete(lTP1)
    line.delete(lTP2)
    label.delete(lblTP1)
    label.delete(lblTP2)
    // draw TP1 & TP2 lines
    if enableTP1Line
        lTP1 := line.new(bar_index, tp1, bar_index + 1, tp1, color=color.green, style=line.style_solid, width=2, extend=extend.right)
    if enableTP2Line
        lTP2 := line.new(bar_index, tp2, bar_index + 1, tp2, color=color.green, style=line.style_solid, width=2, extend=extend.right)
    // draw TP labels
    if enableTP1Label and enableTP1Line
        lblTP1 := label.new(labelXCoord, tp1, text="TP1: " + str.tostring(tp1, format.mintick), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_up, color=labelColorTP, textcolor=color.white)
    if enableTP2Label and enableTP2Line
        lblTP2 := label.new(labelXCoord, tp2, text="TP2: " + str.tostring(tp2, format.mintick), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_up, color=labelColorTP, textcolor=color.white)
 
// === Alerts ===
alertcondition(ta.cross(close, h15) and close > h15, title="Closed Above 15m High", message="Price closed above 15-Minute High")
alertcondition(ta.cross(close, l15) and close < l15, title="Closed Below 15m Low",  message="Price closed below 15-Minute Low")

← 返回列表