本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=5
indicator("ORB Indicator", overlay = true)
inputMax = timeframe.multiplier
sess = input.session("0915-0920", title="ORB Session Time", group = "Indicator")
t = time(timeframe.period, sess + ":1234567")
conf = input.string("CLOSE", "Signal Configure", ["CLOSE", "TOUCH"], group = "Indicator")
longTrailPerc = input.float(title = "ATR (%)", defval = 0.38, step = 0.1, inline = '1', group = "Indicator") * 0.01
enable3 = input.bool(true, "", inline = '1', group = "Indicator")
// rsi_len = input.int(14, title = "RSI Length", group = "Indicator")
// y_coordinate = input.string(defval="Top", title="Table Position", options=["Top", "Middle", "Bottom"], inline = 'pos', group = "Indicator")
// x_coordinate = input.string(defval="Right", title="", options=["Left", "Center", "Right"], inline = 'pos', group = "Indicator")
// size_option = input.string(defval="Tiny", title="Select Size", options=["Auto", "Huge", "Large", "Normal", "Small", "Tiny"], group = "Indicator")
// size = size_option == "Auto" ? size.auto : size_option == "Huge" ? size.huge : size_option == "Large" ? size.large : size_option == " Normal" ? size.normal : size_option == "Small" ? size.small : size_option == "Tiny" ? size.tiny : size.auto
hide = timeframe.isintraday and timeframe.multiplier <= inputMax
is_newbar(res) => ta.change(time(res)) != 0
in_session = not na(t)
is_first = in_session and not in_session[1]
orb_high = float(na)
orb_low = float(na)
if is_first
orb_high := high
orb_low := low
else
orb_high := orb_high[1]
orb_low := orb_low[1]
if high > orb_high and in_session
orb_high := high
if low < orb_low and in_session
orb_low := low
plot(hide and not in_session ? orb_high : na , style=plot.style_circles, color=orb_high[1] != orb_high ? na : color.green, title="ORB High", linewidth=1)
plot(hide and not in_session ? orb_low : na , style=plot.style_circles, color=orb_low[1] != orb_low ? na : color.red, title="ORB Low", linewidth=1)
crossOver = ta.crossover(conf == "CLOSE" ? close : high, orb_high)
crossUnder = ta.crossunder(conf == "CLOSE" ? close : low, orb_low)
var bflag = false
var sflag = false
var new_flag = false
var long1_bo = false
var short1_bo = false
if dayofmonth[1] != dayofmonth
bflag := true
sflag := true
new_flag := false
long1_bo := false
short1_bo := false
if is_first
new_flag := true
plotshape(crossOver and bflag and new_flag, "B", shape.labelup, location.belowbar, color.green, size = size.tiny, text = "B", textcolor = color.white)
if crossOver and bflag and new_flag
// label.new(bar_index, low - (close * 0.001), "", color = color.green, textcolor = color.white, size = size.large, style = label.style_arrowup)
bflag := false
long1_bo := true
short1_bo := false
plotshape(crossUnder and sflag and new_flag, "S", shape.labeldown, location.abovebar, color.red, size = size.tiny, text = 'S', textcolor = color.white)
if crossUnder and sflag and new_flag
// label.new(bar_index, high + (close * 0.001), "", color = color.red, textcolor = color.white, size = size.large, style = label.style_arrowdown)
sflag := false
long1_bo := false
short1_bo := true
shortTrailPerc = longTrailPerc
longStopPrice = 0.0, shortStopPrice = 0.0
longStopPrice := if (long1_bo)
stopValue = close[1] * (1 - longTrailPerc)
math.max(stopValue, longStopPrice[1])
else
0
shortStopPrice := if (short1_bo)
stopValue = close[1] * (1 + shortTrailPerc)
math.min(stopValue, shortStopPrice[1])
else
999999
plot(long1_bo and enable3 ? longStopPrice : na, color = color.green, style = plot.style_linebr)
plot(short1_bo and enable3 ? shortStopPrice : na, color = color.red, style = plot.style_linebr)