//PRC_ALMA MACD | indicator
//17.09.2016
//parameters
// Sigma = 4
// Offset = 0.85
// Fast = 12
// Slow = 26
// Signal = 9
Price = customclose
//---Fast MA
m = (Offset * (Fast - 1))
s = Fast/Sigma
WtdSum = 0
CumWt = 0
for k = 0 to Fast - 1 do
Wtd = Exp(-((k-m)*(k-m))/(2*s*s))
WtdSum = WtdSum + Wtd * Price[Fast - 1 - k]
CumWt = CumWt + Wtd
next
FastMA = WtdSum / CumWt
//---Slow MA
n = (Offset * (Slow - 1))
t = Slow/Sigma
SWtdSum = 0
SCumWt = 0
for k = 0 to Slow - 1 do
SWtd = Exp(-((k-n)*(k-n))/(2*t*t))
SWtdSum = SWtdSum + SWtd * Price[Slow - 1 - k]
SCumWt = SCumWt + SWtd
next
SlowMA = SWtdSum / SCumWt
//---MACD
ALMAMACD = FastMA-SlowMA
//---Signal MA
n = (Offset * (Signal - 1))
t = Signal/Sigma
SWtdSum = 0
SCumWt = 0
for k = 0 to Signal - 1 do
SWtd = Exp(-((k-n)*(k-n))/(2*t*t))
SWtdSum = SWtdSum + SWtd * ALMAMACD[Signal - 1 - k]
SCumWt = SCumWt + SWtd
next
SignalMACD = SWtdSum / SCumWt
RETURN ALMAMACD as "ALMA MACD", SignalMACD as "Signal line"