NOTE: THE FORMULA IN THE CHART IS NOT PART OF THE CODE
This Pine Script calculates statistical measures for candle partitions based on whether a candle is bullish or bearish and whether the price is above or below an EMA. It evaluates statistical properties such as the Index of Qualitative Variation (IQV) and the Chi-Square (χ²) statistic to assess variations in price action.
Concept of Index of Qualitative Variation (IQV) IQV is a statistical measure used to quantify the diversity or dispersion of categorical variables. In this script, it is used to measure how evenly the four categories of candles (green above EMA, red above EMA, green below EMA, red below EMA) are distributed.
Purpose of IQV in the Script: IQV ranges from 0 to 1, where 0 indicates no variation (one category dominates) and 1 indicates maximum variation (categories are equally distributed). A high IQV suggests balanced distributions of bullish/bearish candles above/below the EMA, indicating market uncertainty or mixed sentiment. A low IQV suggests dominance of a particular candle type, indicating a strong trend. Concept of Chi-Square (χ²) Test Chi-square (χ²) is a statistical test that measures the difference between expected and observed frequencies of categorical data. It assesses whether short-term price behavior significantly deviates from historical trends.
Purpose of Chi-Square in the Script: A high χ² value means that short-term candle distributions are significantly different from historical patterns, indicating potential trend shifts. If χ² exceeds a predefined significance threshold (chi_threshold), an alert (Chi² Alert!) is triggered. It helps traders identify periods where recent price behavior deviates from historical norms, possibly signaling trend reversals or market regime changes. Key Takeaways: IQV helps measure the diversity of price action, detecting whether the market is balanced or trending. Chi-square (χ²) identifies significant deviations in short-term price behavior compared to long-term trends. Both metrics together provide insights into whether the market is stable, trending, or shifting.
The Nasan C-score enhances trend strength by incorporating volatility. It is calculated as:
enhanced_t_s =(𝑡𝑠 × avg_movement x 100)/SMA(𝑐lose)
Key Components: 𝑡𝑠 : Measures trend strength based on price movements relative to EMA. ts=green_EMAup_a+0.5×red_EMAup_a−(0.5×green_EMAdown_a+red_EMAdown_a) avg_movement: The SMA of absolute close-open differences, capturing volatility. Normalization: The division by SMA(close) adjusts the score relative to price levels.
Purpose of the Nasan C-score Enhanced Trend Strength
It amplifies the trend strength value by factoring in volatility (price movement). If price volatility is high, trend strength variations have a greater impact. Volatility-Adjusted Momentum
By scaling 𝑡𝑠 with average movement, the score adjusts to changing price dynamics. Higher price fluctuations lead to a higher score, making trend shifts more prominent.
How It Can Be Used in Trading Higher values of Nasan C-score indicate strong bullish or bearish trends. Comparing it with past values helps determine whether momentum is increasing or fading. Thresholds can be set to identify significant trend shifts based on historical highs and lows.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Để truy cập nhanh vào biểu đồ, hãy thêm tập lệnh này vào mục yêu thích của bạn — tìm hiểu thêm tại đây.
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Để truy cập nhanh vào biểu đồ, hãy thêm tập lệnh này vào mục yêu thích của bạn — tìm hiểu thêm tại đây.
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.