0
structureLookback   = input(title="Lookback", type=input.integer, defval=7,  group=trs)
targetBarIndex      = input(title="Bar Index", type=input.integer, defval=0,  group=trs)


//bar_index low high


n = bar_index < targetBarIndex ? na : bar_index - targetBarIndex
pivotLowHigh = tradeType == "Long" ? (bar_index < targetBarIndex ? na : low[n]) : bar_index < targetBarIndex ? na : high[n]
    
//Fib Trailing variablen

var Price = 0.0
t_Price = tradeType == "Long" ? highest(high, structureLookback) : lowest(low, structureLookback)

//Berechnung des Fib-Levels

fib_m23 = Price-(Price-pivotLowHigh)*(-0.236)


//Update Price aufgrund von Price Action

if ((bar_index >= targetBarIndex and  targetBarIndex != 0)or targetBarIndex==0)
    //long version
    if (t_Price > Price or Price == 0.0) and tradeType == "Long"
        Price := t_Price
plot(pivotLowHigh, color=color.gray, title="SwingLow")

使用设置的条形索引使我的枢轴低点的功能的这一部分有效,但是在 10-20 秒后我得到了运行时错误。

Pine 无法确定系列的参考长度。尝试使用 max_bars_back

为什么会出现此错误?以及我必须改变的任何建议?

4

1 回答 1

0

这篇文章解释它:https ://www.tradingview.com/chart/?solution=43000587849

基本上是因为您正在使用low[n]high[n]使用一些n未知的并且可能超出此变量的历史缓冲区。你试过玩max_bars_back参数吗?


升级版:

当您在低分辨率柱上进行计算时,您的 barset 编号大于 10001,因此不可能使用 low[targetBarIndex] 之类的东西,其中 targetBarIndex = 10000,因为系列变量的最大历史长度为 10000。您需要重写脚本.

  1. 我建议您添加其他条件,这将使您的脚本仅在所需的targetBarIndex( if bar_index > targetBarIndex and bar_index<targetBarIndex+2 ) 附近进行计算,因为如我所见, pivotLowHigh仅在该区域中计算值。
//@version=4
strategy("My Strategy", overlay=false, margin_long=100, margin_short=100, max_bars_back = 5000)
structureLookback   = input(title="Lookback", type=input.integer, defval=7)
targetBarIndex      = input(title="Bar Index", type=input.integer, defval=0)

tradeType = "Long"
// //bar_index low high
var float pivotLowHigh = na
var int n = na

if bar_index > targetBarIndex and bar_index<targetBarIndex+2
    n := bar_index - targetBarIndex
    pivotLowHigh := tradeType == "Long" ? low[n] : high[n]
    
    
//Fib Trailing variablen

var Price = 0.0
t_Price = tradeType == "Long" ? highest(high, structureLookback) : lowest(low, structureLookback)

//Berechnung des Fib-Levels

fib_m23 = Price-(Price-pivotLowHigh)*(-0.236)


//Update Price aufgrund von Price Action

if ((bar_index >= targetBarIndex and  targetBarIndex != 0)or targetBarIndex==0)
    //long version
    if (t_Price > Price or Price == 0.0) and tradeType == "Long"
        Price := t_Price
plot(pivotLowHigh, color=color.gray, title="SwingLow")

  1. 第二种方法,如果您确实需要计算每个柱中的过去值,那么您可以使用数组来推送highlow值,并从中计算值。数组大小可以比序列变量的历史大 10 倍。
于 2021-12-07T07:36:56.307 回答