####################################################################################
#Volume color coded by amount of volume on up-tick versus amount of volume on down-tick
declare lower;
def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def Buying = V * (C - L) / (H - L);
def Selling = V * (H - C) / (H - L);
# Selling Volume
plot SV = Selling;
SV.SetPaintingStrategy(PaintingStrategy.line);
SV.SetDefaultColor(Color.RED);
SV.HideTitle();
SV.HideBubble();
SV.SetLineWeight(3);
SV.hide();
# Buying Volume
# Plot BV = Buying;
# Note that Selling + Buying Volume = Volume.
plot BV = volume;
BV.SetPaintingStrategy(PaintingStrategy.line);
BV.SetDefaultColor(Color.DARK_GREEN);
BV.HideTitle();
BV.HideBubble();
BV.SetLineWeight(3);
BV.hide();
#############################################################
# plot average of Buying and Selling Pressure
def price1 = Buying;
input avg1_len = 2;
input avg1_type = AverageType.EXPONENTIAL;
def avg1 = MovingAverage(avg1_type, price1, avg1_len);
def price2 = Selling;
input avg2_len = 2;
input avg2_type = AverageType.EXPONENTIAL;
def avg2 = MovingAverage(avg2_type, price2, avg2_len);
plot BaseBuyAvg = avg1;
BaseBuyAvg.SetDefaultColor(Color.dark_GREEN);
BaseBuyAvg.hidebubble();
BaseBuyAvg.hide();
plot BaseSellAvg = avg2;
BaseSellAvg.SetDefaultColor(Color.red);
BaseSellAvg.hidebubble();
BaseSellAvg.hide();
#####################################################################
####### Tema on 2 period EMA of Buying and Selling Volume############
input Tema_BVlength = 17;
plot TEMA_BV = TEMA(BaseBuyAvg, Tema_BVlength);
TEMA_BV.SetPaintingStrategy(PaintingStrategy.LINE);
TEMA_BV.SetDefaultColor(Color.Plum);
TEMA_BV.SetLineWeight(2);
input Tema_SVlength = 17;
plot TEMA_SV = TEMA(BaseSellAvg, Tema_SVlength);
TEMA_SV.SetPaintingStrategy(PaintingStrategy.LINE);
TEMA_SV.SetDefaultColor(Color.BLACK);
TEMA_SV.SetLineWeight(2);
####################################################################################
#Create an smoothed MA on Buying and Selling TEMAs for signal
input TemaMA_BuySignal_length = 2;
plot TemaMA_BuySignal = Average(TEMA_BV, TemaMA_BuySignal_length);
TemaMA_BuySignal.SetPaintingStrategy(PaintingStrategy.line);
TemaMA_BuySignal.SetDefaultColor(Color.GREEN);
TemaMA_BuySignal.SetLineWeight(1);
input TemaMA_SellSignal_length = 2;
plot TemaMA_SellSignal = Average(TEMA_SV, TemaMA_SellSignal_length);
TemaMA_SellSignal.SetPaintingStrategy(PaintingStrategy.line);
TemaMA_SellSignal.SetDefaultColor(Color.BLACK);
TemaMA_SellSignal.SetLineWeight(1);
####################################################################################