OPEN-SOURCE SCRIPT

Percentile Momentum Indicator

Input Parameters:

lengthPercentile: Defines the period used to calculate the percentile values (default: 30).
lengthMomentum: Defines the period for calculating the Rate of Change (ROC) momentum (default: 10).

Core Logic:

Rate of Change (ROC): The script calculates the ROC of the closing price over the specified period (lengthMomentum).
Percentile Calculations: The script calculates two key percentiles:
percentile_upper (80th percentile of the high prices)
percentile_lower (20th percentile of the low prices)
Percentile Average: An average of the upper and lower percentiles is calculated (avg_percentile).
Trade Signals:

Buy Signal: Triggered when the ROC is positive, the close is above the percentile_lower, and the close is above the avg_percentile.

Sell Signal: Triggered when the ROC is negative, the close is below the percentile_upper, and the close is below the avg_percentile.

Trade State Management:

The script uses a binary state: 1 for long (buy) and -1 for short (sell).
The trade state is updated based on buy or sell signals.

Bar Coloring:

Bars are colored dynamically based on the trade state:
Green for long (buy signal).
Red for short (sell signal).
The same color is applied to the percentile and average percentile lines for visual consistency.
educationalTrend AnalysisVolatility

开源脚本

本着真正的TradingView精神,此脚本的作者已将其开源,以便交易者可以理解和验证它。向作者致敬!您可以免费使用它,但在出版物中重复使用此代码受网站规则约束。 您可以收藏它以在图表上使用。

想在图表上使用此脚本?

免责声明