Pine Script Force Index

Master this unique indicator in TradingView's Pine Script that combines price action and volume to reveal the true driving force behind market movements.

Last Updated on: Expertise: Intermediate

What is the Force Index?

The Force Index (FI), developed by Alexander Elder, is a unique oscillator that measures the strength of buying and selling pressure by combining price movement and volume. Unlike pure momentum indicators that only consider price, Force Index gives greater significance to large price changes that occur on high volume, indicating a strong force pushing the market. It can be positive (bullish force) or negative (bearish force) and oscillates around a zero line.

In Pine Script, Force Index is a powerful tool for confirming trend strength, spotting potential reversals through divergence, and identifying when strong money is entering or leaving the market.

Components and Calculation

The core calculation of the Force Index for a single period is quite simple:

  1. Single Period Force Index:
    `Force Index = Volume * (Current Close - Previous Close)`
    A positive value indicates that buyers are in control (price went up on volume), while a negative value indicates sellers are in control (price went down on volume).
  2. Smoothed Force Index: To make the indicator more useful and reduce noise, the single-period Force Index is usually smoothed using an Exponential Moving Average (EMA) over a specified `length`.
    `Smoothed Force Index = EMA(Force Index, length)`
    Common lengths for smoothing are 1 (raw), 2 (short-term), or 13 (long-term).

This smoothing helps to identify the underlying trend of buying/selling pressure more clearly.

Basic Force Index Implementation in Pine Script

Pine Script v5 provides a straightforward built-in function `ta.fi()` for calculating the Force Index.

//@version=5
indicator("My Force Index Indicator", overlay=false) // overlay=false to plot in a separate pane

// Input for Force Index length (smoothing period for the raw FI)
length = input.int(13, title="FI Length (EMA Smoothing)", minval=1)

// Calculate Force Index using the built-in function
// ta.fi takes the source (usually close) and the length for EMA smoothing
fiValue = ta.fi(close, length)

// Plot the Force Index line
plot(fiValue, title="Force Index", color=color.blue, linewidth=2)

// Plot the Zero Line
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted)

Interpretation: A positive Force Index indicates buying pressure, a negative one indicates selling pressure. The magnitude reflects the strength of that pressure.

Practical Force Index Trading Strategies

1. Trend Confirmation

Force Index is excellent for confirming the strength and direction of a trend, especially when smoothed over a longer period (e.g., 13 periods).

//@version=5
strategy("Force Index Trend Confirmation Strategy", overlay=true)

// Input for Force Index length
length = input.int(13, title="FI Length (EMA Smoothing)", minval=1)

// Calculate Force Index
fiValue = ta.fi(close, length)

// Plot the Force Index line in a separate pane
plot(fiValue, title="Force Index", color.blue, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)

// Define conditions for entries based on consistent FI direction
// Long when FI is positive and rising
longCondition = fiValue > 0 and fiValue > fiValue[1]
// Short when FI is negative and falling
shortCondition = fiValue < 0 and fiValue < fiValue[1]

// Strategy entries/exits
if (longCondition)
    strategy.entry("Long", strategy.long)

if (shortCondition)
    strategy.entry("Short", strategy.short)

2. Zero Line Crossover (Momentum Shift)

Crossovers of the zero line can signal a shift in the dominant force in the market. This is often used for shorter-term signals, especially with a shorter FI length (e.g., 2 periods).

//@version=5
strategy("Force Index Zero Line Crossover Strategy", overlay=true)

// Input for Force Index length (often shorter for crossover signals)
length = input.int(2, title="FI Length (EMA Smoothing)", minval=1)

// Calculate Force Index
fiValue = ta.fi(close, length)

// Plot the Force Index line in a separate pane
plot(fiValue, title="Force Index", color.blue, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)

// Define conditions for entries
longSignal = ta.crossover(fiValue, 0)
shortSignal = ta.crossunder(fiValue, 0)

// Strategy entries/exits
if (longSignal)
    strategy.entry("Long", strategy.long)

if (shortSignal)
    strategy.entry("Short", strategy.short)

3. Force Index Divergence Strategy

Divergence between price and Force Index is a powerful signal, as it suggests a breakdown in the underlying strength of the trend, confirmed by volume. This is often used with the longer-term FI (e.g., 13 periods).

//@version=5
indicator("Force Index Divergence Scanner", overlay=true)

// Input for Force Index length
length = input.int(13, title="FI Length (EMA Smoothing)", minval=1)

// Calculate Force Index
fiValue = ta.fi(close, length)

// Plot Force Index in a separate pane
plot(fiValue, "Force Index", color.blue)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted)

// Simple divergence detection (conceptual, robust detection requires advanced pivot logic)
// This is a simplified example focusing on price vs FI divergence.

// Bullish Divergence (Price lower low, FI higher low)
bullishDivergence = close[2] > close[1] and close[1] > close and fiValue[2] < fiValue[1] and fiValue[1] < fiValue

// Bearish Divergence (Price higher high, FI lower high)
bearishDivergence = close[2] < close[1] and close[1] < close and fiValue[2] > fiValue[1] and fiValue[1] > fiValue

plotshape(bullishDivergence, title="Bullish Divergence", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(bearishDivergence, title="Bearish Divergence", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)

alertcondition(bullishDivergence, "Bullish FI Divergence", "Potential bullish reversal based on Force Index divergence.")
alertcondition(bearishDivergence, "Bearish FI Divergence", "Potential bearish reversal based on Force Index divergence.")

Optimizing Force Index Performance

To get the most from the Force Index in Pine Script:

The "Force" of the Move: The higher the Force Index, the stronger the bullish force. The lower (more negative) the Force Index, the stronger the bearish force. Volume is the key differentiator here.

Common Force Index Pitfalls

Conclusion

The Force Index is a unique and highly insightful technical indicator in Pine Script for TradingView. Its integration of both price change and volume provides a powerful measure of the underlying buying and selling pressure in the market. Whether used for confirming trend strength, identifying momentum shifts through zero-line crossovers, or spotting potential reversals via divergence, the Force Index offers valuable insights. By understanding its calculation, thoughtfully tuning its parameters, and integrating it strategically with other technical analysis tools, you can leverage the Force Index to gain a deeper, volume-confirmed perspective on market dynamics and enhance your trading decisions.