- Platform
-
- Thinkorswim
Direct from the author:
Slight variation, SuperTrend based Volume Waves
Latest version with high breakout and label added.
A very simple Volume study based on accumulation or distribution. AKA Volume Waves.

Code:
# Mobius Volume Wave
# V01.2020
# Plots Volume Waves based on trend.
declare lower;
input n = 6;
DefineGlobalColor("LabelGreen", CreateColor(0, 165, 0)) ;
def v = volume;
def accumulation = isAscending(HL2, n);
def distribution = isDescending(HL2, n);
plot scan = !distribution ;
scan.hide();
def w = if accumulation and !accumulation[1]
then v
else if distribution and !distribution[1]
then v
else w[1] + v;
plot waves = w;
waves.SetPaintingStrategy(PaintingStrategy.Histogram);
waves.AssignValueColor(if accumulation
then GlobalColor("LabelGreen")
else if distribution
then color.red
else color.yellow);
# End Code Mobius Volume Waves
Slight variation, SuperTrend based Volume Waves

Code:
# Mobius Supertrend Volume Waves
# V01.2020
# Plots Volume Waves based on trend.
declare lower;
input n = 6;
input AvgType = AverageType.HULL;
input ATRmult = .7;
input ColorCandles = yes;
def h = high;
def l = low;
def c = close;
def v = volume;
DefineGlobalColor("Ascending", Color.GREEN);
DefineGlobalColor("descending", Color.RED);
DefineGlobalColor("avg", Color.CYAN);
def ATR = MovingAverage(AvgType, TrueRange(h, c, l), n);
def DN = HL2 + (AtrMult * ATR);
def UP = HL2 + (-AtrMult * ATR);
def cond = if c < cond[1]
then DN
else UP;
def accumulation = cond == UP;
def distribution = cond == DN;
def w1 = if accumulation and !accumulation[1]
then v
else if accumulation
then w1[1] + v
else Double.NaN;
def w2 = if distribution and !distribution[1]
then v
else if distribution
then w2[1] + v
else Double.NaN;
plot waves1 = w1;
waves1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
waves1.SetDefaultColor(GlobalColor("Ascending"));
plot waves2 = w2;
waves2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
waves2.SetDefaultColor(GlobalColor("Descending"));
def SD = StDevAll(v);
plot avg = (HighestAll(w1/2)+highestAll(w2/2))/n ;
avg.SetDefaultColor(GlobalColor("avg"));
AssignPriceColor(if ColorCandles and cond == dn
then color.red
else color.green);
Latest version with high breakout and label added.
Code:
# Mobius Supertrend Volume Waves
# Plots Volume Waves based on trend.
# 20210127 - barbaros - added high lines for b4indicators.com
# 20210128 - barbaros - added label
# 20210128 - barbaros - clean up
declare lower;
input n = 6;
input AvgType = AverageType.HULL;
input ATRmult = .7;
input ColorCandles = yes;
def h = high;
def l = low;
def c = close;
def v = volume;
DefineGlobalColor("Ascending", Color.GREEN);
DefineGlobalColor("descending", Color.RED);
DefineGlobalColor("avg", Color.CYAN);
def ATR = MovingAverage(AvgType, TrueRange(h, c, l), n);
def DN = HL2 + (AtrMult * ATR);
def UP = HL2 + (-AtrMult * ATR);
def cond = if c < cond[1] then DN else UP;
def accumulation = cond == UP;
def accumulationTrigger = accumulation and !accumulation[1];
def distribution = cond == DN;
def distributionTrigger = distribution and !distribution[1];
def state = if accumulationTrigger then 1
else if distributionTrigger then -1
else state[1];
def w1 = if accumulationTrigger then v
else if accumulation then w1[1] + v
else Double.NaN;
def w2 = if distributionTrigger then v
else if distribution then w2[1] + v
else Double.NaN;
def w = if state == 1 then w1
else if state == -1 then w2
else Double.NaN;
def hhLine = if accumulationTrigger or distributionTrigger then w[1] else hhLine[1];
def percPosition = w / hhLine;
plot waves1 = w1;
waves1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
waves1.SetDefaultColor(GlobalColor("Ascending"));
plot waves2 = w2;
waves2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
waves2.SetDefaultColor(GlobalColor("Descending"));
plot avg = (HighestAll(w1/2)+highestAll(w2/2))/n ;
avg.SetDefaultColor(GlobalColor("avg"));
plot waveHigh = hhLine;
waveHigh.SetDefaultColor(Color.MAGENTA);
waveHigh.SetLineWeight(2);
AssignPriceColor(if ColorCandles then
if cond == dn then color.red
else color.green
else Color.CURRENT);
AddLabel(yes, if state == 1 then "Accumulation: " + AsPercent(percPosition)
else if state == -1 then "Distribution: " + AsPercent(percPosition)
else "Neutral",
if state == 1 and percPosition >= 1 then Color.GREEN
else if state == -1 and percPosition >= 1 then Color.RED
else Color.GRAY);
alert(w1 crosses hhLine, "accumulation", Alert.BAR, Sound.DING);
alert(w2 crosses hhLine, "distribution", Alert.BAR, Sound.DING);
/CODE]
Last edited: