The Trend Angle Indicator is designed to measure the strength of a trend by calculating the angle of the trend. Specifically, it computes the angle of a Simple Moving Average (SMA) over a specified length and then applies an Exponential Moving Average (EMA) to the angle for smoothing. This approach provides a clear indication of the trend's direction and intensity. It also includes customizable alerts for significant changes in the trend angle and zero-line crossings, making it a robust tool for traders seeking to gauge market momentum.
Key Features - **Trend Angle Calculation**: Measures the trend's angle, providing insights into trend direction and strength. - **SMA and EMA**: Uses SMA for the base calculation and EMA for smoothening the angle values. - **Visual Trend Indication**: Visually indicates uptrends and downtrends with customizable colors - red and green. - **Alerts**: Configurable alerts for significant changes in trend angle and zero-line crossings.
Calculation Methodology
1. **Simple Moving Average (SMA):** - The script calculates the SMA of the close price over a user-defined `input_length`.
2. **Angle Calculation:** - The height of the trend is calculated by subtracting the SMA value from the SMA value `input_length` bars ago. A higher angle value indicates a stronger trend. - The angle in degrees is obtained using the arctangent function: \[ \text{Angle} = \text{atan}(\frac{\text{height}}{\text{input\_length}}) \times \frac{180}{\pi} \]
3. **Exponential Moving Average (EMA):** - Applies an EMA to the calculated angle to smooth out the values based on a user-defined `input_ma_length`.
4. **Trend Detection:** The color of the angle plot and filled area provide a quick visual representation of the current trend direction - The trend angle changes are monitored and visualized with color-coded plots. - Uptrend: Angle >= 0 uses `upColor` (green). - Downtrend: Angle < 0 uses `downColor` (red).
#### Using the Indicator
1. **Adding the Indicator:** - Add the indicator to your TradingView chart by selecting it from the Pine Script library or by pasting the script into the Pine Script editor.
2. **Inputs:** - **Length**: Defines the period for the SMA calculation. - **MA Length**: Sets the period for the EMA smoothing. - **Angle Change Threshold (degrees)**: Defines the threshold for significant angle change alerts. - **Color Candles**: Optionally colorizes the price candles based on the angle's trend direction.
3. **Customizing Plots:** - **Angle Plot**: Displays the EMA of the trend angle. The color changes based on whether the trend is up or down. - **Zero Line**: A horizontal line at zero to easily visualize crossings that signify a change in trend direction. - **Fill Color**: Fills the area above/below the zero line with colors representing the direction of the trend.
4. **Setting Alerts:** - **Cross Above Zero**: Triggers an alert when the trend angle crosses above zero, indicating a potential start of an uptrend. - **Cross Below Zero**: Triggers an alert when the trend angle crosses below zero, indicating a potential start of a downtrend. - **Significant Angle Change**: Alerts when the angle change exceeds the user-defined threshold, highlighting significant trend changes.
#### Example Usage
To use and customize the Trend Angle Indicator on your chart:
1. **Add to Chart**: Apply the indicator from the TradingView library or by pasting the script into the Pine Script editor. 2. **Configure Inputs**: - Adjust the `Length` to set the period for the SMA. - Set the `MA Length` for the EMA smoothing. - Define the `Angle Change Threshold` for receiving alerts on significant changes. 3. **Display Customization**: - Enable `Color Candles` to have the price candles reflect the trend direction. 4. **Set Alerts**: - Use the alert conditions provided to get notified about critical events like zero line crossings or significant angle changes.