OPEN-SOURCE SCRIPT

MadTrend [InvestorUnknown]

The MadTrend indicator is an experimental tool that combines the Median and Median Absolute Deviation (MAD) to generate signals, much like the popular Supertrend indicator. In addition to identifying Long and Short positions, MadTrend introduces RISK-ON and RISK-OFF states for each trade direction, providing traders with nuanced insights into market conditions.

Core Concepts

Median and Median Absolute Deviation (MAD)
  • Median: The middle value in a sorted list of numbers, offering a robust measure of central tendency less affected by outliers.
  • Median Absolute Deviation (MAD): Measures the average distance between each data point and the median, providing a robust estimation of volatility.

Supertrend-like Functionality
  • MadTrend utilizes the median and MAD in a manner similar to how Supertrend uses averages and volatility measures to determine trend direction and potential reversal points.

RISK-ON and RISK-OFF States
  • RISK-ON: Indicates favorable conditions for entering or holding a position in the current trend direction.
  • RISK-OFF: Suggests caution, signaling RISK-ON end and potential trend weakening or reversal.


Calculating MAD
  • The mad function calculates the median of the absolute deviations from the median, providing a robust measure of volatility.




MADTrend Function
  • The MADTrend function calculates the median and MAD-based upper (med_p) and lower (med_m) bands. It determines the trend direction based on price crossing these bands.





Trend Direction and Signals
  • Long Position (direction = 1): When the price crosses above the upper MAD band (med_p).
  • Short Position (direction = -1): When the price crosses below the lower MAD band (med_m).
  • RISK-ON: When the price moves further in the direction of the trend (beyond median +- MAD) after the initial signal.
  • RISK-OFF: When the price retraces towards the median, signaling potential weakening of the trend.


RISK-ON and RISK-OFF States
  • RISK-ON LONG: Price moves above the upper band after a Long signal, indicating strengthening bullish momentum.
  • RISK-OFF LONG: Price falls back below the upper band, suggesting potential weakness in the bullish trend.
  • RISK-ON SHORT: Price moves below the lower band after a Short signal, indicating strengthening bearish momentum.
  • RISK-OFF SHORT: Price rises back above the lower band, suggesting potential weakness in the bearish trend.


Picture below show example RISK-ON periods which can be identified by “cloud”
anlık görüntü
Note: Highlighted areas on the chart indicating RISK-ON and RISK-OFF periods for both Long and Short positions.


Implementation Details

Inputs and Parameters:
  • Source (input_src): The price data used for calculations (e.g., close, open, high, low).
  • Median Length (length): The number of periods over which the median and MAD are calculated.
  • MAD Multiplier (mad_mult): Determines the distance of the upper and lower bands from the median.


Calculations:
  • Median and MAD are recalculated each period based on the specified length.
  • Upper (med_p) and Lower (med_m) Bands are computed by adding and subtracting the scaled MAD from the median.


Visual representation of the indicator on a price chart:
anlık görüntü


Backtesting and Performance Metrics

The MadTrend indicator includes a Backtesting Mode with a performance metrics table to evaluate its effectiveness compared to a simple buy-and-hold strategy.

Equity Calculation:
  • Calculates the equity curve based on the signals generated by the indicator.

Performance Metrics:
  • Metrics such as Mean Returns, Standard Deviation, Sharpe Ratio, Sortino Ratio, and Omega Ratio are computed.
  • The metrics are displayed in a table for both the strategy and the buy-and-hold approach.
  • Note: Due to the use of labels and plot shapes, automatic chart scaling may not function ideally in Backtest Mode.


anlık görüntü


Alerts and Notifications

MadTrend provides alert conditions to notify traders of significant events:
  • Trend Change Alerts
  • RISK-ON and RISK-OFF Alerts - Provides real-time notifications about the RISK-ON and RISK-OFF states for proactive trade management.


Customization and Calibration
  • Default Settings: The provided default settings are experimental and not optimized. They serve as a starting point for users.
  • Parameter Adjustment: Traders are encouraged to calibrate the indicator's parameters (e.g., length, mad_mult) to suit their specific trading style and the characteristics of the asset being analyzed.
  • Source Input: The indicator allows for different price inputs (open, high, low, close, etc.), offering flexibility in how the median and MAD are calculated.


Important Notes
  • Market Conditions: The effectiveness of the MadTrend indicator can vary across different market conditions. Regular calibration is recommended.
    *Backtest Limitations: Backtesting results are historical and do not guarantee future performance.
    *Risk Management: Always apply sound risk management practices when using any trading indicator.
statisticsTrend AnalysisVolatility

Açık kaynak kodlu komut dosyası

Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının yazarı komut dosyasını açık kaynak olarak yayınlamıştır, böylece yatırımcılar betiği anlayabilir ve doğrulayabilir. Yazar çok yaşa! Ücretsiz olarak kullanabilirsiniz, ancak bu kodun yayında yeniden kullanımı Ev kurallarına tabidir. Bir grafikte kullanmak için favorilere ekleyebilirsiniz.

Bu komut dosyasını bir grafikte kullanmak ister misiniz?

Feragatname