Volume Based Buy and Sell Momentum Indicator for TOS

NPTechs

New member
Platform
  1. Thinkorswim
Code:
# Converted to TOS from Siyeon's Tradingview "Volume Based Buy and Sell Momentum by 2tm" indicator by NPtechs

declare lower;
input ma_length = 25;
def xROC = (close - close[1]) * 100 / close;

def nRes1 = if (volume < volume[1]) then
               nRes1[1] + xROC
            else
               nRes1[1];

def nRes2 = if (volume > volume[1]) then
               nRes2[1] + xROC
            else
               nRes2[1];
              
def nRes3 = nRes1 + nRes2;

def nResEMA3 = simpleMovingAvg(nRes1, ma_length) + simpleMovingAvg(nRes2, ma_length);
plot PNVI = nRes3;
plot PEMA = nResEMA3;

input PaintBars = Yes;
AssignPriceColor (if !PaintBars then Color.CURRENT else if PNVI > PEMA then Color.GREEN else Color.RED);

PNVI.SetDefaultColor(GetColor(1));
PNVI.DefineColor("Up Momentum", Color.BLUE);
PNVI.AssignValueColor(PNVI.color("Up Momentum"));

PEMA.SetDefaultColor(GetColor(1));
PEMA.DefineColor("Down Momentum", Color.RED);
PEMA.AssignValueColor(PEMA.color("Down Momentum"));

AddCloud(PNVI,PEMA,PNVI.color("Up Momentum"),PEMA.color("Down Momentum"));

uc
 

DeepThinker

New member
@NPTechs
Could you suggest scanner logic to cover "bull vs bear" use cases, helping to identify

a. rising momentum
b. "entering" or "in" territory

Thanks
 

NPTechs

New member
Thanks
I was also looking for the way to signal rising or slowing momentum
Does this help? You can create scan with delta, avgdelta plots, change the MA lengths and Avgtype to suite your needs

Code:
# 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

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);

uc
 

DeepThinker

New member
Does this help? You can create scan with delta, avgdelta plots, change the MA lengths and Avgtype to suite your needs

Code:
# 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

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);

uc
Many Thanks 👍
I will apply changes for next week testing
 
@NPTechs nice indicator , when the ASSIGNEDPRICECOLOR is used it effects the upper candle colors. so prefer to use ASSIGNEDVALUECOLOR because it doesn't effect other indicator. So you might want to modified your indicator. Just change line 44 to PNVI_PEMA_Diff.AssignVALUEColor you will also pick up the white in the histogram. Hope it help

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.LIGHT_GRAY
else if BarColor == BarColor.Only_Diff then if PNVI_PEMA > 0 then Color.GREEN else Color.RED
else Color.CURRENT);



 
Last edited:

barbaros

Administrator
Staff member
Great job!! please can someone update the code with this new add on!! thanks in advance
You just paste it at the end...here is the combined indicator.

Code:
# 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

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.LIGHT_GRAY
else if BarColor == BarColor.Only_Diff then if PNVI_PEMA > 0 then Color.GREEN else Color.RED
else Color.CURRENT);
 
Top