All indicators

Easy to Use 50/100/200 Day Moving Average Strategy

Oct 11, 2019

Static chart image
SignalsMoving Averages

The 50/100/200 Day Moving Average Strategy tool provides a customizable backtesting framework for evaluating crossover signals between three major Simple Moving Averages (SMA) to identify trend reversals and entry/exit points.

Usage

The Usage section describes how the script can be used to validate trend-following techniques. By default, the strategy initiates a "Buy" signal when the 50-day SMA (Fast) crosses above the 200-day SMA (Slow), commonly known as a Golden Cross. Conversely, it identifies an exit or "Sell" signal when the 50-day SMA crosses below the 200-day SMA, known as a Death Cross.

Users can utilize the three plotted averages to visualize different tiers of trend strength:

  • Fast MA (50): Used for short-to-medium-term momentum.
  • Medium MA (100): Acts as an intermediate filter for trend confirmation.
  • Slow MA (200): Defines the long-term institutional trend.

The strategy is configured to only enter long positions by default, making it suitable for investors focusing on spot equities or long-only portfolios.

Details

The script utilizes the ta.sma function to calculate the Simple Moving Average of the closing price over specified periods. It employs the strategy.risk.allow_entry_in(strategy.direction.long) command to ensure the backtest focuses strictly on upside momentum, filtering out short-selling opportunities.

The execution logic is bound by a timestamp filter, allowing users to define a specific historical starting point for the backtest. This ensures that performance metrics are not skewed by irrelevant historical data or periods where the asset may have behaved differently.

Settings

  • Start Date: Defines the specific day of the month to begin the backtest.
  • Start Month: Defines the specific month to begin the backtest.
  • Start Year: Defines the specific year to begin the backtest.
  • Fast MA Length (50): (Adjustable in code) Sets the lookback period for the fastest moving average.
  • Medium MA Length (100): (Adjustable in code) Sets the lookback period for the intermediate moving average.
  • Slow MA Length (200): (Adjustable in code) Sets the lookback period for the slowest moving average.

FAQ

How do I modify the strategy to use the 100-day MA instead of the 200-day? Users can modify the logic within the script variables or input sections to change the crossover source from the "Slow MA" to the "Medium MA" to test more sensitive signals.

Can I use this strategy for shorting? While the default setting restricts entries to long positions, removing the risk management line in the code allows the strategy to execute both buy and sell-short orders.

How can I access the 50/100/200 Day Moving Average Strategy? You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.

Free indicator

Get free access to this indicator on the platforms below.

TradingView
NinjaTrader
MetaTrader 4/5

Unlock the entire LuxAlgo Library

Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.