SMA, EMA and dual moving average strategies

What is MA

MA is the abbreviation of Moving Average, which is a simple technical analysis tool that analyzes stock price trends by creating a constantly updated average price, or is used to determine its support and resistance levels. This is a lagging indicator because it bases its analysis on past prices. The longer the moving average, the greater the lag; the shorter the time period, the greater the sensitivity to price changes.

Investors can choose different lengths of different time periods to calculate moving averages based on their own trading goals. Short-term moving averages are typically used for short-term trading, while long-term moving averages are more suitable for long-term investing.

What is SMA

SMA is the abbreviation of Simple Moving Average.

The formula of SMA is as follows:

SMA=(A1+A2+...+An)/n

Among them, An=the closing price of the asset price on the nth day, n=the moving average period time. For example, Tesla's stock price closed at $10, $11, $12, $11, and $14 respectively within 5 days. The simple moving average of Tesla stock is equal to $10 + $11 + $12 + $11 + $14 divided by 5, which equals $11.6.

The longer the moving average period, the smoother the simple moving average; the shorter the period, the SMA fluctuates more, but its reading is closer to the original data. In fact, the original price was SMA1.

Disadvantages: SMA may rely too much on outdated data because it treats the impact on day 10 or 200 the same as the impact on day 1 or 2.

Application: Use talib.SMA() for calculations. See the communication section for specific codes. 

What is EMA

EMA (Exponential Moving Average) is the abbreviation of exponential moving average, also called EXPMA indicator. It is an exponentially decreasing weighted moving average, which has greater weight on the recent price trend. The calculation formula of EMA is as follows:

Among them, Smoothing is the smoothing coefficient, usually taken as 2. Days is the moving average period time.

Application: Use talib.EMA() for calculations. See the communication section for specific codes. 

The difference between SMA and EMA

The main difference between exponential moving averages (EMA) and simple moving averages is their sensitivity to changes in the data used in the calculation. Specifically, EMA gives a higher weight to recent prices and can quickly respond to price movements. The disadvantage is that you may be thrown out during market fluctuations; while SMA gives equal weight to all prices, allowing you to better The disadvantage of understanding the overall trend is that it may be delayed and have high lag, and you may miss a good entry position or trading opportunity. Therefore, exponential moving averages are often considered more suitable for short-term trading, and EMA is also preferred by many traders.

SMA EMA
advantage Strong trend lines, avoid most false signals Short-term signals are more accurate
shortcoming The signal is slow and has strong lag More false signals in volatile market conditions

The picture above shows the recent stock price chart of Tsla. The white line is ema20 and the gray line is sma20.

Moving average application and dual moving average trading

Moving averages are an important analytical tool used to determine current price trends and the likelihood of changes in a given trend, and can be used in a variety of ways.

  1. The simplest usage is to use SMA or EMA to quickly determine whether a security is in an uptrend or downtrend. A rising moving average indicates that the underlying is in a stable upward trend, while a falling moving average indicates that it is in a downward trend.

  2. Dual Moving Average Strategy: Compares a pair of SMA or EMA moving averages, each covering a different time period. If the short-term SMA/EMA is higher than the long-term SMA/EMA, an uptrend is expected; conversely, if the long-term average is above the short-term average, then a downtrend is likely to be expected. Taking SMA as an example, the reference code in backtrader is as follows:

  1. By corroborating each other with the EMA and SMA moving averages in the same time period, we can observe whether the trend has turned.

comminicate

Everyone is welcome to leave messages and follow the WeChat official account for more communication. The latest and most complete articles will be published on the WeChat official account first. WeChat public account: Zhuge Talk

reference

Guess you like

Origin blog.csdn.net/richardzhutalk/article/details/124901835