This code snippet demonstrates how to calculate and plot weekly Bollinger Bands on a daily chart using ProBuilder language. Bollinger Bands are a type of statistical chart characterizing the prices and volatility over time of a financial instrument or commodity, using a formulaic method involving moving averages and standard deviation.
//Weekly Bollinger Bands On Faster Time Frame chart
//PRTv11
//By Vonasi
//Date: 20200415
p = 20
deviations = 2
//store each week's close
if opendayofweek < opendayofweek[1] then
a = a+1
$price[a] = close[1]
endif
if a >= p then
//get a mean of last p weeks' close price
total = 0
for b = a downto a-p+1
total = total + $price[b]
next
avg = total/p
//calculate standard deviation
total = 0
for b = a downto a-p+1
total = total + (square($price[b]-avg))
next
stdev = sqrt(total/p)
//calculate bands
upper = avg + (stdev*deviations)
lower = avg - (stdev*deviations)
endif
return upper as "upper", lower as "lower", avg as "avg"
The code snippet above is structured to perform the following steps:
This example is useful for understanding how to manipulate time series data and perform statistical calculations in ProBuilder language to create dynamic trading indicators.
Check out this related content for more information:
https://www.prorealcode.com/topic/higher-time-frame-bollinger-band/#post-126260
Visit Link