OPEN-SOURCE SCRIPT
Updated Fear and Greed Index [DunesIsland]

The Fear and Greed Index [DunesIsland] is a sentiment indicator designed to measure the emotions driving the stock market, specifically investor fear and greed. Fear represents pessimism and caution, while greed reflects optimism and risk-taking. This indicator aggregates multiple market metrics to provide a comprehensive view of market sentiment, helping traders and investors gauge whether the market is overly fearful or excessively greedy.How It WorksThe Fear and Greed Index is calculated using four key market indicators, each capturing a different aspect of market sentiment:
Market Momentum (30% weight)
Stock Price Strength (20% weight)
Put/Call Options (30% weight)
Market Volatility (20% weight)
Each component is normalized using a z-score over a 252-day lookback period (approximately one trading year) and scaled to a range of 0 to 100. The final Fear and Greed Index is a weighted average of these four components, with the weights specified above.Key FeaturesIndex Range: The index value ranges from 0 to 100:
Dynamic Plot Color: The plot line changes color based on the index value, visually indicating the current sentiment zone.
Reference Lines: Horizontal lines are plotted at 0, 25, 50, 75, and 100 to represent the different sentiment levels: Extreme Fear, Fear, Neutral, Greed, and Extreme Greed.
How to Interpret
This indicator is a valuable tool for contrarian investors, as extreme readings often precede market reversals. However, it should be used in conjunction with other technical and fundamental analysis tools for a well-rounded view of the market.
Market Momentum (30% weight)
- Measures how the S&P 500 (SPX) is performing relative to its 125-day simple moving average (SMA).
- A higher value indicates that the market is trading well above its moving average, signaling greed.
Stock Price Strength (20% weight)
- Calculates the net number of stocks hitting 52-week highs minus those hitting 52-week lows on the NYSE.
- A greater number of net highs suggests strong market breadth and greed.
Put/Call Options (30% weight)
- Uses the 5-day average of the put/call ratio.
- A lower ratio (more call options being bought) indicates greed, as investors are betting on rising prices.
Market Volatility (20% weight)
- Utilizes the VIX index, which measures market volatility.
- Lower volatility is associated with greed, as investors are less fearful of large market swings.
Each component is normalized using a z-score over a 252-day lookback period (approximately one trading year) and scaled to a range of 0 to 100. The final Fear and Greed Index is a weighted average of these four components, with the weights specified above.Key FeaturesIndex Range: The index value ranges from 0 to 100:
- 0–25: Extreme Fear (red)
- 25–50: Fear (orange)
- 50–75: Neutral (yellow)
- 75–100: Greed (green)
Dynamic Plot Color: The plot line changes color based on the index value, visually indicating the current sentiment zone.
Reference Lines: Horizontal lines are plotted at 0, 25, 50, 75, and 100 to represent the different sentiment levels: Extreme Fear, Fear, Neutral, Greed, and Extreme Greed.
How to Interpret
- Low Values (0–25): Indicate extreme fear, which may suggest that the market is oversold and could be due for a rebound.
- High Values (75–100): Indicate greed, which may signal that the market is overbought and could be at risk of a correction.
- Neutral Range (25–75): Suggests a balanced market sentiment, neither overly fearful nor greedy.
This indicator is a valuable tool for contrarian investors, as extreme readings often precede market reversals. However, it should be used in conjunction with other technical and fundamental analysis tools for a well-rounded view of the market.
Release Notes
This update to the Fear and Greed Index [DunesIsland] introduces alert conditions to enhance its usability for traders. Now, the indicator triggers a Buy Signal when the index falls to 25 or below, indicating an Extreme Fear zone and a potential oversold condition that may present a contrarian buying opportunity. Conversely, a Sell Signal is triggered when the index rises above 75, signaling a Greed zone and a potential overbought condition that may suggest a market top. To set up these alerts in TradingView, add the indicator to your chart, click the Alert button, select "Fear and Greed: Buy Signal" or "Fear and Greed: Sell Signal," choose "Once Per Bar Close" for daily charts, and configure your preferred notification method (e.g., email, SMS, or webhook). These alerts help you act on extreme market sentiment while using the indicator’s dynamic color-coded plot and reference lines to visualize market fear and greed.Release Notes
The Fear and Greed Index [DunesIsland] script has been updated to include Stochastic RSI as a fifth parameter, enhancing its ability to capture market sentiment. Previously, the index was calculated using four components—Market Momentum (S&P 500 vs. 125-day SMA), Stock Price Strength (NYSE net 52-week highs/lows), Put/Call Ratio, and VIX—weighted at 30%, 20%, 30%, and 20%, respectively. The updated script now incorporates Stochastic RSI (based on a 14-period RSI with 14,3 Stochastic parameters), with all five components equally weighted at 20% to ensure balanced contribution. This addition provides a more comprehensive view of market overbought or oversold conditions, while the core logic, normalization process, plotting, reference lines, and alert conditions remain unchanged, maintaining consistency with the original design.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.