Indicator · Pine Script v6 · Own pane

Fear and Greed Indicator

by rubbermetal· code credited to claygrace74

Fear and Greed Indicator combines five proxies into one 0 to 100 sentiment score in a separate pane: RSI with rate of change, inverted ATR, a market index read from a daily request, price position within Bollinger Bands, and distance from the recent high.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code125
Settings9inputs
LicenceMPL-2.0
Last update4 months ago10 Jun 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

125 lines of Pine Script v6 from Fear and Greed.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

Fear and Greed.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © claygrace74

//@version=6
indicator("Fear and Greed Indicator", shorttitle="FGI", overlay=false)

// ==================== Component Settings ====================
var comp_group = "Component Settings"
rsiPeriod  = input.int(14, "RSI Period", minval=1, group=comp_group)
rocPeriod  = input.int(10, "ROC Period", minval=1, group=comp_group)
atrPeriod  = input.int(14, "ATR Period", minval=1, group=comp_group)
normLen    = input.int(100, "Normalization Lookback", minval=20, tooltip="Period to calculate dynamic min/max for normalization", group=comp_group)

// ==================== Market Reference ====================
var mkt_group = "Market Reference"
ticker     = input.symbol("CMC200", "Market Index Symbol", group=mkt_group)
bbLen      = input.int(20, "Bollinger Band Length (Breadth Proxy)", minval=5, group=mkt_group)
bbMult     = input.float(2.0, "Bollinger Band Multiplier", minval=0.5, step=0.5, group=mkt_group)

// ==================== Display Settings ====================
var disp_group = "Display Settings"
i_showZoneLabels = input.bool(true, "Show Zone Labels", group=disp_group)
i_smoothLen      = input.int(3, "Output Smoothing", minval=1, maxval=10, group=disp_group)

// ==================================================================================
// Dynamic Normalization — scales any value to 0-100 using its own recent range
// ==================================================================================
f_normalize(src, len) =>
    hi = ta.highest(src, len)
    lo = ta.lowest(src, len)
    hi == lo ? 50.0 : (src - lo) / (hi - lo) * 100

// ==================================================================================
// Component Calculations
// ==================================================================================

// 1. Momentum: RSI (already 0-100) + normalized ROC
rsi = ta.rsi(close, rsiPeriod)
roc = ta.roc(close, rocPeriod)
roc_norm = f_normalize(roc, normLen)
momentum = (rsi + roc_norm) / 2

// 2. Volatility: ATR normalized to recent range (high ATR = fear, low ATR = greed)
atr_val = ta.atr(atrPeriod)
atr_norm = f_normalize(atr_val, normLen)
volatility = 100 - atr_norm  // Invert: low vol = greed, high vol = fear

// 3. Market Performance: external index price position in its recent range
mkt_close = request.security(ticker, "D", close, lookahead=barmerge.lookahead_off, ignore_invalid_symbol=true)
mkt_perf = not na(mkt_close) ? f_normalize(mkt_close, normLen) : 50.0

// 4. Price Breadth Proxy: where price sits relative to Bollinger Bands
// Near upper band = greed, near lower band = fear
bb_basis = ta.sma(close, bbLen)
bb_dev   = ta.stdev(close, bbLen) * bbMult
bb_upper = bb_basis + bb_dev
bb_lower = bb_basis - bb_dev
bb_pos   = bb_upper == bb_lower ? 50.0 : (close - bb_lower) / (bb_upper - bb_lower) * 100

// 5. Safe Haven Demand Proxy: distance from recent high
// Near all-time high = greed, far from it = fear
recentHigh = ta.highest(high, normLen)
highDist   = recentHigh > 0 ? (close / recentHigh) * 100 : 50.0

// ==================================================================================
// Composite Fear & Greed Index (0-100)
// ==================================================================================
// Weights: momentum 25%, volatility 25%, market perf 20%, breadth 15%, safe haven 15%
raw_fgi = momentum * 0.25 + volatility * 0.25 + mkt_perf * 0.20 + bb_pos * 0.15 + highDist * 0.15
fgi     = ta.sma(raw_fgi, i_smoothLen)

// Zone classification
zone = fgi >= 80 ? "EXTREME GREED" : fgi >= 60 ? "GREED" : fgi >= 40 ? "NEUTRAL" : fgi >= 20 ? "FEAR" : "EXTREME FEAR"
zoneColor = fgi >= 80 ? color.new(color.lime, 0) : fgi >= 60 ? color.new(color.green, 20) : fgi >= 40 ? color.new(color.gray, 20) : fgi >= 20 ? color.new(color.orange, 20) : color.new(color.red, 0)

// Zone transitions
zonePrev = fgi[1] >= 80 ? "EXTREME GREED" : fgi[1] >= 60 ? "GREED" : fgi[1] >= 40 ? "NEUTRAL" : fgi[1] >= 20 ? "FEAR" : "EXTREME FEAR"
zoneChanged = zone != zonePrev

// ==================================================================================
// Grid Layout
// ==================================================================================
h100 = hline(100, "100", color=color.new(color.gray, 80))
h80  = hline(80, "Extreme Greed", color=color.new(color.lime, 50), linestyle=hline.style_dashed)
h60  = hline(60, "Greed",         color=color.new(color.green, 50), linestyle=hline.style_dotted)
h40  = hline(40, "Fear",          color=color.new(color.orange, 50), linestyle=hline.style_dotted)
h20  = hline(20, "Extreme Fear",  color=color.new(color.red, 50), linestyle=hline.style_dashed)
h0   = hline(0, "0", color=color.new(color.gray, 80))

// Zone fills
fill(h80, h100, color=color.new(color.lime, 90))
fill(h60, h80,  color=color.new(color.green, 92))
fill(h40, h60,  color=color.new(color.gray, 95))
fill(h20, h40,  color=color.new(color.orange, 92))
fill(h0,  h20,  color=color.new(color.red, 90))

// ==================================================================================
// Plots
// ==================================================================================

// FGI line with gradient coloring
fgiColor = color.from_gradient(fgi, 10, 90, color.red, color.lime)
plot(fgi, "Fear & Greed Index", color=fgiColor, linewidth=2)

// 50 midline reference
hline(50, "Midline", color=color.new(color.white, 70), linestyle=hline.style_solid)

// Zone transition markers
plotshape(zoneChanged and fgi > fgi[1], style=shape.triangleup,   location=location.bottom, color=color.green, text="Zone", textcolor=color.green, size=size.tiny, title="Zone Shift Up")
plotshape(zoneChanged and fgi < fgi[1], style=shape.triangledown, location=location.top,    color=color.red,   text="Zone", textcolor=color.red,   size=size.tiny, title="Zone Shift Down")

// Zone label table
var tbl = table.new(position.top_right, 1, 1, bgcolor=color.new(color.black, 50), border_width=1, border_color=color.new(color.gray, 50))

if i_showZoneLabels and barstate.islast
    table.cell(tbl, 0, 0, zone + " (" + str.tostring(fgi, "#.0") + ")", bgcolor=zoneColor, text_color=color.white, text_size=size.small)

// ==================================================================================
// Alert Conditions
// ==================================================================================
alertcondition(ta.crossover(fgi, 80),  "Entering Extreme Greed", "FGI crossed above 80 — extreme greed territory")
alertcondition(ta.crossunder(fgi, 20), "Entering Extreme Fear",  "FGI crossed below 20 — extreme fear territory")
alertcondition(ta.crossover(fgi, 50),  "FGI Above 50",           "Fear & Greed crossed above neutral midline")
alertcondition(ta.crossunder(fgi, 50), "FGI Below 50",           "Fear & Greed crossed below neutral midline")
alertcondition(zoneChanged,            "Zone Changed",            "Fear & Greed moved to a new zone")

Overview

Each component is scaled to its own recent range, weighted, and smoothed. Optional labels mark zones. The default index symbol is a crypto market cap index, so it suits crypto best.

Details

Published by

rubbermetal on GitHub

Code credit

claygrace74, as written in the script's header

Draws

Separate pane below the chart

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
RSI Periodint14rsiPeriod
ROC Periodint10rocPeriod
ATR Periodint14atrPeriod
Normalization Lookbackint100normLen
Market Index SymbolsymbolCMC200ticker
Bollinger Band Length (Breadth Proxy)int20bbLen
Bollinger Band Multiplierfloat2.0bbMult
Show Zone Labelsbooltruei_showZoneLabels
Output Smoothingint3i_smoothLen
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

TTM Squeeze

by Alorse
330 stars

This indicator plots a TTM Squeeze momentum oscillator in a separate pane. It compares a Bollinger Band offset to a Keltner Channel offset and marks the zero line white when the difference is non-negative and black when the bands are inside the channel. A line

Indicator v5 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of TTM Squeeze

Function - Logistic Equation

by ricardosantos79
261 stars

Calculates dynamic modeling values by applying a mathematical logistic differential equation to price change over a specified lookback length. It measures price momentum relative to the recent high-low price range. The script plots positive and negative logist

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 years ago · None stated GitHub repository of Function - Logistic Equation
228 stars

This indicator detects a Bollinger Band squeeze when the bands sit inside Keltner Channels, marking low volatility. It plots red dots during a squeeze and green dots when the bands are outside, in a separate pane. An optional histogram shows momentum as the cl

Indicator v6 Volatility & bandsOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Bollinger Band Squeeze Detector

MACD-V

by harryguiacorn
220 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V
147 stars

This indicator generates trade entry signals and target levels optimized for 1-hour timeframes, designed for external signal extraction. It calculates 7-period and 16-period EMAs alongside 10-period RSI and ATR filters. Long signals occur when the fast EMA cro

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Signal Strategy 100 Candles of 1H Timeframe

Bubbles Indicator

by capissimo
114 stars

The Bubbles Indicator measures volatility squeezes and expansion bursts using Bollinger Bands combined with a sinusoid oscillator and RSI divergence. It processes price data through scaled Bollinger Bands to highlight volatility changes while confirming trend

Indicator v4 Volatility & bandsOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of Bubbles Indicator

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers