Multi Time Frame Standard Deviation Bands - Bounded

Category: Indicators By: Vonasi Created: April 20, 2020, 11:16 AM
April 20, 2020, 11:16 AM
Indicators
1 Comment

This indicator is a bounded version of my Multi Time Frame Simple Moving Average and Standard Deviation Bands indicator.

The indicator allows you to calculate simple moving averages and standard deviation bands (Bollinger Bands) from up to five different time frames. The indicator then shows where price is with each of these sets of bands as they are bounded around zero and 100 where zero represents the lower standard deviation band in each time frame and 100 represents the upper standard deviation band in each time frame.

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 in the indicator 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 price line within its 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.

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

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

You can also 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 Bounded
//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)

MPerc = ((customclose-Mlower)/(Mupper-Mlower))*100
WPerc = ((customclose-Wlower)/(Wupper-Wlower))*100
DPerc = ((customclose-Dlower)/(Dupper-Dlower))*100
HRPerc = ((customclose-HRLower)/(HRupper-HRlower))*100
MiPerc = ((customclose-MiLower)/(Miupper-Milower))*100

return 0 as "0",50 as "50",100 as "100",MPerc as "Monthly",WPerc as "Weekly",DPerc as "Daily",HRPerc as "Hourly",MiPerc as "Minutes"//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-Bounded.png
Downloads: 33
Download
Filename: MTF-SMA-and-STD-Bounded.itf
Downloads: 92
Vonasi Master
V-oyaging ON A S-mall I-ncome
Author’s Profile

Comments

Logo Logo
Loading...