OBV keeps a running total that adds the bar's volume on an up-close and subtracts it on a down-close. Rising OBV confirms the buying pressure behind an uptrend; OBV/price divergence often precedes a reversal. Copy the version for your platform.
//@version=5
indicator("On Balance Volume", overlay=false)
obv = ta.cum(math.sign(ta.change(close)) * volume)
plot(obv, title="OBV", color=color.blue, linewidth=2)#property indicator_separate_window
#property indicator_buffers 1
double ObvBuffer[];
int OnInit() {
SetIndexBuffer(0, ObvBuffer);
IndicatorShortName("OBV");
return 0;
}
int OnCalculate(const int rates_total, const int prev_calculated, const double &close[]) {
for (int i = prev_calculated; i < rates_total; i++)
ObvBuffer[i] = iOBV(NULL, 0, PRICE_CLOSE, i);
return rates_total;
}#property indicator_separate_window
#property indicator_buffers 1
double ObvBuffer[];
int OnInit() {
SetIndexBuffer(0, ObvBuffer);
IndicatorSetString(INDICATOR_SHORTNAME, "OBV");
return INIT_SUCCEEDED;
}
int OnCalculate(const int rates_total, const int prev_calculated,
const datetime &time[], const double &open[], const double &high[],
const double &low[], const double &close[], const long &tick_volume[],
const long &volume[], const int &spread[]) {
for (int i = prev_calculated; i < rates_total; i++)
ObvBuffer[i] = iOBV(NULL, 0, PRICE_CLOSE, i);
return rates_total;
}variables: MyOBV(0);
MyOBV = OBV();
Plot1(MyOBV, "OBV");{On Balance Volume}
vol := OBV();
volTo use it inside dtcharts, paste any version into the Script Converter and it becomes a native indicator on your chart.