Normalized smoothed MACD

Category: Indicators By: Nicolas Created: October 16, 2018, 9:43 AM
October 16, 2018, 9:43 AM
Indicators
1 Comment

MACD normalized with its highest and lowest values over the last “inpNormPeriod”.

Classic settings of periods are available. This version embed a small lag smoothing function of the curves for a better reading.

//PRC_Smoothed & Normalized MACD | indicator
//16.10.2018
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//converted from MT5 version

// --- settings 
inpFastPeriod   = 12           // MACD fast period
inpSlowPeriod   = 26           // MACD slow period
inpMacdSignal   = 9            // Signal period
inpSmoothPeriod = 5            // Smoothing period
inpNormPeriod   = 20           // Normalization period
// --- end of settings 

price        = customclose

if barindex>inpslowperiod then 
 alphaf   = 2.0/(1.0+Max(inpFastPeriod,1))
 alphas   = 2.0/(1.0+Max(inpSlowPeriod,1))
 alphasig = 2.0/(1.0+Max(inpMacdSignal,1))
 alphasm  = 2.0/(1.0+Max(inpSmoothPeriod,1))

 emaf = emaf[1]+alphaf*(price-emaf[1])
 emas = emas[1]+alphas*(price-emas[1])
 imacd = emaf-emas

 mmax = Highest[inpNormPeriod](imacd)
 mmin = Lowest[inpNormPeriod](imacd)
 if mmin<>mmax then 
  nval = 2.0*(imacd-mmin)/(mmax-mmin)-1.0 
 else
  nval = 0
 endif

 val = val[1] + alphasm*(nval-val[1])
 sig = sig[1] + alphasig*(val-sig[1])
endif

//colours
if val>val[1] then 
 valr=30
 valv=144
 valb=255
elsif val<val[1] then 
 valr=244
 valv=164
 valb=96
endif
if sig>val then 
 sigr=244
 sigv=164
 sigb=96
else
 sigr=30
 sigv=144
 sigb=255
endif

return val coloured(valr,valv,valb) style(line,3) as "reg smooth MACD", sig coloured(sigr,sigv,sigb) style(dottedline) as "signal line", 0 coloured(169,169,169) style(dottedline) 

 

Download
Filename: PRC_SmoothNorm-MACD.itf
Downloads: 333
Nicolas Master
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Logo Logo
Loading...