Volume Based Buy and Sell Momentum Indicator by NPtechs for TOS Updated and with counter

Platform
  1. Thinkorswim
# Converted to TOS from Siyeon's Tradingview "Volume Based Buy and Sell Momentum by 2tm" indicator by NPtechs
# v0.2 Replaced cloud with historgram, added averages of differences to show momentum, added couple Bar color options

#Modified by Gatekeeper 06242022
#NOTE: time frames must match the chart. any matter of interpertation is of the user. If delta(CYAN) MUST cross the avgdelta(WHITE) for count to change + or -, vice versa. Any pull back after the cross will be added to the pervious + or - count.
#Count only indicates the dela and avgdelts cross nothing else to interpreted.

declare lower;
input roc_ma = 25;
input delta_ma = 14;
input avg_delta_ma = 8;
input averageType = AverageType.EXPONENTIAL;
input BarColor = { "None", default "Diff_AvgDelta", "Only_Diff" };

def xROC = (close - close[1]) * 100 / close;
def nRes1 = if (volume < volume[1],nRes1[1] + xROC,nRes1[1]);
def nRes2 = if (volume > volume[1],nRes2[1] + xROC,nRes2[1]);
def nRes3 = nRes1 + nRes2;
def nResEMA3 = simpleMovingAvg(nRes1, roc_ma) + simpleMovingAvg(nRes2, roc_ma);
def PNVI_PEMA = nRes3 - nResEMA3;

plot delta = MovingAverage(averageType,PNVI_PEMA, delta_ma);
delta.SetDefaultColor(Color.CYAN);

plot avgdelta = MovingAverage(averageType,delta,avg_delta_ma);
avgdelta.SetDefaultColor(Color.WHITE);

plot PNVI_PEMA_Diff = PNVI_PEMA * 0.5;
PNVI_PEMA_Diff.SetDefaultColor(GetColor(5));
PNVI_PEMA_Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
PNVI_PEMA_Diff.SetLineWeight(4);
PNVI_PEMA_Diff.DefineColor("Positive and Up", Color.GREEN);
PNVI_PEMA_Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
PNVI_PEMA_Diff.DefineColor("Negative and Down", Color.RED);
PNVI_PEMA_Diff.DefineColor("Negative and Up", Color.DARK_RED);
PNVI_PEMA_Diff.AssignValueColor(
if PNVI_PEMA_Diff >= 0 then
if PNVI_PEMA_Diff > PNVI_PEMA_Diff[1] then PNVI_PEMA_Diff.Color("Positive and Up") else PNVI_PEMA_Diff.Color("Positive and Down")
else
if PNVI_PEMA_Diff < PNVI_PEMA_Diff[1] then PNVI_PEMA_Diff.Color("Negative and Down") else PNVI_PEMA_Diff.Color("Negative and Up")
);

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.WHITE);
ZeroLine.HideTitle();
ZeroLine.HideBubble();

#AssignPriceColor (
# if BarColor == BarColor.Diff_AvgDelta then if PNVI_PEMA #> 0 and delta > avgdelta then Color.GREEN
# else if PNVI_PEMA < 0 and delta < avgdelta then #Color.RED else Color.LIGHT_GRAY
# else if BarColor == BarColor.Only_Diff then if #PNVI_PEMA > 0 then Color.GREEN else Color.RED
# else Color.CURRENT);

PNVI_PEMA_Diff.AssignVALUEColor (
if BarColor == BarColor.Diff_AvgDelta then if PNVI_PEMA > 0 and delta > avgdelta then Color.GREEN
else if PNVI_PEMA < 0 and delta < avgdelta then Color.RED else Color.YELLOW
else if BarColor == BarColor.Only_Diff then if PNVI_PEMA > 0 then Color.GREEN else Color.RED
else Color.CURRENT);


###############

#cos251 And SuryaKirnaC Orginal for the RSM Pg7
#modified from by Gatekeeper


plot UpTrend = if delta > avgdelta then 1 else 0;#-1;
plot DownTrend = if delta < avgdelta then 1 else 0;#-1;


###plot DownTrend = if (MACDBB_Midline < 50 and SlowK < 50 and Value < Avg then 1 else 0;
UpTrend.Hide();
DownTrend.Hide();

def bnumUp;
def bnumDown;
def closeUpTrendStart;
def closeDownTrendStart;
def UpTrendBarCount;
def DownTrendBarCount;
if UpTrend and (!UpTrend[1] or DownTrend[1]) {
bnumUp = BarNumber();
bnumDown = 0;
closeUpTrendStart = close;
closeDownTrendStart = 0;
UpTrendBarCount = 1;
DownTrendBarCount = 0;
} else if UpTrend {
bnumUp = bnumUp[1];
bnumDown = 0;
closeUpTrendStart = closeUpTrendStart[1];
closeDownTrendStart = 0;
UpTrendBarCount = UpTrendBarCount[1] + 1;
DownTrendBarCount = 0;
} else if DownTrend and (!DownTrend[1] or UpTrend[1]) {
bnumUp = 0;
bnumDown = BarNumber();
closeDownTrendStart = close;
closeUpTrendStart = 0;
UpTrendBarCount = 0;
DownTrendBarCount = 1;
} else if DownTrend {
bnumDown = bnumDown[1];
closeDownTrendStart = closeDownTrendStart[1];
DownTrendBarCount = DownTrendBarCount[1] + 1;
bnumUp = 0;
closeUpTrendStart = 0;
UpTrendBarCount = 0;
} else {
bnumUp = 0;
bnumDown = 0;
closeUpTrendStart = 0;
closeDownTrendStart = 0;
UpTrendBarCount = 0;
DownTrendBarCount = 0;
}

###XXX Basic
def GetTrend = if Uptrend then 1 else if DownTrend then -1 else 0;

AddLabel (yes, if GetTrend == 1 then "VB+" + UpTrendBarCount else if GetTrend == -1 then "VB-" + DownTrendBarCount else "",

if GetTrend == 1 then COLOR.GREEN else if GetTrend == -1 then COLOR.RED else COLOR.YELLOW);






 
Top