SMA algorithm