PINE LIBRARY
Aggiornato

trend_magic

169
Trend Magic Library
This script defines a custom Pine Script library named "trend_magic" that implements a Trend Magic indicator, a hybrid technical tool combining CCI (Commodity Channel Index) and ATR (Average True Range) to dynamically track trend direction and strength.

🔧 Key Components:
🔹 Function: trend_magic(...)
This function takes four parameters:

src: The source price (e.g., close)

cci_periode: Period for the CCI calculation

atr_coeff: Multiplier for the ATR to define bands

atr_periode: Period used to calculate the ATR (via SMA of true range)

📈 Logic Inside the Function:
ATR Calculation:

ATR = ta.sma(ta.tr, atr_periode): Calculates the ATR using a simple moving average of the True Range.

Band Levels:

upT = low - ATR * atr_coeff: Lower boundary (support-like)

downT = high + ATR * atr_coeff: Upper boundary (resistance-like)

Trend Calculation:

If CCI is positive, the trend is calculated as the maximum of the previous trend or the current lower band (upT).

If CCI is negative, the trend is the minimum of the previous trend or the current upper band (downT).

This logic makes the trend "stick" in one direction until a reversal condition is met.

Trend Direction (dir):

Set to 1 (bullish) if trend is rising, -1 (bearish) if falling, or remains unchanged otherwise.

Note di rilascio
v2

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.