Problem Statement
Moving Averages & Moving Average Crossover
1. Introduction to Moving Averages
A moving average (MA) is a trend-following indicator used in technical analysis to smooth out price data by creating a constantly updated average price. It helps traders identify the direction of the market trend—whether upward, downward, or sideways—by filtering out short-term price fluctuations or “noise.”
The basic principle:
Moving Average = (Sum of Closing Prices over Period) / (Number of Periods)
2. Types of Moving Averages
- Simple Moving Average (SMA) – gives equal weight to all data points in the specified period. For example, a 20-day SMA is the average of the past 20 days’ closing prices.
- Exponential Moving Average (EMA) – gives more weight to recent prices, making it more responsive to new trends. Traders often prefer EMA for short-term trading.
- Weighted Moving Average (WMA) – assigns varying weights to data points, emphasizing more recent values while still considering the entire dataset.
Participants have the freedom to use any one of the above 3 MAs.
3. Purpose and Use in Stock Charts
Moving averages are usually plotted over price charts and used to:
- Identify market trends (rising MA for uptrend, falling MA for downtrend)
- Determine support and resistance levels
- Generate buy or sell signals when combined with price action or other averages
- Smooth out volatility for clearer visualization of underlying price direction
On any asset price chart one can draw moving average of any timeframe/period. The most commonly used moving averages are of 9 days, 10 days, 12 days, 20 days, 26 days, 50 days, 100 days and 200 days. Shorter the time frame more agile is the MA curve and longer the time frame smoother is the MA curve.
4. Moving Average Crossover Concept
A moving average crossover occurs when two moving averages of different timeframes intersect, signaling potential trend reversals or confirmations. A faster (shorter period) moving average reacts quickly to price changes, while a slower (longer period) moving average changes direction more gradually and represents the broader trend.
When the faster MA crosses the slower MA, traders interpret it as a signal:
- Bullish crossover: Short-term MA crosses from below and goes above long-term MA indicating a possible uptrend.
- Bearish crossover: Short-term MA crosses from above and goes below long-term MA indicating a possible downtrend.
Examples: The 50-day MA crossing above the 200-day MA forms a Golden Cross. The 50-day MA crossing below the 200-day MA forms a Death Cross.
5. Types of Moving Average Crossover Strategies
- Single Moving Average Crossover (Price vs MA): A signal occurs when the stock price itself crosses the moving average line.
- Double Moving Average Crossover: Uses two different MAs (e.g., 20-day and 50-day) to capture changes in trend direction.
- Triple Moving Average Crossover: Uses three MAs (e.g., 10, 20, and 50 days) to reduce false signals and provide better confirmation of trend strength.
6. Practical Application in Technical Analysis
Short-term traders (e.g., intraday or swing traders) might use 5-day, 10-day, or 20-day MAs for quick signals. Long-term investors often look at 50-day, 100-day, or 200-day MAs for broader trend identification.
A common setup:
If a 10-day EMA crosses above a 50-day EMA → Buy signal. If it crosses below → Sell or exit signal.
7. Outline of the Competition
The participant(s) is expected to write his/her own code to identify an MA crossover and depending on bullish or bearish crossover the code should generate an entry signal and the participant should devise his/her exit strategy (i.e. % profit or % loss or number of days after entry). The developed code will use last 3 month’s historical stock data on NSE 500 stocks to backtest the code/strategy. Participants are free to use any NSE stock API. Some APIs may be paid. Since we are talking about MAs of days time frame and not minute or hour time frame, the participants have to use end of the day (i.e. closing price at 3:30 pm) closing price. UPSTOX trading platform provides free API in such case. Opening UPSTOX account is free. However, this should be taken as a piece of information and this is in no way a promotion of UPSTOX brokerage.
Some YouTube resources:
The backtest result of a strategy should be tabulated in the following format (participants should include):
- Strategy name / MA types and periods
- Stocks tested (NSE 500 list subset)
- Backtest period (last 3 months)
- Entry criteria
- Exit criteria
- Return, Max drawdown, Win rate, Number of trades