Reg
Reg

Reputation: 87

On "plot" getting: "Pine cannot determine the referencing length of a series" error

Using max_bars_back() managed to get the code to execute but then on plot (lines 35 & 36 - when they are commented out the script will run) the error came back. I would have thought that all the calculating would have been done and plot only had to display the results so I was a little surprised by this result.

I also tried to set buffer with max_bars_back() to a large number like 10000 and still got the error so I figured the problem was more than just the buffer being too small.

This code isn't finished and even with this bug fixed it won't yet do precisely what I want but I have to get past this point to finish it. What I am trying to do is plot a line showing the highest point and lowest point of the candles for the length of candles where isSideways remains true and then not plot anything when isSideways is false. I mention this because if a completely different approach is the correct solution please do enlighten me as I am rather new to pine script.

//@version=4
study("My Script")

sidewaysBbSource      = input(close, "Source"                    , type=input.source  ,                                        group="Sideways Detection")
sidewaysBbLength      = input( 50  , "Length"                    , type=input.integer , minval=1      ,                        group="Sideways Detection")
sidewaysBbrLen        = input( 21  , "Signal Smoothing"          , type=input.integer , minval=1      , maxval=50,             group="Sideways Detection")
sidewaysBbMult        = input(  4.0, "Std Deviation"             , type=input.float   , minval=0.001  , maxval=50, step=0.001, group="Sideways Detection")
sidewaysBbrStdThresh  = input( 0.08, "Std Deviation threshold"   , type=input.float   ,                            step=0.01 , group="Sideways Detection")

// Sideways indicator
sidewaysBasis   = sma(sidewaysBbSource, sidewaysBbLength)
sidewaysStdDev2 = sidewaysBbMult * stdev(sidewaysBbSource, sidewaysBbLength)
sidewaysUpper   = sidewaysBasis + sidewaysStdDev2
sidewaysLower   = sidewaysBasis - sidewaysStdDev2
sidewaysBbr     = (sidewaysBbSource - sidewaysLower)/(sidewaysUpper - sidewaysLower)
sidewaysStdDev  = stdev(sidewaysBbr, sidewaysBbrLen)
isSideways      = (sidewaysBbr > 0.0 and sidewaysBbr < 1.0) and sidewaysStdDev <= sidewaysBbrStdThresh

int le = 0
max_bars_back(le, 300)
le := barssince(not isSideways)
le := le == 0 ? 1 : le
//plot(le, color=color.new(color.blue, 0), style=plot.style_cross)

float L = 0
float H = 0
//max_bars_back(L, 300)
//max_bars_back(H, 300)
L := lowestbars(high, le)
H := highestbars(low, le)

//L := le == 1 ? na : L
//H := le == 1 ? na : H

plot(L, "Lowest sideways" , color=color.new(color.blue, 0), style=plot.style_cross)
//plot(H, "highest sideways", color=color.new(color.red, 0), style=plot.style_cross)

bgcolor(                    title="Sidways",                        color=isSideways ? color.rgb(236, 64, 122, 50) : color.new(color.white, 100))
plot(sidewaysStdDev,        title="Standard Deviation",             color=color.new(color.blue, 0),     style=plot.style_line)
plot(sidewaysBbrStdThresh,  title="Standard Deviation Threshold",   color=color.new(color.white, 50),   style=plot.style_cross)

Upvotes: 0

Views: 745

Answers (1)

Reg
Reg

Reputation: 87

I asked support for pine and this is the answer:

//@version=4
study("My Script", max_bars_back = 4999)
...

Upvotes: 3

Related Questions