Я хочу написать условие, в котором, если на 15-минутном графике (например), если 2-я, 3-я и 4-я свечи находятся в пределах диапазона открытия, созданного 1-й 15-минутной свечой, то после 5-й свечи, если какая-либо свеча разбивается вне диапазона будет сработать покупка (прорыв вверх) или продажа (прорыв вниз).
У меня есть код для диапазона открытия, но я должен включить этот критерий.
//@version=4
study(title="ORB Indicator", shorttitle="ORB", overlay=true)
//User Input
showHistoricalORB = input(false, title="Show historical ORB",
type=input.bool)
showAvg = input(false, title="Show average", type=input.bool)
orbTimeFrame = input("15", title="ORB timeframe", type=input.resolution)
sessSpec = input("0915-1530", title="Session time", type=input.session)
// Defaults
// Colors
aColor = color.gray
rColor = color.red
sColor = color.green
// Line style & Transparency
lStyle = plot.style_line
lTransp = 35
// Get High & Low
getSeries(_e, _timeFrame) => security(syminfo.tickerid, _timeFrame, _e,
lookahead=barmerge.lookahead_on)
is_newbar(res, sess) =>
t = time(res, sess)
na(t[1]) and not na(t) or t[1] < t
newbar = is_newbar("375", "0915-1530")
var float orbH = na
var float orbL = na
if newbar
orbH := getSeries(high[0], orbTimeFrame)
orbL := getSeries(low[0], orbTimeFrame)
orbA = (orbH + orbL)/2
// Today's Session Start timestamp
y = year(timenow)
m = month(timenow)
d = dayofmonth(timenow)
// Start & End time for Today
start = timestamp(y, m, d, 09, 15)
end = start + 86400000
// Plot only if session started
isToday = timenow > start
// Plot selected timeframe's High, Low & Avg
// Plot lines
if isToday
_h = line.new(start, orbH, end, orbH, xloc.bar_time,
color=color.new(rColor, lTransp))
line.delete(_h[1])
_l = line.new(start, orbL, end, orbL, xloc.bar_time,
color=color.new(sColor, lTransp))
line.delete(_l[1])
if showAvg
_a = line.new(start, orbA, end, orbA, xloc.bar_time,
color=color.new(aColor, lTransp))
line.delete(_a[1])
// Plot labels
if isToday
l_h = label.new(start, orbH, text="High", xloc=xloc.bar_time,
textcolor=rColor, style=label.style_none)
label.delete(l_h[1])
l_l = label.new(start, orbL, text="Low", xloc=xloc.bar_time,
textcolor=sColor, style=label.style_none)
label.delete(l_l[1])
if showAvg
l_a = label.new(start, orbA, text="Avg", xloc=xloc.bar_time,
textcolor=aColor, style=label.style_none)
label.delete(l_a[1])
plot(showHistoricalORB ? orbH : na, title=' High', color=rColor,
transp=lTransp)
plot(showHistoricalORB ? orbL : na, title=' Low', color=sColor,
transp=lTransp)
plot(showHistoricalORB ? showAvg ? orbA : na : na, title=' Avg',
color=aColor, transp=lTransp)
// Display Buy & Sell signal
plotSignals = false
if showHistoricalORB
plotSignals := true
else
if year(time) == year(timenow) and month(timenow) == month(time) and
dayofmonth(time) == dayofmonth(timenow)
plotSignals := true
//This is the point where i run into the problem of finding out if the
2nd, 3rd, 4th bars are within the opening range of the 1st 15min bar
//After the 5th bar onwards, any bar if breaks the range, a buy or sell is
triggered
//n_bar = bar_index
//Calc_candle(oH, oL, a)=>
// for n_bar = 1 to barstate.islast by 1
// var orb_break_up = 0
// var orb_break_dn = 0
// orb_break_up := close > oH ? 1 : na
// orb_break_dn := close < oL ? 1 : na
// [orb_break_up, orb_break_dn]
//[o1, o2] = Calc_candle(orbH, orbL, x)
//plotshape(plotSignals and o1 ? crossover(close, orbH) : na,
style=shape.triangleup, location=location.belowbar, color=color.lime,
text="Buy", textcolor=color.lime)
//plotshape(plotSignals and o2 ? crossover(orbL, close) : na,
style=shape.triangledown, location=location.abovebar, color=color.red,
text="Sell", textcolor=color.red)