Converted from Tradingview:
https://usethinkscript.com/threads/converted-tradingview-buyer-to-seller-volume-bsv.13874/
here is a version without MTF
not sure if these formulas should be changed, to be averages, not just sums
def BuyAverage = sum(greencandlevolume, AvgLength);
def SellAverage = sum(redcandlevolume, AvgLength);
https://usethinkscript.com/threads/converted-tradingview-buyer-to-seller-volume-bsv.13874/
here is a version without MTF
not sure if these formulas should be changed, to be averages, not just sums
def BuyAverage = sum(greencandlevolume, AvgLength);
def SellAverage = sum(redcandlevolume, AvgLength);
Code:
declare lower;
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Steversteves
#//@version=5
#indicator("Buyer to Seller Volume (BSV)")
#BackgroundData(symbol, timeframe, data) =>
# isLive = barstate.isrealtime
# request.security(symbol, timeframe, data[isLive ? 1 : 0])[isLive ? 0 : 1]
#InSession(sessionTimes, sessionTimeZone=syminfo.timezone) =>
# not na(time(timeframe.period, sessionTimes, sessionTimeZone))
def chartagg = getaggregationperiod();
def chartmin = chartagg/(1000*60);
#addlabel(yes, chartmin + " min", color.yellow);
#higherTimeFrame = input.timeframe("D", title="Time Frame")
#AvgLength = input.int(14, title="Average Length")
input AvgLength = 14;
#greencandle = (close > open)
#redcandle = (open > close)
def greencandle = (close > open);
def redcandle = (open > close);
#greencandlevolume = if greencandle
# volume
#redcandlevolume = if redcandle
# volume
def greencandlevolume = if greencandle then volume else 0;
def redcandlevolume = if redcandle then volume else 0;
#// Vol Over time
#BuyAverage = BackgroundData(syminfo.tickerid, higherTimeFrame, math.sum(greencandlevolume, AvgLength))
#SellAverage = BackgroundData(syminfo.tickerid, higherTimeFrame, math.sum(redcandlevolume, AvgLength))
def BuyAverage = sum(greencandlevolume, AvgLength);
def SellAverage = sum(redcandlevolume, AvgLength);
#buyvolmax = ta.highest(BuyAverage, AvgLength)
#buyvolmin = ta.lowest(BuyAverage, AvgLength)
#sellvolmax = ta.highest(SellAverage, AvgLength)
#sellvolmin = ta.lowest(SellAverage, AvgLength)
def buyvolmax = highest(BuyAverage, AvgLength);
def buyvolmin = lowest(BuyAverage, AvgLength);
def sellvolmax = highest(SellAverage, AvgLength);
def sellvolmin = lowest(SellAverage, AvgLength);
#bool buyvolmaxatmax = BuyAverage >= buyvolmax
#bool buyvolminatmin = BuyAverage <= buyvolmin
#bool sellvolmax2 = SellAverage >= sellvolmax
#bool sellvolmin2 = SellAverage >= sellvolmin
def buyvolmaxatmax = BuyAverage >= buyvolmax;
def buyvolminatmin = BuyAverage <= buyvolmin;
def sellvolmax2 = SellAverage >= sellvolmax;
def sellvolmin2 = SellAverage >= sellvolmin;
#// Color
#color volBullColorInput = input.color(color.green, "Bull")
#color volBearColorInput = input.color(color.red, "Bear")
#color neutralinput = input.color(color.gray, "Neutral")
#color maxbuyers = input.color(color.fuchsia, "Max Buyers")
#color minbuyers = input.color(color.black, "Max Sellers")
#color buyerneutral = input.color(color.black, "Buyers Neutral")
DefineGlobalColor("Bull", color.green); #volBullColorInput
DefineGlobalColor("Bear", color.red); #volBearColorInput
DefineGlobalColor("Neutral", color.gray); #neutralinput
DefineGlobalColor("Max Buyers", color.magenta); #maxbuyers
DefineGlobalColor("Max Sellers", color.black); #minbuyers
DefineGlobalColor("Buyers Neutral", color.black); #buyerneutral
#color buyavgcolor = buyvolmaxatmax ? minbuyers : volBullColorInput
#color sellavgcolor = sellvolmax2 ? neutralinput : volBearColorInput
#// SMA Vol
#volavg = (BuyAverage + SellAverage) / 2
def volavg = (BuyAverage + SellAverage) / 2;
#sma = ta.sma(volavg, AvgLength)
input ma1_type = AverageType.simple;
def sma = MovingAverage(ma1_type, volavg, AvgLength);
#plot(sma, "SMA", color=color.yellow)
plot zsma = sma;
zsma.SetDefaultColor(Color.yellow);
#zsma.setlineweight(1);
zsma.hidebubble();
#//plot(br, style=plot.style_histogram, color = pallette)
#plot(BuyAverage, "Buyer Volume", color = volBullColorInput, linewidth=2)
#plot(SellAverage, "Seller Volume", color = volBearColorInput, linewidth=2)
plot zBuyAverage = BuyAverage;
zBuyAverage.SetDefaultColor(GlobalColor("bull"));
zBuyAverage.setlineweight(2);
zBuyAverage.hidebubble();
plot zSellAverage = SellAverage;
zSellAverage.SetDefaultColor(GlobalColor("bear"));
zsellAverage.setlineweight(2);
zsellAverage.hidebubble();
Last edited by a moderator: