feat: add new indicators (Decay, Edecay, MinusDi, MinusDm, PlusDi, PlusDm, Maxindex, Minindex, Sarext) and update pine scripts, core libs, validation tests, and python bindings
2026-03-09 13:45:46 -07:00
|
|
|
// Licensed under the Apache License, Version 2.0
|
2026-01-18 19:02:03 -08:00
|
|
|
// © mihakralj
|
|
|
|
|
//@version=6
|
|
|
|
|
indicator("On Balance Volume (OBV)", "OBV", overlay=false)
|
|
|
|
|
|
|
|
|
|
//@function Calculates On Balance Volume
|
|
|
|
|
//@param c Close price series
|
|
|
|
|
//@param vol Volume series
|
|
|
|
|
//@returns Cumulative On Balance Volume value
|
|
|
|
|
//@optimized for performance and dirty data
|
|
|
|
|
obv(series float c = close, series float vol = volume) =>
|
|
|
|
|
float close_price = nz(c, close)
|
|
|
|
|
float volume_val = nz(vol, 0.0)
|
|
|
|
|
float prev_close = nz(close_price[1], close_price)
|
|
|
|
|
var float obv_cumulative = 0.0
|
|
|
|
|
obv_cumulative += close_price > prev_close ? volume_val : close_price < prev_close ? -volume_val : 0.0
|
|
|
|
|
obv_cumulative
|
|
|
|
|
|
|
|
|
|
// ---------- Main loop ----------
|
|
|
|
|
|
|
|
|
|
// Calculation
|
|
|
|
|
obv_value = obv(close, volume)
|
|
|
|
|
|
|
|
|
|
// Plot
|
|
|
|
|
plot(obv_value, "OBV", color=color.yellow, linewidth=2)
|