Skip to main content

OBV Strategy

Discover our OBV Strategy PineScript template, designed for traders seeking to use OBV indicators. Easily backtest on TradingView and live execute this template on AlgoTest.
Adjusting inputs like Length, target points, and stop loss points to suit your trading preferences.

OBV Indicator Pinescript

//@version=5
strategy("OBV Strategy", overlay=true)

// Input parameters
length = input.int(14, title="Length")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")

// Initialize OBV variable
var float obv_value = na

// Calculate OBV
obv_value := nz(obv_value[1]) + (close - close[1]) * (volume > volume[1] ? 1 : volume < volume[1] ? -1 : 0)

// Strategy logic
long_condition = ta.crossover(obv_value, ta.sma(obv_value, length))
short_condition = ta.crossunder(obv_value, ta.sma(obv_value, length))

// Plot OBV
plot(obv_value, color=color.blue, title="OBV")

// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels
long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

Mastering the OBV Indicator

History of the OBV Indicator

The On-Balance Volume (OBV) indicator was developed by Joseph Granville in the early 1960s and was first introduced in his book "Granville's New Key to Stock Market Profits." The OBV is a momentum indicator that uses volume flow to predict changes in stock price.

What is the OBV Indicator?

On-Balance Volume (OBV) is a cumulative indicator that relates volume to price change. OBV is designed to show whether volume is flowing into or out of a security. The theory behind OBV is based on the distinction between smart money -- presumably the institutional investors -- and less sophisticated retail investors. As a stock's price increases, volume increases as well, suggesting a confirmation of the trend.

Best Use Cases for OBV Indicator

  1. Trend Confirmation: OBV can be used to confirm an asset's price trend or warn of potential reversals. If the price of a stock is rising but OBV is declining, this could indicate a potential price drop.

  2. Breakouts: OBV is often used to predict when a stock is about to experience a breakout. If OBV increases rapidly without a corresponding price change, it may indicate that the price will catch up soon.

  3. Divergence: Divergence between OBV and price can signal a potential reversal. If price makes a new high or low and OBV does not, this lack of confirmation can be a warning sign of a turn in the opposite direction.

Frequently Asked Questions

How do I use OBV indicator?

To use the OBV indicator, track the cumulative total volume that adds or subtracts a multiple of the volume depending on the direction of the price change. It rises when the price finishes higher and falls when the price ends lower.

What is the best time frame for OBV indicator?

OBV can be effective on any time frame, but it is most useful on daily charts for identifying longer-term trends.

Is OBV good for day trading?

While OBV can be used for day trading, its effectiveness might be limited compared to its use in identifying longer-term trends because it's sensitive to sudden shifts in volume.

What is the trading strategy of OBV?

A common OBV trading strategy is to buy when the OBV starts rising and the price is still stable or starting to rise, suggesting incoming buying pressure. Conversely, sell when the OBV starts falling and the price begins to follow or has already started to fall.

For more insights and detailed analysis tools based on OBV and other strategies, visit AlgoTest Signals.