OPEN-SOURCE SCRIPT

CauchyTrend [InvestorUnknown]

The CauchyTrend is an experimental tool that leverages a Cauchy-weighted moving average combined with a modified Supertrend calculation. This unique approach provides traders with insight into trend direction, while also offering an optional ATR-based range analysis to understand how often the market closes within, above, or below a defined volatility band.


Core Concepts

Cauchy Distribution and Gamma Parameter
  • The Cauchy distribution is a probability distribution known for its heavy tails and lack of a defined mean or variance. It is characterized by two parameters: a location parameter (x0, often 0 in our usage) and a scale parameter (γ, "gamma").
  • Gamma (γ): Determines the "width" or scale of the distribution. Smaller gamma values produce a distribution more concentrated near the center, giving more weight to recent data points, while larger gamma values spread the weight more evenly across the sample.
  • In this indicator, gamma influences how much emphasis is placed on values closer to the current price versus those further away in time. This makes the resulting weighted average either more reactive or smoother, depending on gamma’s value.




captura
captura
A chart showing different Cauchy PDFs with various gamma values, illustrating how gamma affects the weight distribution.

Cauchy-Weighted Moving Average (CWMA)
  • Using the Cauchy PDF, we calculate normalized weights to create a custom Weighted Moving Average. Each bar in the lookback period receives a weight according to the Cauchy PDF. The result is a Cauchy Weighted Average (cwm_avg) that differs from typical moving averages, potentially offering unique sensitivity to price movements.




Supertrend with a Cauchy Twist
  • The indicator integrates a modified Supertrend calculation using the cwm_avg as its reference point. The Supertrend logic typically sets upper and lower bands based on volatility (ATR), and flips direction when price crosses these bands.
  • In this case, the Cauchy-based average replaces the usual baseline, aiming to capture trend direction via a different weighting mechanism.
  • When price closes above the upper band, the trend is considered bullish; closing below the lower band signals a bearish trend.


ATR Stats Range (Optional)
Beyond the fundamental trend detection, the indicator optionally computes ATR-based stats to understand price distribution relative to a volatility corridor centered on the cwm_avg line:
  • Volatility Range:
  • Defined as cwm_avg ± (ATR * atr_mult), this range creates upper and lower bands. Turning on atr_stats computes how often the daily close falls: Within the range, Above the upper ATR boundary, Below the lower ATR boundary, Within the range but above cwm_avg, Within the range but below cwm_avg
  • These statistics can help traders gauge how the market behaves relative to this volatility envelope and possibly identify if the market tends to revert to the mean or break out more often.


captura

Backtesting and Performance Metrics
The code is integrated with a backtesting library that allows users to assess strategy performance historically:
  • Equity Curve Calculation: Compares CauchyTrend-based signals against the underlying asset.
  • Performance Metrics Table: Once enabled, displays key metrics such as mean returns, Sharpe Ratio, Sortino Ratio, and more, comparing the strategy to a simple Buy & Hold approach.


Alerts and Notifications
The indicator provides Alerts for key events:
  • Long Alert: Triggered when the trend flips bullish.
  • Short Alert: Triggered when the trend flips bearish.


Customization and Calibration
Important: The default parameters are not optimized for any specific instrument or time frame. Traders should:
  • Adjust the length and gamma parameters to influence how sharply or broadly the cwm_avg reacts to price changes.
  • Tune the atr_len and atr_mult for the Supertrend logic to better match the asset’s volatility characteristics.
  • Experiment with atr_stats on/off to see if that additional volatility distribution information provides helpful insights.

Traders may find certain sets of parameters that align better with their preferred trading style, risk tolerance, or asset volatility profile.

Disclaimer: This indicator is for educational and informational purposes only. Past performance in backtesting does not guarantee future results. Always perform due diligence, and consider consulting a qualified financial advisor before trading.
Moving AveragesstatisticsTrend Analysis

Script de código aberto

No verdadeiro espírito do TradingView, o autor desse script o publicou como código aberto, para que os traders possam compreendê-lo e analisá-lo. Parabéns ao autor! Você pode usá-lo gratuitamente, mas a reutilização desse código em publicações é regida pelas Regras da Casa. Você pode favoritá-lo para usá-lo em um gráfico.

Quer usar esse script no gráfico?

Aviso legal