ALMA for ThinkOrSwim

The research for the perfect Moving Average is a constant in the trading world. A moving average can be used to alert of trend changes, market overbought/oversold conditions or “unnormal” values. Having the perfect balance between precision and smoothness in a moving average has been the goal of numerous studies and projects, giving birth to a variaety of moving averages like Simple Moving Average (SMA), Exponential MA (EMA), Weighted MA (WMA), Wilder MA, Hull MA (HMA), Jurik MA (JMA), Fractal Adaptive MA (FAMA), MESA Adaptive MA (MAMA), etc.

Among them, there is one that it is specially famous, the Arnaud Legoux MA (ALMA), and for good reasons. ALMA doesn’t give too much importance to what happened in the very last bar of data, but to the underlying trend. It responds quick to changes in trend and doesn’t suffer from any overshoot effects found in others MA like HMA.

ALMA

Not happy with all of this, ALMA is available for free on the Internet. Other MAs are behind high paying walls that not everyone are willing to jump. Thanks to this, ALMA has been downloaded more than 25,000 times since January 2010, and counting.

But! There is no ThinkOrSwim code available in the ALMA website, there is no ALMA indicator in ThinkOrSwim, and, until today, I haven’t found anyone on the Internet that has published the ALMA adapted to ThinkOrSwim language, ThinkScript.

Thanks to someone adapting ALMA to Excel, I’ve been able to adapt ALMA to ThinkOrSwim and I’m recoding all my old indicators to use ALMA as their MA. This will result in better signals for all of those indicators that try to highlight out-of-the-normal values.

As ALMA is shared for free on the Internet by its original authors, I want to join them and offer for free the ThinkScript code for ALMA:

Code:

#XBPTrading: http://xbptrading.com | xbptrading@gmail.com
#XBP18_01_ALMA
#Update: August 2017

script ALMA {
 input Data = close;
 input Window = 9;
 input Sigma = 6;
 input Offset = 0.85;

 def m = (Offset * (Window - 1));
 def s = Window/Sigma;

 def SumVectorData = fold y = 0 to Window with WS do WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
 def SumVector = fold z = 0 to Window with CW do CW + Exp(-(sqr(z-m))/(2*sqr(s)));

 plot ALMA = SumVectorData / SumVector;
}

input Window = 9;
input Sigma = 6;
input Offset = 0.85;

plot ALMA = ALMA (close, Window, Sigma, Offset);
ALMA.setPaintingStrategy(PaintingStrategy.LINE);
ALMA.SetDefaultColor(Color.CYAN);
ALMA.HideTitle();
ALMA.HideBubble();

Note: If you use this code in your indicators, please keep the 3 commented lines in the header.

As an example here is Nasdaq futures with ALMA(9, 6, 0.85):

NQwithALMA

 

Advertisements

2 Comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s