OPEN-SOURCE SCRIPT
Aggiornato MA Ratio Weighted Trend System I [InvestorUnknown]

The MA Ratio Weighted Trend System I combines slow and fast indicators to identify stable trends and capture potential market turning points. By dynamically adjusting the weight of fast indicators based on the Moving Average Ratio (MAR), the system aims to provide timely entry and exit signals while maintaining overall trend stability through slow indicators.
Slow and Fast Indicators with Dynamic Weighting
Slow Indicators: Designed for stable trend identification, these indicators maintain a constant weight in the overall signal calculation. They include:
Fast Indicators: Aim to detect rapid market changes and potential turning points. Their weights are dynamically adjusted based on the absolute value of the Moving Average Ratio (MAR). Fast indicators include:
Dynamic Weighting Mechanism:
Moving Average Ratio (MAR) is calculated as the ratio of the price to its moving average, minus one (for simplicity and visualization).
Weight Calculation
Fast indicator weights are determined based on the absolute value of MAR, possibly with an offset to avoid scenarios where MAR follows rapid price reversals too closely:
Pine Script®
Threshold-Based vs. Continuous Weighting:
Offset Mechanism
The offset parameter shifts the MAR used for weighting by a certain number of bars. This helps avoid situations where the MAR follows sudden price movements too closely, preventing fast indicators from failing to provide timely exit signals.

Signal Calculation
The final signal is a weighted average of the slow and fast indicators:
Pine Script®
Backtesting and Performance Metrics
Enables users to test the indicator's performance over historical data, comparing it to a buy-and-hold strategy.

Alerts
Set up alerts for when the signal crosses above or below the thresholds.
Pine Script®
Important Notes
Slow and Fast Indicators with Dynamic Weighting
Slow Indicators: Designed for stable trend identification, these indicators maintain a constant weight in the overall signal calculation. They include:
- DMI For Loop (Directional Movement Index)
- CCI For Loop (Commodity Channel Index)
- Aroon For Loop
Fast Indicators: Aim to detect rapid market changes and potential turning points. Their weights are dynamically adjusted based on the absolute value of the Moving Average Ratio (MAR). Fast indicators include:
- ZLEMA For Loop (Zero-Lag Exponential Moving Average)
- IIRF For Loop (Infinite Impulse Response Filter)
Dynamic Weighting Mechanism:
Moving Average Ratio (MAR) is calculated as the ratio of the price to its moving average, minus one (for simplicity and visualization).
Weight Calculation
Fast indicator weights are determined based on the absolute value of MAR, possibly with an offset to avoid scenarios where MAR follows rapid price reversals too closely:
// Function to calculate weights based on MAR
f_mar_weights(series float mar, simple int offset, simple float weight_thre) =>
o_mar = math.abs(mar[offset])
float fast_weight = 0
float slow_weight = 1
if o_mar != 0
if weight_thre > 0
if o_mar <= weight_thre
fast_weight := o_mar
else
fast_weight := o_mar
[fast_weight, slow_weight]
Threshold-Based vs. Continuous Weighting:
- Threshold-Based: Fast indicators receive weight only when the absolute MAR exceeds a user-defined threshold (weight_thre).
- Continuous: By setting weight_thre to zero, fast indicators always receive some weight, though this may increase false signals.
Offset Mechanism
The offset parameter shifts the MAR used for weighting by a certain number of bars. This helps avoid situations where the MAR follows sudden price movements too closely, preventing fast indicators from failing to provide timely exit signals.
Signal Calculation
The final signal is a weighted average of the slow and fast indicators:
// Calculate Signal (as weighted average)
float sig = math.round(((DMI*slow_w) + (CCI*slow_w) + (Aroon*slow_w) + (ZLEMA*fast_w) + (IIRF*fast_w)) / (3*slow_w + 2*fast_w), 2)
Backtesting and Performance Metrics
Enables users to test the indicator's performance over historical data, comparing it to a buy-and-hold strategy.
Alerts
Set up alerts for when the signal crosses above or below the thresholds.
alertcondition(long_alert, "LONG (MAR Weighted Trend System)", "MAR Weighted Trend System flipped ⬆LONG⬆")
alertcondition(short_alert, "SHORT (MAR Weighted Trend System)", "MAR Weighted Trend System flipped ⬇Short⬇")
Important Notes
- Customization: Due to the experimental nature of this indicator, users are strongly encouraged to adjust and calibrate the settings to align with their trading strategies and market conditions.
- Default Settings Disclaimer: The default settings are not optimized or recommended for any specific use and serve only as placeholders for the indicator's publication.
- Backtest Results Disclaimer: Historical backtest results are not indicative of future performance. Market conditions change, and past results do not guarantee future outcomes.
Note di rilascio
Updated the code to pinescript v6, added backtesting library v2 with more backtesting functions and removed old backtesting functions from the codeNote di rilascio
Updated the code to pinescript v6, added backtesting library v2 with more backtesting functions and removed old backtesting functions from the codeScript open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
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.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
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.