如何在日内围绕定义的交易时段(最高价和最低价)绘制一个方框
我正在研究这个松树脚本,我想在08:00到09:00绘制一个盒子 内部高和低。我被起草了盒子的坐标。
对我来说问题是我不知道如何将酒吧作为整数 我定义的会话。目前,FirstBar和LastBar是布尔
//@version=5
indicator("breakout", overlay=true)
usrTimeframe = input.timeframe('15', title="Timeframe", options=['1', '3', '5','15','30'])
usrSession = input.session('0800-0900', title="Session")
// Color timeframe
timeInSession = time(timeframe.period, usrSession + ':23456')
bgcolor(timeInSession ? color.new(color.blue, 90) : na)
//check bars in timeframe
showHi = input(true, 'Show highs')
showLo = input(true, 'Show lows')
srcHi = input(high, 'Source for Highs')
srcLo = input(low, 'Source for Lows')
noPlotOutside = input(true, 'Don\'t plot outside of hours')
var hi = 10e-10
var lo = 10e10
if timeInSession
// We are entering allowed hours; reset hi/lo.
if not timeInSession[1]
hi := srcHi
lo := srcLo
lo
else
// We are in allowed hours; track hi/lo.
hi := math.max(srcHi, hi)
lo := math.min(srcLo, lo)
lo
plot(showHi and not (noPlotOutside and not timeInSession) ? hi : na, 'Highs', color.new(color.blue, 0), 3, plot.style_circles)
plot(showLo and not (noPlotOutside and not timeInSession) ? lo : na, 'Lows', color.new(color.fuchsia, 0), 3, plot.style_circles)
firstBar = na(timeInSession[1]) and not na(timeInSession) or timeInSession[1] < timeInSession
lastBar = na(timeInSession) and not na(timeInSession)
breakoutBox = box.new(left = firstBar, top = hi, right = lastBar, bottom = lo)
plot(close, title="ENDplot")
来源:
[https://stackoverflow.com/questions/69644349/how-to-get-highest-high-lowest-low-and-close-of-a-session-in-pine-script-tradin](https://stackoverflow.com/questions/69644349/how-to-get-highest-high-lowest-low-and-close-of-a-session-in-pine-script-tradin)
[https://www.tradingcode.net/tradingview/daily-high-low-boxes/](https://www.tradingcode.net/tradingview/daily-high-low-boxes/)
我尝试使用特定的时间戳来定义某些条, 但这只是没有显示任何框
t1 = (timestamp("GMT+1",2022,03,25,08,00,00))
t2 = (timestamp("GMT+1",2022,03,25,09,00,00))
candleHigh = high[t1]
candleLow = low[t2]
breakoutBox = box.new(left = t1, top = hi, right = t2, bottom = lo)
更新:28.03.2022
我进一步更改了代码,并试图将几天更改为自定义会话,但是现在盒子没有显示,有人想到了吗?
//@version=5
strategy("custom session", overlay=true, margin_long=100, margin_short=100)
// Input options
boxBorderSize = input.int(2, title="Box border size", minval=0)
upBoxColor = input.color(color.new(color.green, 85), title="Up box colour")
upBorderColor = input.color(color.green, title="Up border colour")
downBoxColor = input.color(color.new(color.red, 85), title="Down box colour")
downBorderColor = input.color(color.red, title="Down border colour")
joinBoxes = input.bool(false, title="Join boxes")
usrSession = input.session('0800-0929', title="uSession", options=['0800-0929','0800-0930', '0900-1029', '0900-1030'])
// Create variables
var sessionHighPrice = 0.0
var sessionLowPrice = 0.0
var prevDayClose = 0.0 //will later be problem if sessionstart is not daystart!
var box sessionBox = na
// See if a new calendar day started on the intra-day time frame
//newDayStart = dayofmonth != dayofmonth[1] and
// timeframe.isintraday
//see if new session started
newSessionStart = usrSession != usrSession[1] and timeframe.isminutes
inSession = not na(time(timeframe.period, "0800-0929:23456", "GMT+1"))
// If a new session starts, set the high and low to that bar's data. Else
// during the session track the highest high and lowest low.
if newSessionStart and inSession
sessionHighPrice := high
sessionLowPrice := low
prevDayClose := close[1]
else if inSession
sessionHighPrice := math.max(sessionHighPrice, high)
sessionLowPrice := math.min(sessionLowPrice, low)
else
na
// When a new session start, create a new box for that session.
// Else, during the session, update that day's box.
if newSessionStart and inSession
sessionBox := box.new(left=bar_index, top=sessionHighPrice,
right=bar_index + 1, bottom=sessionLowPrice,
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.
if inSession and not joinBoxes
box.set_right(sessionBox[1], bar_index[1])
else if inSession
box.set_top(sessionBox, sessionHighPrice)
box.set_rightbottom(sessionBox, right=bar_index + 1, bottom=sessionLowPrice)
// If the current bar closed higher than yesterday's close, make
// the box green (and paint it red otherwise)
if close > prevDayClose
box.set_bgcolor(sessionBox, upBoxColor)
box.set_border_color(sessionBox, upBorderColor)
else
box.set_bgcolor(sessionBox, downBoxColor)
box.set_border_color(sessionBox, downBorderColor)
else
na
I am working on this pine script where I want to draw a box from 08:00 to 09:00 and from
the high and low within it. I am stuck with drafting the coordinates for the box.
The problem for me is that I don't know how to get the bars as integer within
the session I defined. Right now, firstBar and lastBar are boolean
//@version=5
indicator("breakout", overlay=true)
usrTimeframe = input.timeframe('15', title="Timeframe", options=['1', '3', '5','15','30'])
usrSession = input.session('0800-0900', title="Session")
// Color timeframe
timeInSession = time(timeframe.period, usrSession + ':23456')
bgcolor(timeInSession ? color.new(color.blue, 90) : na)
//check bars in timeframe
showHi = input(true, 'Show highs')
showLo = input(true, 'Show lows')
srcHi = input(high, 'Source for Highs')
srcLo = input(low, 'Source for Lows')
noPlotOutside = input(true, 'Don\'t plot outside of hours')
var hi = 10e-10
var lo = 10e10
if timeInSession
// We are entering allowed hours; reset hi/lo.
if not timeInSession[1]
hi := srcHi
lo := srcLo
lo
else
// We are in allowed hours; track hi/lo.
hi := math.max(srcHi, hi)
lo := math.min(srcLo, lo)
lo
plot(showHi and not (noPlotOutside and not timeInSession) ? hi : na, 'Highs', color.new(color.blue, 0), 3, plot.style_circles)
plot(showLo and not (noPlotOutside and not timeInSession) ? lo : na, 'Lows', color.new(color.fuchsia, 0), 3, plot.style_circles)
firstBar = na(timeInSession[1]) and not na(timeInSession) or timeInSession[1] < timeInSession
lastBar = na(timeInSession) and not na(timeInSession)
breakoutBox = box.new(left = firstBar, top = hi, right = lastBar, bottom = lo)
plot(close, title="ENDplot")
Sources:
[https://stackoverflow.com/questions/69644349/how-to-get-highest-high-lowest-low-and-close-of-a-session-in-pine-script-tradin](https://stackoverflow.com/questions/69644349/how-to-get-highest-high-lowest-low-and-close-of-a-session-in-pine-script-tradin)
[https://www.tradingcode.net/tradingview/daily-high-low-boxes/](https://www.tradingcode.net/tradingview/daily-high-low-boxes/)
I tried defining certain bars by using specific timestamps,
but this just does not show any box
t1 = (timestamp("GMT+1",2022,03,25,08,00,00))
t2 = (timestamp("GMT+1",2022,03,25,09,00,00))
candleHigh = high[t1]
candleLow = low[t2]
breakoutBox = box.new(left = t1, top = hi, right = t2, bottom = lo)
UPDATE: 28.03.2022
I transformed the code further and tried to change days into a custom session, but now the boxes don't show, someone an idea?
//@version=5
strategy("custom session", overlay=true, margin_long=100, margin_short=100)
// Input options
boxBorderSize = input.int(2, title="Box border size", minval=0)
upBoxColor = input.color(color.new(color.green, 85), title="Up box colour")
upBorderColor = input.color(color.green, title="Up border colour")
downBoxColor = input.color(color.new(color.red, 85), title="Down box colour")
downBorderColor = input.color(color.red, title="Down border colour")
joinBoxes = input.bool(false, title="Join boxes")
usrSession = input.session('0800-0929', title="uSession", options=['0800-0929','0800-0930', '0900-1029', '0900-1030'])
// Create variables
var sessionHighPrice = 0.0
var sessionLowPrice = 0.0
var prevDayClose = 0.0 //will later be problem if sessionstart is not daystart!
var box sessionBox = na
// See if a new calendar day started on the intra-day time frame
//newDayStart = dayofmonth != dayofmonth[1] and
// timeframe.isintraday
//see if new session started
newSessionStart = usrSession != usrSession[1] and timeframe.isminutes
inSession = not na(time(timeframe.period, "0800-0929:23456", "GMT+1"))
// If a new session starts, set the high and low to that bar's data. Else
// during the session track the highest high and lowest low.
if newSessionStart and inSession
sessionHighPrice := high
sessionLowPrice := low
prevDayClose := close[1]
else if inSession
sessionHighPrice := math.max(sessionHighPrice, high)
sessionLowPrice := math.min(sessionLowPrice, low)
else
na
// When a new session start, create a new box for that session.
// Else, during the session, update that day's box.
if newSessionStart and inSession
sessionBox := box.new(left=bar_index, top=sessionHighPrice,
right=bar_index + 1, bottom=sessionLowPrice,
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.
if inSession and not joinBoxes
box.set_right(sessionBox[1], bar_index[1])
else if inSession
box.set_top(sessionBox, sessionHighPrice)
box.set_rightbottom(sessionBox, right=bar_index + 1, bottom=sessionLowPrice)
// If the current bar closed higher than yesterday's close, make
// the box green (and paint it red otherwise)
if close > prevDayClose
box.set_bgcolor(sessionBox, upBoxColor)
box.set_border_color(sessionBox, upBorderColor)
else
box.set_bgcolor(sessionBox, downBoxColor)
box.set_border_color(sessionBox, downBorderColor)
else
na
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

在整合了很多东西之后,我想出了这个可行的解决方案,
它不漂亮,但可以完成工作。注意:有时候需要修改代码并不是所有的输入都有效!
after bodging a lot of stuff together I came up with this working solution,
its not pretty but does the job. Note: Some times have to be modified in the code not all the inputs are effective!