Code Library / Volume Analysis
Pine Script OBV Strategy
On Balance Volume strategy with MA confirmation.
Language: Pine Script · Category: Volume Analysis · Tags: OBV, On Balance Volume, Pine Script, strategy, momentum
Source code
//@version=5
strategy("OBV",overlay=false)
obv=ta.obv; obvMA=ta.sma(obv,20)
if ta.crossover(obv,obvMA) and close>ta.sma(close,20)
strategy.entry("Long",strategy.long)
if ta.crossunder(obv,obvMA)
strategy.entry("Short",strategy.short)
plot(obv,"OBV",color.blue,2); plot(obvMA,"MA",color.orange)How to use this snippet
This is a building block, not a finished trading system. Paste it into your own Pine Script project, compile it, and test it on a demo account with your broker's real spreads before relying on it. You can convert it to MQL4 or MQL5 with the Pine Script converter.