1

Here I have a code and have a problem with stdev()the parameter length requires integer value which is stored in variable "bar". How can I make it read the value from a variable.

//@version=4    
study("My",overlay=true)
numbars=1
t= time('D')
if t == t[1]
    numbars :=nz(numbars[1]) + 1
else 
    numbars :=1

bar=numbars
z=stdev(close,"bar")
a=vwap + (3*z)
b=vwap-(3*z)
plot(vwap)
plot(a)
plot(b)
PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21
Shubhz
  • 13
  • 3

1 Answers1

0

From reference manual: ARGUMENTS source (series) Series of values to process. length (integer) Number of bars (length).

If the parameter type is “integer”, its value must be known before script execution. So, you cannot use a variable for length in that sense.

For its value to be determined at runtime, it would need to be of type "series integer".

vitruvius
  • 15,740
  • 3
  • 16
  • 26
  • The if else statement. sets the length after formation of new candle. It is like for 1st candle it'll calculate standard deviation with parameter length=1 ...then for 2nd candle it'll calculate standard deviation for length =2 (for both bars previous as well as second bar) but I'm unable to feed length – Shubhz Jan 11 '20 at 21:16