Smooth Moving Average

We have built a new moving average that some other software products have featured, which creates slightly different averages than the standard simple moving average. To download click here, and then store both the.dll file and the .tpl file in the NeuroShell Trader template folder. After restarting NeuroShell, the new indicator will be found in the Custom Indicators folder. Parameters are just the time series to average and the number of periods (bars) to average it over.

For those interested in programming indicators, here is the PowerBasic source code with an explanation of how the indicator is computed in the comments:

#COMPILE DLL
SUB SmoothMA ALIAS "SmoothMA" (BYVAL series AS DOUBLE PTR, BYVAL periods AS LONG, _
BYVAL signal AS DOUBLE PTR, BYVAL cnt AS LONG) EXPORT
'
' The first value for a Smoothed Moving Average is determined by the formula SMOOTH:
' SMOOTH =(series 1 + series 2 + series 3)/periods

' The next values are plotted according to this formula.

' SMOOTH = (previous SMOOTH numerator - previous SMOOTH + series 4)/periods etc.

' Example: If the values 1,2,3,4 and 5 were reported for the first five bars the three-period smoothed
' moving averages for those bars would be calculated as follows:
'(1+2 +3)/3 = 2

' This is the first value and would be plotted on the third bar from the left.
' (6 - 2 + 4)/3 = 2.67 This second value would be plotted on the fourth bar from the left.
' (8 - 2.67+5)/3 = 3.44 This third value would be plotted on the fifth bar from the left, and so on.

DIM missing AS DOUBLE
missing=3.4e38

DIM lastsum AS DOUBLE ' remembers last numerator

REGISTER i AS LONG

lastsum=0 ' initialize the first numerator

FOR i=0 TO cnt-1 ' go through the entire chart

IF i< periods-1 THEN ' there are not yet enough of the time series for the first average @signal[i] = missing ' this plots nothing on the chart lastsum = lastsum + @series[i] ' add to the first numerator ELSEIF i=periods-1 THEN lastsum = lastsum + @series[i] ' add to the first numerator @signal[i] = lastsum/periods ELSE ' this is for the second and subsequent averages lastsum = lastsum - @signal[i-1] + @series[i] ' get the new numerator @signal[i] = lastsum/periods END IF NEXT i END SUB

Was this article helpful?

Related Articles