OPEN-SOURCE SCRIPT

Demand Index

66
##Description:
This indicator is a precise Pine Script replica of the "Demand Index" (Study ID 139) as found in the Sierra Chart trading platform.

Originally developed by James Sibbet, the Demand Index combines price and volume data to measure buying and selling pressure. It is often considered a leading indicator, anticipating price trend changes by identifying divergences between the price action and the volume flow.

##Key Features & Formula Logic

This script strictly follows the official documentation provided by Sierra Chart to ensure the values match the original platform as closely as possible.

Specific calculation details included in this port:

- P(HL2C): Uses the weighted average (High + Low + 2*Close).

- Range Calculation: Uses a Moving Range based on Max(High, 2) - Min(Low, 2).

- The H0/L0 Factor: A unique characteristic of the Sierra Chart formula is the use of H0 and L0 (the High and Low of the first loaded bar in history) to scale the volatility exponent. This script replicates that behavior.

Note: Because H0 and L0 depend on the start of the loaded data, values may shift slightly if the amount of historical data on your chart changes. This is consistent with how the study behaves in Sierra Chart.

- Complex Weighting: Calculates "Buy Power" and "Sell Power" using the specific exponential decay formula outlined in SC ID 139.

##Settings (Inputs)

- Buy/Sell Power Length (nBS): Length for smoothing Volume and Range (Default: 19).

- Buy/Sell Power MA Length: Length for the smoothing of the calculated Buy/Sell Power (Default: 19).

- Demand Index MA Length: Length for the final Simple Moving Average (SMA) of the Demand Index (Default: 19).

- MA Type: Choose the smoothing algorithm for intermediate steps (EMA, SMA, WMA, RMA). Default is EMA.

##How to Trade / Interpret

- Divergence: The most powerful signal. If price makes a new High but the Demand Index fails to reach a new High, it suggests Buying Power is weakening (Bearish Divergence). Conversely for Bullish Divergence.

- Zero Line Cross: A cross above zero indicates Buy Power > Sell Power (Bullish). A cross below zero indicates Sell Power > Buy Power (Bearish).

Disclaimer: This script is for educational and analytical purposes only. It is a code conversion based on public documentation of Sierra Chart Study ID 139.

Sierra Chart, best trading software, EVER!
With the best datafeet. Denali Exchange Data Feed.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.