dK = 2.0 / (p1 + 1.0)

dEMAB = 0.0

p1 = 100

For j = n + 1 To (n + 1 + p1)

dEMAB += m_aClose(j)

Next j

If p1 > 0 Then

dEMAB = dEMAB / p1

End If

For i = n To 0 Step -1

m_aEMA(i) = dEMAB + dK * (m_aClose(i) - dEMAB)

dEMAB = m_aEMA(i)

Next i

Hope this helps.

dEMAB = 0.0

p1 = 100

For j = n + 1 To (n + 1 + p1)

dEMAB += m_aClose(j)

Next j

If p1 > 0 Then

dEMAB = dEMAB / p1

End If

For i = n To 0 Step -1

m_aEMA(i) = dEMAB + dK * (m_aClose(i) - dEMAB)

dEMAB = m_aEMA(i)

Next i

Hope this helps.