本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © amitgandhinz
//@version=5
indicator(title="ORB with Price Targets (GetThatCashMoney)", overlay=true)
// Input options
openingRangeMinutes = input.int(15, title="Opening Range Period (minutes)", options=[5, 15, 30])
//session = input.session("0930-0945", title="Opening Range Session Time", options=["0930-0935", "0930-0945", "0930-1000"])
boxBorderSize = input.int(2, title="Box border size", minval=0)
showShadedBox = input.bool(true, "Shade the ORB Range")
shadeColor = input.color(color.teal, "Shaded ORB Range Color")
showPriceTargets= input.bool(true, "Show Default Price Targets (50%, 100%)")
showFibTargets= input.bool(false, "Show Fibonacci Targets (21.2%, 61.8%)")
session = switch openingRangeMinutes
5 => "0930-0935"
15 => "0930-0945"
30 => "0930-1000"
=> "0930-0945"
inputMax = openingRangeMinutes
timeinrange(session) => not na(time(timeframe.period, session + ":23456", "America/New_York")) ? 1 : 0
// t = time(timeframe.period, session + ":23456")
in_session = timeinrange(session)
hideOpen = timeframe.isintraday and timeframe.multiplier <= inputMax and not in_session
// Create variables
var orbTitle = "ORB" + str.tostring(openingRangeMinutes)
var orbHighPrice = 0.0
var orbLowPrice = 0.0
var box dailyBox = na
// See if a new calendar day started on the intra-day time frame
newDayStart = dayofmonth != dayofmonth[1] and
timeframe.isintraday
// determine ORB15 levels
is_newbar(res) => ta.change(time(res)) != 0
is_first = in_session and not in_session[1]
if is_first
orbHighPrice := high
orbLowPrice := low
else
orbHighPrice := orbHighPrice[1]
orbLowPrice := orbLowPrice[1]
if high > orbHighPrice and in_session
orbHighPrice := high
if low < orbLowPrice and in_session
orbLowPrice := low
var oh = label.new(bar_index, orbHighPrice, style=label.style_label_lower_left, text=orbTitle + " HIGH", color=color.green, textcolor=color.white)
var ol = label.new(bar_index, orbLowPrice, style=label.style_label_lower_left, text=orbTitle + " LOW", color=color.red, textcolor=color.white)
label.set_xy(oh, bar_index + 2, orbHighPrice)
label.set_xy(ol, bar_index + 2, orbLowPrice)
// When a new day start, create a new box for that day.
// Else, during the day, update that day's box.
if showShadedBox
if is_first
dailyBox := box.new(left=bar_index, top=orbHighPrice,
right=bar_index + 1, bottom=orbLowPrice,
border_width=boxBorderSize)
// If we don't want the boxes to join, the previous box shouldn't
// end on the same bar as the new box starts.
box.set_right(dailyBox[1], bar_index[1])
else
box.set_top(dailyBox, orbHighPrice)
box.set_rightbottom(dailyBox, right=bar_index + 1, bottom=orbLowPrice)
box.set_bgcolor(dailyBox, color.new(shadeColor, 80))
box.set_border_color(dailyBox, color.teal)
plot(not in_session ? orbHighPrice : na, style=plot.style_linebr, color=orbHighPrice[1] != orbHighPrice ? na : color.green, title="ORB High", linewidth=2)
plot(not in_session ? orbLowPrice : na , style=plot.style_linebr, color=orbLowPrice[1] != orbLowPrice ? na : color.red, title="ORB Low", linewidth=2)
// plot PT for ORB - 50% retracement
orbRange = orbHighPrice - orbLowPrice
plot(not in_session and showPriceTargets ? orbHighPrice + (orbRange * 0.5) : na, style=plot.style_linebr, color=orbHighPrice[1] != orbHighPrice ? na : color.purple, title="ORB High PT 1", linewidth=2)
plot(not in_session and showPriceTargets ? orbHighPrice + (orbRange * 1.0): na , style=plot.style_linebr, color=orbHighPrice[1] != orbHighPrice ? na : color.blue, title="ORB High PT 2", linewidth=2)
plot(not in_session and showPriceTargets ? orbLowPrice + (orbRange * -0.5): na , style=plot.style_linebr, color=orbLowPrice[1] != orbLowPrice ? na : color.purple, title="ORB Low PT 1", linewidth=2)
plot(not in_session and showPriceTargets ? orbLowPrice + (orbRange * -1.0): na , style=plot.style_linebr, color=orbLowPrice[1] != orbLowPrice ? na : color.blue, title="ORB Low PT 2", linewidth=2)
// fib levels
plot(not in_session and showFibTargets ? orbHighPrice + (orbRange * 0.272): na , style=plot.style_linebr, color=orbLowPrice[1] != orbLowPrice ? na : color.orange, title="ORB 27.2%", linewidth=2)
plot(not in_session and showFibTargets ? orbHighPrice + (orbRange * 0.618): na , style=plot.style_linebr, color=orbLowPrice[1] != orbLowPrice ? na : color.fuchsia, title="ORB 61.8%", linewidth=2)
plot(not in_session and showFibTargets ? orbLowPrice + (orbRange * -0.272): na , style=plot.style_linebr, color=orbLowPrice[1] != orbLowPrice ? na : color.orange, title="ORB 27.2%", linewidth=2)
plot(not in_session and showFibTargets ? orbLowPrice + (orbRange * -0.618): na , style=plot.style_linebr, color=orbLowPrice[1] != orbLowPrice ? na : color.fuchsia, title="ORB 61.8%", linewidth=2)
drawPriceTargetLabel(fromPrice, level, name, col) =>
var pt = label.new(bar_index, fromPrice + (orbRange * level), style=label.style_label_lower_left, text=orbTitle + " " + name, color=col, textcolor=color.white)
label.set_xy(pt, bar_index + 2, fromPrice + (orbRange * level))
isToday = false
if year(timenow) == year(time) and month(timenow) == month(time) and dayofmonth(timenow) == dayofmonth(time) and not session.ispremarket and not in_session
isToday := true
if (not in_session and showPriceTargets and isToday)
drawPriceTargetLabel(orbHighPrice, 0.5, "PT 50%", color.purple)
drawPriceTargetLabel(orbHighPrice, 1.0, "PT 100%", color.blue)
drawPriceTargetLabel(orbLowPrice, -0.5, "PT 50%", color.purple)
drawPriceTargetLabel(orbLowPrice, -1.0, "PT 100%", color.blue)
if (not in_session and showFibTargets and isToday)
drawPriceTargetLabel(orbHighPrice, 0.272, "FIB 27.2%", color.orange)
drawPriceTargetLabel(orbHighPrice, 0.618, "FIB 61.8%", color.fuchsia)
drawPriceTargetLabel(orbLowPrice, -0.272, "FIB 27.2%", color.orange)
drawPriceTargetLabel(orbLowPrice, -0.618, "FIB 61.8%", color.fuchsia)