61. Introduction to SMA Algorithm

Published at 1683738340.137779

Definition of SMA

The moving average (MA) is one of the classic tools used by technical analysts. Simple moving average (SMA) is the most common form of MA, defined as follows:

  • Collect past price points data: Pt-N+1 ...,Pt-3,Pt-2,Pt-1,Pt;

  • Select the number of price points (N) to be averaged;

  • Calculate the average of the last N price points:

SMA(N)t = (Pt + P(t-1) + P(t-2) + ... + P(t-N+1)) ÷ N

SMA Algorithm

Hypothesis. When the price starts to rise again after a downtrend, the price line crossing over the SMA signals an uptrend that is expected to continue in the short term. Conversely, when the price starts to fall after an uptrend, a drop below the SMA signals the beginning of a downtrend.

Strategy Group

Market. Derivatives market – futures contracts VN30F1M.

When to Open Positions

  • Independent variable: VN30F1M price by ticks.

  • Dependent variable:

SMA(N)t = (Pt + P(t-1) + P(t-2) + ... + P(t-N+1)) ÷ N

where Pt is the current price of VN30F1M, Pt-1 is the previous tick price.

  • Parameter: the number of tick price points (N) to calculate the average, default = 2000.

  • Place a limit order (LO) to buy at the ceiling price or sell at the floor price as soon as there’s a signal to open a position.

If Pt-1 < SMA(N)t-1 and Pt ≥ SMA(N)t then open a buy position;

If Pt-1 > SMA(N)t-1 and Pt ≤ SMA(N)t then open a sell position.

  • Only trade 01 contract maximum for each position. Limit 03 positions maximum per day (03 transactions to open positions and 03 transactions to close positions).

When to Close Positions

  • Place orders to sell at the floor price or buy at the ceiling price as soon as the target is reached.

Take-profit point = Position opening price + Expected profit

  • If Pt ≤ (Price to open the position - Stop loss) then place an order to buy at the ceiling price or sell at the floor price to close the position (stop loss). The stop loss threshold can be adjusted.

  • No positions remain overnight. At the ATC sessions, if the account still has an open position, then close the position with an ATC order.


  • Expected profit: N/A;

  • Maximum drawdown (MDD): N/A.


  • The SMA algorithm works well when the market has a clear trend.

  • SMA algorithm is a popular and simple algorithm in technical analysis, designed to illustrate the concept of “trading algorithm” and test the automated system. Therefore, investors should note that this algorithm does not guarantee profits.

Read more