【发布时间】:2021-03-15 20:45:11
【问题描述】:
我正在尝试创建一个脚本,将给定交易品种的历史最高价显示为交易视图上的一条水平线。我已经想出了如何搜索历史最高点,但是当我尝试显示它时,它似乎显示了以前的历史最高点。我添加了诊断输出,这似乎显示了我希望绘制的线的价格,但在实际图表上它绘制得更低。我做错了什么?
// © dickymoore
//@version=4
study("All-time-high", overlay=true)
// input
Athlw = input(title="All-time-high line widths", type=input.integer, defval=4, minval=0, maxval=4)
Athlc = input(title="All-time-high line color", type=input.color, defval=color.new(color.fuchsia,50))
years = input(title="Years back to search for an ATH", type=input.integer, defval=6,minval=0, maxval=100)
seriesForAth=security(syminfo.tickerid,"M",high,barmerge.gaps_off,barmerge.lookahead_off)
highestHigh = highest(seriesForAth,(12*years))
// Draw lines from the previous highs and lows
newSession = change(time('D'))
count = barssince(newSession)
var line AllTimeHigh = na
if (newSession)
AllTimeHigh := line.new(x1=bar_index[1],y1=highestHigh,
x2=bar_index,y2=highestHigh, extend=extend.both, color=Athlc,width=Athlw)
line.delete(id = AllTimeHigh[1])
//diagnostics
f_print(_text) =>
var _label = label.new(bar_index, na, _text, xloc.bar_index, yloc.price, color(na), label.style_none, color.gray, size.large, text.align_left)
label.set_xy(_label, bar_index, highest(10)[1])
label.set_text(_label, _text)
f_print("Diagnostics \n" + "\nHigh = " + tostring(highestHigh))
【问题讨论】:
标签: pine-script