本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=5
indicator('Chews Opening Range Breakout - Fib', shorttitle="Cs fORB ", overlay=true)
quantity = input.int(10, title="Quantity", step=10, minval=1, group="Details")
loss_factor = input.float(0.618, options=[0, 0.236, 0.328, 0.5, 0.618, 0.786, 1], title="Fib-based Percentage to Risk", group="Details")
wicks = input.bool(false, title="Consider Wicks in Fibonacci?", group="Wicks")
entry_color = input.color(color.white, title="Entry Color", group="Colors")
buy_color = input.color(color.black, title="Take Profit Color", group="Colors")
sell_color = input.color(color.black, title="Stoploss Color", group="Colors")
bck_buy = input.color(color.olive, title="Background Color for Profit", group="Background Colors")
bck_buy_transp = input.int(80, title="Background Color Profit Transparency", minval=0, maxval=100, group="Background Colors")
bck_sell = input.color(color.red, title="Background Color for Stoploss", group="Background Colors")
bck_sell_transp = input.int(80, title="Background Color Stoploss Transparency", minval=0, maxval=100, group="Background Colors")
wdth = input.int(1, title="Line Width", minval=0, step=1, group="Line Dimensions")
t = time('1440', session.regular) // 1440=60*24 is the number of minutes in a whole day. You may use "0930-1600" as second session parameter
//plot(t, style=linebr) // Uncomment for better understanding
is_first = na(t[1]) and not na(t) or t[1] < t
var second_index = 0
float profit_wanted = 0
isNewDay = time("D") != time("D")[1]
if isNewDay
second_index := bar_index + 1
//label.new(bar_index, high, text="First bar", textcolor=entry_color)
// enter strategy on new
else if bar_index == second_index
// Calculate the move
if wicks // consider the wicks
profit_wanted := math.abs(high[1] - low[1])
else
profit_wanted := math.abs(close[1] - open[1])
// check if previous bar was green (LONG)
if close[1] >= open[1]
// entry
entry_line = line.new(second_index - 1, close[1], second_index, close[1], width=wdth, color=entry_color)
// exit
//exit_line = line.new(second_index - 1, close[1] + profit_factor * profit_wanted, second_index, close[1] + profit_factor * profit_wanted, width=wdth, color=buy_color)
exit_line = line.new(second_index - 1, close[1] + profit_wanted, second_index, close[1] + profit_wanted, width=wdth, color=buy_color)
// stoploss
stop_line = line.new(second_index - 1, close[1] - (profit_wanted * (1 - loss_factor)), second_index, close[1] - (profit_wanted * (1 - loss_factor)), width=wdth, color=sell_color)
linefill.new(entry_line, exit_line, color.new(bck_buy, bck_buy_transp))
linefill.new(entry_line, stop_line, color.new(bck_sell, bck_sell_transp))
label.new(second_index-1, high[1], text="Entry: " + str.tostring(math.round(close[1], 2)) + "\nExit: " + str.tostring(math.round(close[1] + profit_wanted, 2)) + "\nStoploss: " + str.tostring(math.round(close[1] - (profit_wanted * (1 - loss_factor)), 2)) + "\nQty: " + str.tostring(quantity), textcolor=entry_color)
// check if previous bar was red (SHORT)
if open[1] >= close[1]
// entry
entry_line = line.new(second_index - 1, close[1], second_index, close[1], width=wdth, color=entry_color)
// exit
//exit_line = line.new(second_index - 1, close[1] - profit_factor * profit_wanted, second_index, close[1] - profit_factor * profit_wanted, width=wdth, color=buy_color)
exit_line = line.new(second_index - 1, close[1] - profit_wanted, second_index, close[1] - profit_wanted, width=wdth, color=buy_color)
// stoploss
stop_line = line.new(second_index - 1, close[1] + (profit_wanted * (1 - loss_factor)), second_index, close[1] + (profit_wanted * (1 - loss_factor)), width=wdth, color=sell_color)
linefill.new(entry_line, exit_line, color.new(bck_buy, bck_buy_transp))
linefill.new(entry_line, stop_line, color.new(bck_sell, bck_sell_transp))
label.new(second_index-1, high[1], text="Entry: " + str.tostring(math.round(close[1], 2)) + "\nExit: " + str.tostring(math.round(close[1] - profit_wanted, 2)) + "\nStoploss: " + str.tostring(math.round(close[1] + (profit_wanted * (1 - loss_factor)), 2)) + "\nQty: " + str.tostring(quantity), textcolor=entry_color)