One More Average MACD

Category: Indicators By: Nicolas Created: November 23, 2016, 6:16 PM
November 23, 2016, 6:16 PM
Indicators
2 Comments

Another MACD (Moving Average Convergence Divergence) indicator built upon a special moving average formula that adapt its period automatically accordingly to the market behaviour and noises. This moving average is called the OMA (One More Average), the formula come from an MT4 version found on internet.

The adaptive period can be more or less adaptive by changing the “sensibility” parameter (0.1 step). The adaptive behaviour of the formula can be shutdown with “Adaptive=0”.

MACD parameters can be changed between at lines 11 and 12 (Fast and Slow moving average periods).

The signal line is made with an ALMA.

I add the dynamic gradient color code to customise the look and feel of the classic MACD histogram, so this indicator is only compatible with PRT v10.3 and above.

//PRC_OneMoreAverage MACD | indicator
//23.11.2016
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge

//--parameters
//>OMA parameters
Sensibility = 1
Adaptive = 1
//>MACD periods
FLength = 24
SLength = 52
//>signal line
SigLength = 9
Sigma = 4
Offset = 0.85
//--------

Speed = Sensibility
Speed  = Max(Speed,-1.5)
price = average[1](customclose)
tconst=Speed

//--Fast moving average
FLength = Max(FLength,1)
//adaptive period
averagePeriod = FLength
if adaptive=1 and averagePeriod > 1 then
 minPeriod = averagePeriod/2.0
 maxPeriod = minPeriod*5.0
 endPeriod = round(maxPeriod)
 signal    = Abs((price-stored[endPeriod]))
 noise     = 0.00000000001

 for k=1 to endPeriod do
  noise=noise+Abs(price-stored[k])
  averagePeriod = round(((signal/noise)*(maxPeriod-minPeriod))+minPeriod)
 next

endif

alpha = (2.0+tconst)/(1.0+tconst+averagePeriod)

e1 = e1 + alpha*(price-e1)
e2 = e2 + alpha*(e1-e2)
v1 = 1.5 * e1 - 0.5 * e2
e3 = e3 + alpha*(v1   -e3)
e4 = e4 + alpha*(e3-e4)
v2 = 1.5 * e3 - 0.5 * e4
e5 = e5 + alpha*(v2   -e5)
e6 = e6 + alpha*(e5-e6)
Fast = 1.5 * e5 - 0.5 * e6
//------------------------------------

//--Slow moving average
SLength = Max(SLength,1)
//adaptive period
averagePeriod = SLength
if adaptive=1 and averagePeriod > 1 then
 minPeriod = averagePeriod/2.0
 maxPeriod = minPeriod*5.0
 endPeriod = round(maxPeriod)
 signal    = Abs((price-stored[endPeriod]))
 noise     = 0.00000000001

 for k=1 to endPeriod do
  noise=noise+Abs(price-stored[k])
  averagePeriod = round(((signal/noise)*(maxPeriod-minPeriod))+minPeriod)
 next

endif

alpha = (2.0+tconst)/(1.0+tconst+averagePeriod)

e1 = e1 + alpha*(price-e1)
e2 = e2 + alpha*(e1-e2)
v1 = 1.5 * e1 - 0.5 * e2
e3 = e3 + alpha*(v1   -e3)
e4 = e4 + alpha*(e3-e4)
v2 = 1.5 * e3 - 0.5 * e4
e5 = e5 + alpha*(v2   -e5)
e6 = e6 + alpha*(e5-e6)
Slow = 1.5 * e5 - 0.5 * e6
//------------------------------------


//--Signal moving average
OMAMACD = Slow-Fast
SigLength = Max(SigLength,1)
//---Signal MA
n = (Offset * (SigLength - 1))
t = SigLength/Sigma
SWtdSum = 0
SCumWt  = 0
for k = 0 to SigLength - 1 do
 SWtd = Exp(-((k-n)*(k-n))/(2*t*t))
 SWtdSum = SWtdSum + SWtd * OMAMACD[SigLength - 1 - k]
 SCumWt = SCumWt + SWtd
next
SIGMACD = SWtdSum / SCumWt
//------------------------------------

stored=price

// --- ProRealcode RGB color matrix for PRT v10.3
valueentry = OMAMACD //data entry for automatic color scaling
maxr = 153 //R of RGB value for "bullish" sentiment/zone
maxg = 255 //G of RGB value for "bullish" sentiment/zone
maxb = 153 //B of RGB value for "bullish" sentiment/zone
minr = 255 //R of RGB value for "bearish" sentiment/zone
ming = 204 //G of RGB value for "bearish" sentiment/zone
minb = 204 //B of RGB value for "bearish" sentiment/zone
maxvalue = highest[200](valueentry) //could be modified by the maximum value in a bounded oscillator
middlevalue = 0 //middle value of the indicator
minvalue = lowest[200](valueentry) //could be modified by the minimum value in a bounded oscillator
absmaxvalue = abs(maxvalue)
absminvalue = abs(minvalue)
absmidvalue = abs(middlevalue)
if valueentry>absmidvalue then
 r = maxr/(absmaxvalue-absmidvalue)*valueentry
 g = maxg/(absmaxvalue-absmidvalue)*valueentry
 b = maxb/(absmaxvalue-absmidvalue)*valueentry
else
 r = abs(minr/abs(absminvalue-absmidvalue)*valueentry)
 g = abs(ming/abs(absminvalue-absmidvalue)*valueentry)
 b = abs(minb/abs(absminvalue-absmidvalue)*valueentry)
endif

RETURN OMAMACD coloured(r,g,b), SIGMACD as "Signal"

Download
Filename: alphabet-google-OMA-MACD.png
Downloads: 57
Download
Filename: PRC_OneMoreAverage-MACD.itf
Downloads: 196
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...