本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// © asenski at gmail dot com
//@version=5
indicator("Opening Range with Fibs", "OR", overlay=true)
orSpec = input.session("0930-1000", "Opening Range with Fib Extensions")
refsym = input.symbol("SPX500USD", "Reference for time range (So that it is in EST)")
rgColor = input.color(color.rgb(255, 255, 0), "Range color")
// L1Color = input.color(color.rgb(0, 0, 255), "L1 color")
// L2Color = input.color(color.rgb(255, 115, 40), "L2 color")
// L3Color = input.color(color.rgb(255, 0, 255), "L3 color")
L1 = input.float(1.272, "L1")
L2 = input.float(1.618, "L2")
// L3 = input.float(2.618, "L3")
t = request.security(refsym, timeframe.period, time(timeframe.period, orSpec), gaps=barmerge.gaps_on)
var float orh = na
var float orl = na
var int orbars = 0
var float extL1up = na
var float extL2up = na
var float extL3up = na
var float extL1dn = na
var float extL2dn = na
var float extL3dn = na
newSession = na(t[1]) and not na(t)
inSession = not na(t[1]) and not na(t)
endSession = not na(t[1]) and na(t)
if newSession
orh := high
orl := low
orbars := 0
extL1up := na
extL2up := na
extL3up := na
extL1dn := na
extL2dn := na
extL3dn := na
if inSession
orh := math.max(high, orh)
orl := math.min(low, orl)
orbars += 1
var float vwapsum = na
var float volumesum = na
if endSession
extL1up := orl + (orh - orl) * L1
extL2up := orl + (orh - orl) * L2
// extL3up := orl + (orh - orl) * L3
extL1dn := orh - (orh - orl) * L1
extL2dn := orh - (orh - orl) * L2
// extL3dn := orh - (orh - orl) * L3
b1 = box.new(bar_index - orbars - 1, orh, bar_index - 1, orl, border_color = rgColor, bgcolor = na)
b2 = box.new(bar_index - orbars - 1, extL1up, bar_index - 1, extL2up, border_color = rgColor, bgcolor = na)
b3 = box.new(bar_index - orbars - 1, extL1dn, bar_index - 1, extL2dn, border_color = rgColor, bgcolor = na)
if barstate.islast
box.delete(b1[1])
box.delete(b2[1])
box.delete(b3[1])
//plot(newSession ? na : orh, "OR high", color=rgColor,style=plot.style_linebr)
//plot(newSession ? na : orl, "OR low", color=rgColor,style=plot.style_linebr)
//plot(newSession ? na : extL1up, "L1 above", color=L1Color, style=plot.style_linebr)
//plot(newSession ? na : extL2up, "L2 above", color=L2Color, style=plot.style_linebr)
//plot(newSession ? na : extL3up, "L3 above", color=L3Color, style=plot.style_linebr)
//plot(newSession ? na : extL1dn, "L1 below", color=L1Color, style=plot.style_linebr)
//plot(newSession ? na : extL2dn, "L2 below", color=L2Color, style=plot.style_linebr)
//plot(newSession ? na : extL3dn, "L3 below", color=L3Color, style=plot.style_linebr)