Skip to content

Instantly share code, notes, and snippets.

@pequet
Last active June 25, 2018 23:59
Show Gist options
  • Save pequet/f0abde98a85e4130b93156e3cc3192be to your computer and use it in GitHub Desktop.
Save pequet/f0abde98a85e4130b93156e3cc3192be to your computer and use it in GitHub Desktop.
// Created by @pequet (https://www.tradingview.com/u/pequet) May 28 2018
// https://github.com/pequet/
// NOT FOR DISTRIBUTION
// @version=3
study(title="1' OBV v0.0.4", shorttitle="1' OBV", overlay=false)
// inputs
// ------
formulaInput = input("line", options=["line","candles"], title="Formula") // good idea or dumb idea?
// functions
// ---------
OnePeriod() => ismonthly ? 40320*interval
: isweekly ? 10080*interval
: isdaily ? 1440*interval
: interval
vol = cum(formulaInput=="line" ? ( change(close)>0 ? volume : change(close)<0 ? -volume : 0 ) : ( open<close ? volume : open>close ? -volume : 0 ))
obv = security(tickerid, '1', vol)
plot(obv, color=blue, transp=0, title="SOBV")
// -
@greg-oire
Copy link

study(title="Candle body weighted Spectroscopic OBV v0.0.5", shorttitle="SOBV v0.0.5", overlay=false, precision=0)

// inputs
// ------

formulaInput = input("line", options=["line","candles"], title="Formula") // good idea or dumb idea?
src = input(close, title="source")
adjust = input (false, title = "use volume adjusted with candle body size")

bodysize = 1/(abs(open-close))
adjvol = volume/bodysize
volu = adjust ? adjvol : volume

// functions
// ---------

OnePeriod() => ismonthly ? 40320interval
: isweekly ? 10080
interval
: isdaily ? 1440*interval
: interval

vol = cum(formulaInput=="line" ? ( change(src)>0 ? volu : change(src)<0 ? -volu : 0 ) : ( open<close ? volu : open>close ?-volu : 0 ))

res = input(false, title="use 1 min resolution to calculate OBV")
TF = input(title="Resolution TF", type=resolution,defval="1")
reso = res ? TF : period

obv = security(tickerid, reso, vol)

plot(obv, color=lime, transp=0, title="SOBV", linewidth=2)

@greg-oire
Copy link

bodysize = abs(open-close)
adjvol = volume*bodysize
volu = adjust ? adjvol : volume

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment