I just came across pine script now and want to create a simple indicator. I am not a programmer so it’s not native to me.
The code would calculate the average values of the high-low for the last 20 bars. The variable avgRange would be used to store the average. So the function I used to calculate simple moving average was: ta.sma(
I want to calculate the standard deviation of the high-low over each of the last 20 bars. I would name the variable StDev. What function do I use for that? Is it ta.cstd(
?
Lastly, I want to find the coefficient of variation(I named the variable CoffVar) and plot it’s value.
So the code I wrote so far is below. I left the standard deviation blank because I don’t know what to fill in there.
BarRange()=>high-low
avgRange=ta.sma(BarRange(),20)
StDev=…….
CoffVar=StDev/avgRange*100
plot(CoffVar)
pine script already has a built in function in the technical analysis library (
ta.stdev
). you will just need to enter the source (in your case hl2 is the mid point of the bar) and the number of bars: