Bars Since MA Cross Can Help Trend Following
Nov 17, 2022

The Bars Since MA Cross indicator counts the number of bars since a crossover between two moving averages, providing a visual representation of trend duration and maturity.
Usage
The Bars Since MA Cross indicator is primarily used to identify the "age" of a market trend. Unlike standard moving average crossovers that simply show the point of change, this tool tracks how long a specific condition has persisted.
- Positive Values: When the fast moving average is above the slow moving average, the indicator plots positive values (green bars/area), indicating the length of the bullish phase.
- Negative Values: When the fast moving average is below the slow moving average, the indicator plots negative values (red bars/area), indicating the length of the bearish phase.
- Identifying Divergences: Traders can look for decreasing peaks in the bar count during successive price highs or lows, which may suggest a weakening trend.
- Trend Maturity: Exceptionally high or low readings relative to historical norms can signal that a move is "long in the tooth" and may be due for a reversal or consolidation.
Details
The script functions by calculating two user-defined moving averages and comparing their relative positions. Every time a crossover occurs, an internal counter resets to zero. As long as the relationship remains the same (e.g., Fast > Slow), the counter increments (or decrements for bearish phases) by one for every new bar on the chart.
By default, the script utilizes an 8-period and 21-period Exponential Moving Average (EMA). However, the implementation allows for mixing different types of averages, such as comparing a fast WMA against a slow SMA, offering flexibility for various trend-following strategies.
Settings
Fast Average
- Length: Sets the period for the fast-moving average (minimum 2).
- Price: Determines the source data (e.g., close, open, hl2) for the fast average.
- Method: Selects the calculation type (SMA, EMA, SMMA, WMA, or VWMA).
Slow Average
- Length: Sets the period for the slow-moving average (minimum 2).
- Price: Determines the source data for the slow average.
- Method: Selects the calculation type (SMA, EMA, SMMA, WMA, or VWMA).
Color Settings
- Above Zero Color: Sets the color for bullish trend duration.
- Below Zero Color: Sets the color for bearish trend duration.
- Transparency Percent: Adjusts the transparency level of the plotted area.
FAQ
How do I access the Bars Since MA Cross indicator?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
Can I use different types of moving averages together?
Yes, the indicator allows you to independently select the method for both the fast and slow averages. For example, you can compare an 8-period EMA to a 21-period SMA.
Does the counter reset automatically?
The counter resets to zero whenever a "Bullish Cross" (Fast crosses over Slow) or a "Bearish Cross" (Fast crosses under Slow) is detected.
Free indicator
Get free access to this indicator on the platforms below.
Unlock the entire LuxAlgo Library
Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.