blackbeard12
New member
I'm sure this has already been done before, but I coded a volume script that subtracts the area under the curve of the buyer's volume by the sellers. The aim I was trying to accomplish was to visualize trends as they happen. It was a cool project and gave some good signals. It was extremely choppy so I added in a smoothing factor, which works best with high time frames and higher lengths. Haven't posted here in a while and wanted to give something back.
Code:
# Volume Analysis with Smoothing
# Benzene
input volumeLookback = 20; # Number of bars to consider for volume analysis
input smoothingPeriod = 5; # Smoothing period for buyer and seller activity
def buyerVolume = if close > close[1] then volume else 0;
def sellerVolume = if close < close[1] then volume else 0;
def totalVolume = Sum(volume, volumeLookback);
def buyerActivity = buyerVolume / totalVolume;
def sellerActivity = sellerVolume / totalVolume;
def smoothedBuyerActivity = Average(buyerActivity, smoothingPeriod);
def smoothedSellerActivity = Average(sellerActivity, smoothingPeriod);
plot buyerSellerDifference = smoothedBuyerActivity - smoothedSellerActivity;
buyerSellerDifference.SetDefaultColor(Color.GREEN);
# Add baseline at 0
plot baseline = 0;
baseline.SetDefaultColor(Color.GRAY);
baseline.SetStyle(Curve.SHORT_DASH);
Last edited by a moderator: