This is a simple moving average convergence/divergence (MACD) script that allows investors to
- Identify the market entry points for buying or selling
- Compare their profit or losses from buying and selling based on the MACD signals to a simple buy-hold-sell position based on historical financial data.
One of the two methods can be selected to compute the MACD histogram.
| Methods | Formula | Assumptions |
|---|---|---|
| Simple Moving Average (SMA) | ![]() |
|
| Exponential Moving Average (EMA) | ![]() |
![]() |
The MACD line is calculated as follow:

which is used to calculate the signal line:

The signal line serves as a trigger for buy and sell signals. When the signal line crosses
Over the MACD line, a buy signal will be indicated.Under the MACD line, a sell signal will be indicated.
3 stock exchanges' historical financial datas are provided for computation.
- CAC40 for the period of 1998 to 2021
- FTSE100 for the period of 1998 to 2021, and
- SPY for the period of 2016 to 2021




