Pine script 如何从指定时间段的开始到结束绘制线
我正在写一个代码来绘制每周的高点和低点,并以此为基础试图得到范围。问题是,在绘制线时,应参考x1和x2,以便从时间范围的开始到结束绘制线,例如从一周的开始到一周的结束 这是我的密码。我已经输入了一些barindex,但它会向后绘制线条。非常感谢您的帮助。谢谢Pine script 如何从指定时间段的开始到结束绘制线,pine-script,Pine Script,我正在写一个代码来绘制每周的高点和低点,并以此为基础试图得到范围。问题是,在绘制线时,应参考x1和x2,以便从时间范围的开始到结束绘制线,例如从一周的开始到一周的结束 这是我的密码。我已经输入了一些barindex,但它会向后绘制线条。非常感谢您的帮助。谢谢 // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © alpha
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © alphatrader09
//@version=4
study("Range" , overlay = true)
_1 = input(title = "═════ TimeFrame Settings ═════", type = input.bool, defval = true)
i_resolution = input(title = "Select Timeframe", type = input.resolution, defval ="W")
tfHighLow() =>
float _highestHigh = na
float _lowestLow = na
_highestHigh := highest(high,2)
_lowestLow := lowest(low,2)
[_highestHigh, _lowestLow]
[_hH,_lL] = security(syminfo.tickerid, expression = tfHighLow(), resolution = i_resolution, gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on )
// Values to plot
_h = _hH[1]
_l = _lL[1]
_r = (_h - _l)
_t1 = _lL + _r*1.382
_t2 = _lL + _r*1.618
_m = (_h + _l)/2
_s1 = _hH - _r*1.382
_s2 = _hH - _r*1.618
// lines to plot
var line _Lh = na
var line _Ll = na
var line _Lt1 = na
var line _Lt2 = na
var line _Lm = na
var line _Ls1 = na
var line _Ls2 = na
bool newSess = change(time(i_resolution)) > 0
if newSess and bar_index > 1
_Lh := line.new(x1=bar_index[20], y1=_h, x2=bar_index[0], y2 = _h, xloc = xloc.bar_index, color= color.teal)
做了一些研发,改进了代码中的一些问题,下面是脚本
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © alphatrader09
//@version=4
study("Range" , overlay = true)
_1 = input(title = "═════ TimeFrame Settings ═════", type = input.bool, defval = true)
i_resolution = input(title = "Select Timeframe", type = input.resolution, defval ="W")
tfHighLow() =>
float _highestHigh = na
float _lowestLow = na
_highestHigh := high[1]
_lowestLow := low[1]
[_highestHigh, _lowestLow]
[_hH,_lL] = security(syminfo.tickerid, expression = tfHighLow(), resolution = i_resolution, gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on )
// Values to plot
_h = _hH
_l = _lL
_r = (_h - _l)
_t1 = _lL + _r*1.382
_t2 = _lL + _r*1.618
_m = (_h + _l)/2
_s1 = _hH - _r*1.382
_s2 = _hH - _r*1.618
// lines to plot
var line _Lh = na
var line _Ll = na
var line _Lt1 = na
var line _Lt2 = na
var line _Lm = na
var line _Ls1 = na
var line _Ls2 = na
if _m[1] != _m
line.set_x2(_Lh, bar_index)
line.set_x2(_Ll, bar_index)
line.set_x2(_Lt1, bar_index)
line.set_x2(_Lt2, bar_index)
line.set_x2(_Lm, bar_index)
line.set_x2(_Ls1, bar_index)
line.set_x2(_Ls2, bar_index)
_Lm := line.new(bar_index, _m, bar_index, _m, xloc = xloc.bar_index, extend= extend.none,color= color.black, width=2)
_Lh := line.new(bar_index, _h, bar_index, _h, xloc = xloc.bar_index, extend= extend.none,color= color.teal)
_Ll := line.new(bar_index, _l, bar_index, _l, xloc = xloc.bar_index, extend= extend.none,color= color.red)
_Lt1 := line.new(bar_index, _t1, bar_index, _t1, xloc = xloc.bar_index, extend= extend.none,color= color.teal, style =line.style_dashed)
_Lt2 := line.new(bar_index, _t2, bar_index, _t2, xloc = xloc.bar_index, extend= extend.none,color= color.teal, style = line.style_dashed)
_Ls1 := line.new(bar_index, _s1, bar_index, _s1, xloc = xloc.bar_index, extend= extend.none,color= color.red, style = line.style_dashed)
_Ls2 := line.new(bar_index, _s2, bar_index, _s2, xloc = xloc.bar_index, extend= extend.none,color= color.red, style = line.style_dashed)
if not na(_Lm) and line.get_x2(_Lm) != bar_index
line.set_x2(_Lh, bar_index)
line.set_x2(_Ll, bar_index)
line.set_x2(_Lt1, bar_index)
line.set_x2(_Lt2, bar_index)
line.set_x2(_Lm, bar_index)
line.set_x2(_Ls1, bar_index)
line.set_x2(_Ls2, bar_index)