大佬教程收集整理的这篇文章主要介绍了Tradingview:Pine 无法确定系列的参考长度。尝试使用 max_bars_back,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我目前正在编写一个使用多个时间帧的指标。我只使用 Box.new@H_674_4@ 来显示信息。
我的目标是计算所有相对坐标,将它们保存在一个数组中,然后添加或更新相对
Box@H_674_4@。
我在运行代码时经常遇到此错误,但并非总是如此。新 bar 开头的错误(见图):
Pine 无法确定系列的参考长度。尝试使用 max_bars_BACk
我的代码:
//@version=4
study("SO_example",overlay=true,max_bars_BACk=2000)
//Help function for Higher Timeframe
is_newbar(res) =>
t = time(res)
not na(t) and (na(t[1]) or t > t[1])
//variables
lookBACk_size = 5
move_ratio = input(title="move_ratio",type=input.float,defval=0.5,minval=-10,maxval=10)
atr_ratio = 0.5
lookBACk = 3
higher_res = "60"
// Price Data from Higher Timerframe
o = security(syminfo.tickerID,higher_res,open,barmerge.gaps_off,barmerge.lookahead_off)
h = security(syminfo.tickerID,high,barmerge.lookahead_off)
l = security(syminfo.tickerID,low,barmerge.lookahead_off)
c = security(syminfo.tickerID,close,barmerge.lookahead_off)
//Init Arrays
//Calculations
var drive_detected = array.new_int(0)
var drive_rev_break = array.new_int(0)
var drive_break = array.new_float(0)
var drive_revpoint = array.new_float(0)
//Initialize Boxes for coordinates
Box_trans = 70
col = color.new(color.red,Box_trans)
Box[] Boxes = array.new_Box()
var b0 = Box.new(bar_index,bar_index-2,bgcolor=col,border_wIDth=0)
array.push(Boxes,b0)
var b1 = Box.new(bar_index,border_wIDth=0 )
array.push(Boxes,b1)
var b2 = Box.new(bar_index,b2)
var b3 = Box.new(bar_index,b3)
var b4 = Box.new(bar_index,b4)
//only look for ordinates based on higher Timeframe
if(is_newbar(higher_res))
// condition Calculation
_tr = h-l
_move_mean = sma(_tr,lookBACk)
_move = sum(_tr,lookBACk)
_atr = rma(_tr,14)
_change = c-o
_net_change = sum(_change,lookBACk)
_ratio = 1-((_move- _net_changE)/_movE)
_atr_ratio = (_move_mean/_atr)
_ratio_p = _ratio>0 ? _ratio : na
_ratio_n = _ratio<=0 ? abs(_ratio) : na
condition = _atr_ratio>= atr_ratio and abs(_ratio) > move_ratio
if condition
//save Coordinates
array.unshift(drive_detected,bar_indeX)
array.unshift(drive_break,high)
array.unshift(drive_revpoint,low)
//keep @R_734_10586@l Coordinates of last 'lookBACk_size',pop the rest
if array.size(drive_detected) >lookBACk_size
array.pop(drive_detected)
array.pop(drive_break)
array.pop(drive_revpoint)
bool(na)
//draw/update Boxes
if array.size(drive_detected)>=lookBACk_size
for i = 0 to lookBACk_size-1
_Box = array.get(Boxes,i)
Box.seT_Bottom(_Box,array.get(drive_revpoint,i))
Box.set_top(_Box,array.get(drive_break,i))
Box.set_left(_Box,array.get(drive_detected,i))
Box.set_right(_Box,bar_indeX)
@H_674_4@
我感觉这是条件计算的问题,并且只计算 is_newbar(higher_res)@H_674_4@。
我哪里错了?处理数据的底层结构是什么,以便我可以理解错误及其发生的原因?
非常感谢!
干杯
试试这个方法。我们已经在 condition@H_674_4@ 块外获取了通向
if@H_674_4@ 的计算,因此它们在每个柱上执行:
//@version=4
study("SO_example",overlay=true,max_bars_BACk=2000)
//Help function for Higher Timeframe
is_newbar(res) =>
t = time(res)
not na(t) and (na(t[1]) or t > t[1])
//variables
lookBACk_size = 5
move_ratio = input(title="move_ratio",type=input.float,defval=0.5,minval=-10,maxval=10)
atr_ratio = 0.5
lookBACk = 3
higher_res = "60"
// Price Data from Higher Timerframe
o = security(syminfo.tickerid,higher_res,open,barmerge.gaps_off,barmerge.lookahead_off)
h = security(syminfo.tickerid,high,barmerge.lookahead_off)
l = security(syminfo.tickerid,low,barmerge.lookahead_off)
c = security(syminfo.tickerid,close,barmerge.lookahead_off)
//Init Arrays
//Calculations
var drive_detected = array.new_int(0)
var drive_rev_break = array.new_int(0)
var drive_break = array.new_float(0)
var drive_revpoint = array.new_float(0)
//Initialize boxes for coordinates
box_trans = 70
col = color.new(color.red,box_trans)
box[] boxes = array.new_box()
var b0 = box.new(bar_index,bar_index-2,bgcolor=col,border_width=0)
array.push(boxes,b0)
var b1 = box.new(bar_index,border_width=0 )
array.push(boxes,b1)
var b2 = box.new(bar_index,b2)
var b3 = box.new(bar_index,b3)
var b4 = box.new(bar_index,b4)
// condition Calculation
_tr = h-l
_move_mean = sma(_tr,lookBACk)
_move = sum(_tr,lookBACk)
_atr = rma(_tr,14)
_change = c-o
_net_change = sum(_change,lookBACk)
_ratio = 1-((_move- _net_changE)/_movE)
_atr_ratio = (_move_mean/_atr)
_ratio_p = _ratio>0 ? _ratio : na
_ratio_n = _ratio<=0 ? abs(_ratio) : na
condition = _atr_ratio>= atr_ratio and abs(_ratio) > move_ratio
//only look for ordinates based on higher Timeframe
if(is_newbar(higher_res))
if condition
//save Coordinates
array.unshift(drive_detected,bar_indeX)
array.unshift(drive_break,high)
array.unshift(drive_revpoint,low)
//keep @R_734_10586@l Coordinates of last 'lookBACk_size',pop the rest
if array.size(drive_detected) >lookBACk_size
array.pop(drive_detected)
array.pop(drive_break)
array.pop(drive_revpoint)
bool(na)
//draw/update Boxes
if array.size(drive_detected)>=lookBACk_size
for i = 0 to lookBACk_size-1
_box = array.get(boxes,i)
box.seT_Bottom(_box,array.get(drive_revpoint,i))
box.set_top(_box,array.get(drive_break,i))
box.set_left(_box,array.get(drive_detected,i))
box.set_right(_box,bar_indeX)
@H_674_4@
以上是大佬教程为你收集整理的Tradingview:Pine 无法确定系列的参考长度。尝试使用 max_bars_back全部内容,希望文章能够帮你解决Tradingview:Pine 无法确定系列的参考长度。尝试使用 max_bars_back所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。