All indicators

Example of Code for Moving Average Cross - Changing Colors

Jan 9, 2014

Static chart image
SignalsMoving Averages

The Example of Code for Moving Average Cross - Changing Colors indicator identifies potential trend reversals and shifts in market momentum using a dual exponential moving average (EMA) system with dynamic visual feedback.

Usage

The indicator is primarily used for trend identification and capturing momentum shifts. Users can monitor the relationship between a short-term and long-term EMA to determine the prevailing market direction.

  • Bullish Trend: When the short-term EMA is above the long-term EMA, the lines turn green, indicating bullish momentum.
  • Bearish Trend: When the short-term EMA falls below the long-term EMA, the lines turn red, indicating bearish momentum.
  • Crossovers: A change in color serves as a signal for a potential trend change. The script includes built-in alert functionality to notify users when these crossovers occur on a bar close.

The visual style distinguishes the two averages: the short-term EMA is displayed as a solid line, while the long-term EMA is displayed as a dotted line. A silver fill between the two lines helps visualize the "zone" or gap between different trend timeframes.

Details

This tool is based on methodology associated with trading champion Chuck Hughes, who utilized the 50-period and 100-period EMAs to capture long-term trend changes. The script calculates two Exponential Moving Averages (EMA) and compares their values at every bar.

The logic follows standard crossover mechanics:

  1. EMA Short: Calculates the average price over a shorter lookback period to stay reactive to recent price action.
  2. EMA Long: Calculates the average price over a longer lookback period to provide a baseline for the primary trend.
  3. Color Logic: The color is determined by a conditional check (emaShort >= emaLong). This ensures that the entire structure—both lines and the cloud—updates instantly as the trend oscillates.

Settings

  • Short EMA Length: Determines the period for the faster moving average (default is 50). Increasing this value makes the indicator less sensitive to price fluctuations.
  • Long EMA Length: Determines the period for the slower moving average (default is 100). This serves as the primary trend filter.

FAQ

How do I interpret the different line styles? The solid line represents the short-term EMA, while the dotted line (circles) represents the long-term EMA. When the solid line is above the dotted line, the trend is considered bullish.

Can I use this indicator for scalping or day trading? While the default settings are optimized for long-term trend changes (50/100), the EMA lengths can be adjusted in the settings to suit lower timeframes or faster trading styles.

How can I access the Example of Code for Moving Average Cross - Changing Colors? 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.