OPEN-SOURCE SCRIPT

My TMwP

183
## Indicator Description

This indicator is an enhanced version of the Trend Magic indicator, incorporating a clearly defined pivot line to visually indicate potential trend reversals.

The original Trend Magic indicator leverages two key components:

- **Commodity Channel Index (CCI)**: A momentum-based oscillator developed by Donald Lambert in 1980, which measures the current price relative to its average over a specified period.
- **Average True Range (ATR)**: A volatility indicator that captures market volatility by measuring price movement ranges.

### How the Indicator Works

The Commodity Channel Index (CCI) calculation involves three primary steps:

1. **Typical Price Calculation**
The typical price is the average of each period's high, low, and close prices:
$$
\text{Typical Price} = \frac{\text{High} + \text{Low} + \text{Close}}{3}
$$
*(In this indicator, the built-in variable `hlc3` is used.)*

2. **Simple Moving Average (SMA) of Typical Price**
The indicator calculates an SMA of the typical price over a user-defined period.

3. **CCI Calculation**
Finally, the CCI is computed as the difference between the typical price and its SMA, divided by a multiple of the mean deviation.

### Pivot Line and Trend Reversal

The pivot line added to this enhanced Trend Magic indicator clearly marks the price level at which a trend reversal would occur. Specifically, when the asset's price crosses and closes beyond the SMA of the typical price, a pivot occurs—signaling a potential change in market direction. This pivot line thus provides traders with an intuitive visual reference for identifying critical trend reversal points.

### Customizable Parameters

Users can easily customize key parameters through input settings:

- **CCI Period**: Adjusts sensitivity to momentum shifts.
- **ATR Multiplier**: Modifies volatility responsiveness.
- **ATR Period**: Defines the lookback period for volatility calculations.

By fine-tuning these parameters, you can adapt the indicator to their preferred trading style and market conditions.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.