I modified the Buy and Sell Volume indicator
https://usethinkscript.com/threads/...ssure-indicators-labels-for-thinkorswim.8466/
to plot a "buy" moving average and "sell" moving average. When the two cross, it helps to show a trend reversal.
I included some code to plot when the two cross up or down. Unfortunately, it's only showing the "cross down" and doesn't show the "cross up" plots. Can someone help me get the "cross up" to show?
Ruby:
#Buy/Sell Volume Moving Averages
declare on_volume;
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.HISTOGRAM);
SV.SetDefaultColor(Color.RED);
SV.HideTitle();
SV.HideBubble();
SV.SetLineWeight(5);
# Buying Volume
# Plot BV = Buying;
# Note that Selling + Buying Volume = Volume.
plot BV = volume;
BV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BV.SetDefaultColor(Color.DARK_GREEN);
BV.HideTitle();
BV.HideBubble();
BV.SetLineWeight(5);
input length = 26;
plot VolAvg = Average(Selling, length);
plot VolAvg2 = Average(Buying, length);
VolAvg.SetDefaultColor(GetColor(2));
VolAvg2.SetDefaultColor(GetColor(6));
AddVerticalLine(VolAvg crosses above VolAvg2, "Up", Color.Green, Curve.Points);
AddVerticalLine(VolAvg2 crosses below VolAvg, "Down", Color.Yellow, Curve.Points);
#End
Here you go. I also added a cloud and a "Net Buy / Sell" avg line to spot divergences. Both can be turned on/off but most likely need to diable volume histogram for these 2 features to be useful.
#Buy/Sell Volume Moving Averages
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.HISTOGRAM);
SV.SetDefaultColor(Color.RED);
SV.HideTitle();
SV.HideBubble();
SV.SetLineWeight(5);
# Buying Volume
# Plot BV = Buying;
# Note that Selling + Buying Volume = Volume.
plot BV = volume;
BV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BV.SetDefaultColor(Color.DARK_GREEN);
BV.HideTitle();
BV.HideBubble();
BV.SetLineWeight(5);
input length = 26;
plot SellingAvg = Average(Selling, length);
plot BuyingAvg = Average(Buying, length);
SellingAvg.SetDefaultColor(GetColor(2));
BuyingAvg.SetDefaultColor(GetColor(6));
AddVerticalLine(BuyingAvg crosses above SellingAvg, "Up", Color.Green, Curve.Points);
AddVerticalLine(BuyingAvg crosses below SellingAvg, "Down", Color.yellow, Curve.Points);
#End
# ---------------------------------------- Add Net Buy / Sell ----------------
DefineGlobalColor( "Net Pressure Up", color.cyan);
DefineGlobalColor( "Net Pressure Down", color.magenta);
def NetBuySell = BuyingAvg - SellingAvg;
Plot NetPressure = NetBuySell;
NetPressure.AssignValueColor(if NetPressure >= NetPressure[1] then GlobalColor ("Net Pressure Up") else GlobalColor ("Net Pressure Down"));
NetPressure.SetDefaultColor(GetColor(2));
# --------------------------------------- Add Cloud --------------------------
input ShowCloud = no;
DefineGlobalColor( "Bullish Cloud", CreateColor(201, 255, 234));
DefineGlobalColor( "Bearish Cloud", CreateColor(255, 105, 105));
AddCloud(if ShowCloud then BuyingAvg else Double.NaN, SellingAvg, GlobalColor("Bullish Cloud"), GlobalColor("Bearish Cloud"));