OBV Strategy

Research Paper on Trading Strategies Beside Calculator and Laptop

OBV Strategy Indicator Pinescript

These strategies are for demonstration purposes only and are not intended for actual trading. Saanmi Capital is not responsible for any profit or loss arising from the use of these sample strategies.

//@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)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top