Moving Average Slope to determine market direction
Mar 3, 2021

The Moving Average Slope indicator provides a visual representation of market direction by analyzing the trajectory of a simple moving average to identify trend shifts. It offers traders a streamlined way to determine if a trend is gaining or losing momentum through a dynamic color-coded system based on the angle of price movement.
Usage
The Moving Average Slope is primarily used as a trend-following tool to confirm the prevailing market bias. Traders can use the indicator to filter trades: focusing on long positions when the moving average is green (sloping upward) and short positions when it is red (sloping downward).
Because the script highlights changes in trajectory, it is effective for identifying potential trend reversals or the end of a consolidation phase. While the default period is set to 20 to capture approximately one month of trading data, the length can be adjusted to suit different timeframes or trading styles, such as scalping or long-term swing trading.
Details
The indicator calculates a Simple Moving Average (SMA) based on a user-defined source and length. The slope logic is determined by comparing the current moving average value to its value five bars prior.
- Bullish Trend: If the value of the moving average one bar ago is greater than the value five bars ago, the slope is considered positive, and the line is colored green.
- Bearish Trend: If the value of the moving average one bar ago is less than or equal to the value five bars ago, the slope is considered negative, and the line is colored red.
The script also includes built-in alert functionality that triggers when the slope color changes, allowing users to stay informed of trend shifts without constant chart monitoring.
Settings
- Length: The number of bars used to calculate the Simple Moving Average. Increasing this value produces a smoother line that is less sensitive to short-term price fluctuations.
- Source: The price data point used for the calculation (e.g., Close, Open, High, Low).
- Offset: Shifts the moving average plot forward or backward in time on the chart.
FAQ
How do I interpret the color changes on the Moving Average Slope?
A change from red to green indicates that the moving average has begun to slope upward, suggesting a bullish shift. Conversely, a change from green to red indicates a downward slope, suggesting a bearish shift.
Can I use this indicator for automated alerts?
Yes, the script includes alert conditions that trigger specifically when the trend changes direction, which can be configured to notify you once per bar close.
How can I access the Moving Average Slope?
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.
Unlock the entire LuxAlgo Library
Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.