OPEN-SOURCE SCRIPT
CUSUM Peaks & Troughs with Drift

This script implements an Improved CUSUM (Cumulative Sum) Peaks & Troughs with Drift indicator. Here's a breakdown of how it works:
Input Parameters:
cusumThreshold: Threshold value for detecting peaks and troughs.
cusumDrift: Drift value used to adjust the CUSUM calculation.
movingAverageLength: Length of the moving average used as a reference for deviation calculation.
Moving Average Calculation:
Calculates the simple moving average (SMA) of the closing prices over a specified length.
Price Deviation Calculation:
Computes the deviation of the closing price from the moving average.
CUSUM Calculation with Drift:
Utilises cumulative sum (CUSUM) calculations with drift adjustment.
Tracks positive and negative deviations from the moving average, considering the specified drift value.
Peak and Trough Detection:
Detects peaks and troughs based on the predefined thresholds (cusumThreshold).
Resets the CUSUM values when peaks or troughs are detected.
Plotting:
Plots shapes (triangles) above the bars for peaks and below the bars for troughs.
Optionally, you can uncomment the lines to visualise the CUSUM values and the zero line for reference.
This indicator helps identify potential turning points or reversals in the price action by detecting peaks (high points) and troughs (low points) in the cumulative sum of price deviations from the moving average, considering drift to adapt to underlying trends in the data.
Input Parameters:
cusumThreshold: Threshold value for detecting peaks and troughs.
cusumDrift: Drift value used to adjust the CUSUM calculation.
movingAverageLength: Length of the moving average used as a reference for deviation calculation.
Moving Average Calculation:
Calculates the simple moving average (SMA) of the closing prices over a specified length.
Price Deviation Calculation:
Computes the deviation of the closing price from the moving average.
CUSUM Calculation with Drift:
Utilises cumulative sum (CUSUM) calculations with drift adjustment.
Tracks positive and negative deviations from the moving average, considering the specified drift value.
Peak and Trough Detection:
Detects peaks and troughs based on the predefined thresholds (cusumThreshold).
Resets the CUSUM values when peaks or troughs are detected.
Plotting:
Plots shapes (triangles) above the bars for peaks and below the bars for troughs.
Optionally, you can uncomment the lines to visualise the CUSUM values and the zero line for reference.
This indicator helps identify potential turning points or reversals in the price action by detecting peaks (high points) and troughs (low points) in the cumulative sum of price deviations from the moving average, considering drift to adapt to underlying trends in the data.
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。