我想在 1 分钟时间范围内绘制上午 10:00 至 10:12 之间的高点和低点。如何为这种情况绘制水平线?
//@version=5
indicator("High and Low Plotter", overlay=true)
// Input parameters
startHour = input(10, title="Start Hour")
startMinute = input(00, title="Start Minute")
endHour = input(10, title="End Hour")
endMinute = input(12, title="End Minute")
// Variables
var float sessionHigh = na
var float sessionLow = na
// Conditions
inSession = (hour == startHour and minute >= startMinute) and
(hour == endHour and minute <= endMinute)
// Logic
if (inSession)
if(high > sessionHigh or na(sessionHigh))
sessionHigh := high
if(low < sessionLow or na(sessionLow))
sessionLow := low
// Plotting
plot(inSession ? sessionHigh : na, color=color.red,
title="High in Session")
plot(inSession ? sessionLow : na, color=color.green,
title="Low in Session")
您应该使用
line.new
功能。像这样的东西
//@version=5
indicator("My script", overlay = true)
sessionTime = input.session('1000-1012', 'Session')
tz = 'UTC-8'
session = time(timeframe.period, sessionTime, tz)
startSession = not na(session) and na(session[1])
endSession = na(session) and not na(session[1])
var sessionHighPrice = 0.0
var sessionLowPrice = 0.0
var firstBar = bar_index
line hLine = na
line lLine = na
if startSession
hLine.delete(), lLine.delete()
sessionHighPrice := high
sessionLowPrice := low
firstBar := bar_index
if not na(session)
if high > sessionHighPrice
sessionHighPrice := high
if low < sessionLowPrice
sessionLowPrice := low
if barstate.islast
hLine := line.new(firstBar, sessionHighPrice, bar_index, sessionHighPrice, extend = extend.right)
lLine := line.new(firstBar, sessionLowPrice, bar_index, sessionLowPrice, extend = extend.right)