Multi Time Frame Simple Moving Average and Standard Deviation Bands

Category: Indicators By: Vonasi Created: April 20, 2020, 10:44 AM
April 20, 2020, 10:44 AM
Indicators
6 Comments

This indicator allows you to display simple moving averages and standard deviation bands (Bollinger Bands) from slower time frames on your faster time frame chart. The indicator allows you to draw up to five different time frame lines and bands on your chart. Apply the indicator multiple times if you need more.

This indicator only works with PRTv11 onwards.

You set the average period and number of standard deviations for the bands with the various ‘p’ and ‘dev’ settings.

  • Mp – Monthly average period
  • MDev – Monthly deviations
  • Wp – Weekly average period
  • WDev – Weekly deviations.
  • Dp – Daily average period
  • DDev – Daily deviations.
  • HRp – Hourly average period
  • HRDev – Hourly deviations.
  • MIp – Minutes average period
  • MIDev – Minutes deviations.

If putting Hourly or Minute lines on your chart then you also need to set HRQty and MIQty to the number of hours or minutes. So for example set HRQTY to 4 to display the simple moving average and standard deviation bands from the 4 hour chart. Set the p value of any line that you don’t want to draw to zero –  this also helps the indicator calculate slightly quicker. For example if on a daily chart set HRp and MIp to zero.

The ‘EveryBar’ setting allows to to either just update the lines at the close of each bar on their slower time frame chart or if ‘EveryBar’ is set then the lines update on every bar on the chart you are viewing them on.

You can turn individual lines on and off and change their colour in the indicator configure window.

You can select whether the lines are calculated on close, high, low, median price etc in the indicator configure window.

As always I advise downloading and importing the ITF file to get full functionality.

//Multi Time Frame SMA and STD v2.1
//By Vonasi
//Date: 20200420

//Mp = 20        //Monthly SMA period
//Wp = 20        //Weely SMA period
//Dp = 20        //Dailly SMA period
//HRp = 20       //Hourly SMA period
//MIp = 20       //Minute SMA period
//Mdev = 2       //Number of deviations for Monthly bands
//Wdev = 2       //Number of deviations for Weekly bands
//Ddev = 2       //Number of deviations for Daily bands
//HRdev = 2      //Number of deviations for Hourly bands
//Midev = 2      //Number of deviations for Minute bands
//HRqty= 1       //Which Hour time frame
//MIqty= 1       //Which minute time frame
//EveryBar = 1   //Calculate new SMA on every bar or only update on close

once Mupper = undefined
once Mlower = undefined
once Mavg = undefined
once Wupper = undefined
once Wlower = undefined
once Wavg = undefined
once Dupper = undefined
once Dlower = undefined
once Davg = undefined
once HRupper = undefined
once HRlower = undefined
once HRavg = undefined
once Miupper = undefined
once Milower = undefined
once Miavg = undefined

//store each occurance
if Mp then
if openmonth <> openmonth[1] then
Ma = Ma+1
$Mprice[Ma] = customclose[1]
endif
endif

if Wp then
if opendayofweek < opendayofweek[1] then
Wa = Wa+1
$Wprice[Wa] = customclose[1]
endif
endif

if Dp then
if opendayofweek <> opendayofweek[1] then
Da = Da+1
$Dprice[Da] = customclose[1]
endif
endif

if HRp then
if openhour <> openhour[1] and openhour mod HRqty = 0 then
HRa = HRa+1
$HRprice[Hra] = customclose[1]
endif
endif

if Mip then
if openminute <> openminute[1] and openminute mod MIqty = 0 then
Mia = Mia+1
$Miprice[Mia] = customclose[1]
endif
endif

if Ma+1 >= Mp then
if everybar and Mp then
$Mprice[Ma+1] = customclose
total = 0
for b = Ma+1 downto Ma-Mp+2
total = total + $Mprice[b]
next
Mavg = total/Mp
total = 0
for b = Ma+1 downto Ma-Mp+2
total = total + (square($Mprice[b]-Mavg))
next
endif

if not everybar and Mp then
total = 0
for b = Ma downto Ma-Mp+1
total = total + $Mprice[b]
next
Mavg = total/Mp
total = 0
for b = Ma downto Ma-Mp+1
total = total + (square($Mprice[b]-Mavg))
next
endif
Mstdev = sqrt(total/Mp)
endif

if Wa+1 >= Wp then
if everybar and Wp then
$Wprice[Wa+1] = customclose
total = 0
for b = Wa+1 downto Wa-Wp+2
total = total + $Wprice[b]
next
Wavg = total/Wp
total = 0
for b = Wa+1 downto Wa-Wp+2
total = total + (square($Wprice[b]-Wavg))
next
endif

if not everybar and Wp then
total = 0
for b = Wa downto Wa-Wp+1
total = total + $Wprice[b]
next
Wavg = total/Wp
total = 0
for b = Wa downto Wa-Wp+1
total = total + (square($Wprice[b]-Wavg))
next
endif
Wstdev = sqrt(total/Wp)
endif

if Da+1 >= Dp then
if everybar and Dp then
$Dprice[Da+1] = customclose
total = 0
for b = Da+1 downto Da-Dp+2
total = total + $Dprice[b]
next
Davg = total/Dp
total = 0
for b = Da+1 downto Da-Dp+2
total = total + (square($Dprice[b]-Davg))
next
endif

if not everybar and Dp then
total = 0
for b = Da downto Da-Dp+1
total = total + $Dprice[b]
next
Davg = total/Dp
total = 0
for b = Da downto Da-Dp+1
total = total + (square($Dprice[b]-Davg))
next
endif
Dstdev = sqrt(total/Dp)
endif

if HRa+1 >= HRp then
if everybar and HRp then
$HRprice[HRa+1] = customclose
total = 0
for b = HRa+1 downto HRa-HRp+2
total = total + $HRprice[b]
next
HRavg = total/HRp
total = 0
for b = HRa+1 downto HRa-HRp+2
total = total + (square($HRprice[b]-HRavg))
next
else
total = 0
for b = HRa downto HRa-HRp+2
total = total + $HRprice[b]
next
HRavg = total/HRp
total = 0
for b = HRa downto HRa-HRp+1
total = total + (square($HRprice[b]-HRavg))
next
endif
HRstdev = sqrt(total/HRp)
endif

if Mia+1 >= Mip then
if everybar and Mip then
$Miprice[Mia+1] = customclose
total = 0
for b = Mia+1 downto Mia-Mip+2
total = total + $Miprice[b]
next
Miavg = total/Mip
total = 0
for b = Mia+1 downto Mia-Mip+2
total = total + (square($Miprice[b]-Miavg))
next
else
total = 0
for b = Mia downto Mia-Mip+2
total = total + $Miprice[b]
next
Miavg = total/Mip
total = 0
for b = Mia downto Mia-Mip+1
total = total + (square($Miprice[b]-Miavg))
next
endif
Mistdev = sqrt(total/Mip)
endif

//calculate bands
Mupper = Mavg + (Mstdev*Mdev)
Wupper = Wavg + (Wstdev*Wdev)
Dupper = Davg + (Dstdev*Ddev)
HRupper = HRavg + (HRstdev*HRdev)
Miupper = Miavg + (Mistdev*MIdev)
Mlower = Mavg - (Mstdev*Mdev)
Wlower = Wavg - (Wstdev*Wdev)
Dlower = Davg - (Dstdev*Ddev)
HRlower = HRavg - (HRstdev*HRdev)
Milower = Miavg - (Dstdev*MIdev)

return Mupper as "Month Upper STD Band", Mlower as "Month Lower STD Band", Mavg as "Month SMA", Wupper as "Week Upper STD Band", Wlower as "Week Lower STD Band", Wavg as "Week SMA", Dupper as "Day Upper STD Band", Dlower as "Day Lower STD Band", Davg as "Day SMA", HRupper as "Hour Upper STD Band", HRlower as "Hour Lower STD Band", HRavg as "Hour SMA", Miupper as "Minute Upper STD Band", Milower as "Minute Lower STD Band", Miavg as "Minute SMA"

Download
Filename: MTF-SMA-and-STD-v2.1.itf
Downloads: 225
Download
Filename: MTF-SMA-and-STD.png
Downloads: 95
Vonasi Master
V-oyaging ON A S-mall I-ncome
Author’s Profile

Comments

Logo Logo
Loading...