Last active
May 31, 2018 23:59
-
-
Save pequet/3a4a6b9b917ae663263459de2a05e5ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created by @pequet (https://www.tradingview.com/u/pequet) May 28 2018 | |
// https://github.com/pequet/ | |
// NOT FOR DISTRIBUTION | |
// @version=3 | |
// Thanks Greg A! https://www.tradingview.com/u/Gregg_s/ | |
// Candles are often missing for shitcoins on tradingview and sometimes in not-so-small resolutions | |
// https://www.tradingview.com/script/Cp6sqEAN-Candle-Thief-v1-0-TradingView-Anomalies/ | |
// Implications: | |
// 1. Option to calculate the on balance volume based on the color of each candle as opposed to the last closing price (is this a dumb idea?) | |
// 2. The number of the periods we look back varies so we need to check the time of each period, unfortunately this doubles the number of security function calls | |
study(title="Spectroscopic OBV v0.0.3", shorttitle="SOBV v0.0.3", overlay=false) | |
// inputs | |
// ------ | |
formulaInput = input("line", options=["line","candles"], title="Formula") | |
// functions | |
// --------- | |
OnePeriod() => ismonthly ? 40320*interval | |
: isweekly ? 10080*interval | |
: isdaily ? 1440*interval | |
: interval | |
res = OnePeriod() == 10080 ? '720' | |
: OnePeriod() == 1440 ? '120' | |
: OnePeriod() == 720 ? '60' | |
: OnePeriod() == 240 ? '15' | |
: OnePeriod() == 120 ? '10' | |
: OnePeriod() == 60 ? '5' | |
: OnePeriod() == 15 ? '1' | |
: OnePeriod() == 5 ? '1' | |
: resolution | |
vol = formulaInput=="line" ? ( change(close)>0 ? volume : change(close)<0 ? -volume : 0 ) : ( open<close ? volume : open>close ? -volume : 0 ) | |
v0 = security(tickerid, res, vol) | |
v1 = security(tickerid, res, time[1]) < time ? 0 : security(tickerid, res, vol[1]) | |
v2 = security(tickerid, res, time[2]) < time ? 0 : security(tickerid, res, vol[2]) | |
v3 = security(tickerid, res, time[3]) < time ? 0 : security(tickerid, res, vol[3]) | |
v4 = security(tickerid, res, time[4]) < time ? 0 : security(tickerid, res, vol[4]) | |
v5 = security(tickerid, res, time[5]) < time ? 0 : security(tickerid, res, vol[5]) | |
v6 = security(tickerid, res, time[6]) < time ? 0 : security(tickerid, res, vol[6]) | |
v7 = security(tickerid, res, time[7]) < time ? 0 : security(tickerid, res, vol[7]) | |
v8 = security(tickerid, res, time[8]) < time ? 0 : security(tickerid, res, vol[8]) | |
v9 = security(tickerid, res, time[9]) < time ? 0 : security(tickerid, res, vol[9]) | |
v10 = security(tickerid, res, time[10]) < time ? 0 : security(tickerid, res, vol[10]) | |
v11 = security(tickerid, res, time[11]) < time ? 0 : security(tickerid, res, vol[11]) | |
v12 = security(tickerid, res, time[12]) < time ? 0 : security(tickerid, res, vol[12]) | |
v13 = security(tickerid, res, time[13]) < time ? 0 : security(tickerid, res, vol[13]) | |
v14 = security(tickerid, res, time[14]) < time ? 0 : security(tickerid, res, vol[14]) | |
v15 = security(tickerid, res, time[15]) < time ? 0 : security(tickerid, res, vol[15]) | |
obv = cum(v0+v1+v2+v3+v4+v5+v6+v7+v8+v9+v10+v11+v12+v13+v14+v15) | |
plot(obv, transp=0, title="SOBV") | |
// - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment