Volume Confirmation for a Trend System For ThinkOrSwim

SethW446

New member
VIP
"Volume Confirmation For A Trend System" is an article by Buff Pelz Dormeier, CMT, published in the August 2024 edition of TASC's Traders' Tips.

The article discusses how volume flows can help validate price movements, both trending and non-trending. It also presents an updated trend-following trading system that combines the ADX, trend thrust indicator, and volume price confirmation indicator.

The ToS script below demonstrates the use of volume data to validate price movements based on the techniques in the article.

The link below gives good description of the indicator and the strategy results, which are noteworthy.
https://www.tradingview.com/script/...rates the use,edition of TASC's Traders' Tips.

W4vP9ry.png
 
Last edited by a moderator:
This code is from TradingView, who used it in TASC article this August 24, title given above. The link below gives good description of the indicator and the strategy results, which are noteworthy. I would love to have someone convert this to TOS.

https://www.tradingview.com/script/K3s5dmdv-TASC-2024-08-Volume-Confirmation-For-A-Trend-System/

Code:
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PineCodersTASC

//  TASC Issue: August 2024 - Vol. 42
//     Article: Volume Confirmation For A Trend System.
//              The Trend Thrust Indicator And
//              Volume Price Confirmation Indicator.
//  Article By: Buff Pelz Dormeier
//    Language: TradingView's Pine Script™ v5
// Provided By: PineCoders, for tradingview.com


//@version=5
string title = "TASC 2024.08 Volume Confirmation For A Trend System"
string stitle = "VCTS"
strategy(title, stitle, false)


// Input
lenADX  = input.int(14, "ADX Length", 1)
smt     = input.int(14, "ADX Smoothing", 1, 50)
fastTTI = input.int(13, "TTI Fast Average", 1)
slowTTI = input.int(26, "TTI Slow Average", 1)
smtTTI  = input.int(9,  "TTI Signal Length", 1)
shortVP = input.int(5,  "VPCI Short-Term Average", 1)
longVP  = input.int(25, "VPCI Long-Term Average", 1)


// Functions
// ADX
adx(lenADX, smt) =>
    upDM   =  ta.change(high)
    dwDM   = -ta.change(low)
    pDM    = na(upDM) ? na : upDM > dwDM and upDM > 0 ? upDM : 0
    mDM    = na(dwDM) ? na : dwDM > upDM and dwDM > 0 ? dwDM : 0
    ATR    = ta.atr(lenADX)
    pDI    = fixnan(100 * ta.rma(pDM, lenADX) / ATR)
    mDI    = fixnan(100 * ta.rma(mDM, lenADX) / ATR)
    ADX    = 100*ta.rma(math.abs((pDI - mDI)  / (pDI + mDI)), smt)
    ADX

// TTI
// See also: https://www.tradingview.com/script/B6a7HzVn/
tti(price, fast, slow) =>
    fastMA = ta.vwma(price, fast)
    slowMA = ta.vwma(price, slow)
    VWMACD = fastMA - slowMA
    vMult  = math.pow((fastMA / slowMA), 2)
    VEFA   = fastMA * vMult
    VESA   = slowMA / vMult
    TTI    = VEFA - VESA
    signal = ta.sma(TTI, smtTTI)
    [TTI, signal]

// VPCI
// See also: https://www.tradingview.com/script/lmTqKOsa-Indicator-Volume-Price-Confirmation-Indicator-VPCI/
vpci(long, short) =>
    VPC    = ta.vwma(close, long)  - ta.sma(close, long)
    VPR    = ta.vwma(close, short) / ta.sma(close, short)
    VM     = ta.sma(volume, short) / ta.sma(volume, long)
    VPCI   = VPC * VPR * VM
    VPCI


// Calculations
float ADX     = adx(lenADX, smt)
[TTI, signal] = tti(close, fastTTI, slowTTI)
float VPCI    = vpci(longVP, shortVP)


// Plot
col1  = #4daf4a50
col2  = #e41a1c20
col0  = #ffffff00
adxL1 = plot(ADX,    "ADX", #984ea3)
adxL0 = plot(30,     "ADX Threshold", #984ea350)
ttiL1 = plot(TTI,    "TTI", #ff7f00)
ttiL0 = plot(signal, "TTI Signal", #ff7f0050)
vpcL1 = plot(VPCI*10,"VPCI", #377eb8)
vpcL0 = plot(0,      "VPCI Zero", #377eb850)
fill(adxL1, adxL0, ADX > 30 ? col1 : col0)
fill(ttiL1, ttiL0, TTI > signal ? col1 : col0)
fill(vpcL1, vpcL0, VPCI > 0 ? col1 : col2)


// Strategy entry/exit rules
if ADX > 30
    if TTI > signal
        if VPCI > 0
            strategy.entry("entry", strategy.long)
if VPCI < 0
    strategy.close_all("exit")
find below the indicator and strategy. * Paste the strategy under the strategy tab.

Indicator :
CSS:
#// Indicator for TOS
#// © PineCodersTASC
#//  TASC Issue: August 2024 - Vol. 42
#//     Article: Volume Confirmation For A Trend System.
#//              The Trend Thrust Indicator And
#//              Volume Price Confirmation Indicator.
#//  Article By: Buff Pelz Dormeier
#//    Language: TradingView's Pine Script™ v5
#// Provided By: PineCoders, for tradingview.com
#string title = "TASC 2024.08 Volume Confirmation For A Trend System"
# converted by Sam4@Samer800    - 07/2024
declare lower;

input adxThreshold = 30.0;
input adxLength  = 14;#, "ADX Length", 1)
input adxSmoothingLength = 14;#, "ADX Smoothing", 1, 50)
input ttiFastLength = 13;#, "TTI Fast Average", 1)
input ttiSlowLength = 26;#, "TTI Slow Average", 1)
input ttiSignalLength  = 9;#  "TTI Signal Length", 1)
input vpciFastLength = 5;#,  "VPCI Short-Term Average", 1)
input vpciSlowLength  = 25;#, "VPCI Long-Term Average", 1)

def na = Double.NaN;
def last = IsNaN(close);

#vwma(source, length)
script VWMA {
    input src = close;
    input len = 14;
    input vol = volume;
    def nom = Average(src * vol, len);
    def den = Average(vol, len);
    def VWMA = nom / den;
    plot result = if isNaN(VWMA) then 0 else VWMA;
}
#// TTI
#// See also: https://www.tradingview.com/script/B6a7HzVn/
script tti {
    input price = close;
    input fast = 13;
    input slow = 26;
    def fastMA = vwma(price, fast);
    def slowMA = vwma(price, slow);
    def VWMACD = fastMA - slowMA;
    def vMult  = Power((fastMA / slowMA), 2);
    def VEFA   = fastMA * vMult;
    def VESA   = slowMA / vMult;
    def TTI    = VEFA - VESA;
    plot out = TTI;
}
#// VPCI
#// See also: https://www.tradingview.com/script/lmTqKOsa-Indicator-Volume-Price-Confirmation-Indicator-VPCI/
script vpci {
    input long = 25;
    input short = 5;
    def VPC  = vwma(close, long)  - Average(close, long);
    def VPR  = vwma(close, short) / Average(close, short);
    def VM   = Average(volume, short) / Average(volume, long);
    def VPCI = VPC * VPR * VM;
    plot out = if isNaN(VPCI) then 0 else VPCI;
}
#// Calculations
def "DI+"   = DMI(Length = adxLength)."DI+";
def "DI-"   = DMI(Length = adxLength)."DI-";
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX = WildersAverage(DX, adxSmoothingLength);
def TTI = tti(close, ttiFastLength, ttiSlowLength);
def signal = Average(TTI, ttiSignalLength);
def VPCI   = vpci(vpciSlowLength, vpciFastLength);

def ttiL1 = TTI; #,    "TTI", #ff7f00)
def ttiL0 = signal; #, "TTI Signal", #ff7f0050)
def vpcL1 = VPCI * 10; #,"VPCI", #377eb8)
def vpcL0 = if last then na else 0; #,      "VPCI Zero", #377eb850)

plot adxL1 = ADX; #,    "ADX", #984ea3)
plot adxL0 = if last then na else adxThreshold; #,     "ADX Threshold", #984ea350)

adxL0.SetStyle(Curve.SHORT_DASH);
adxL1.SetDefaultColor(Color.MAGENTA);
adxL0.SetDefaultColor(Color.PLUM);

AddCloud(adxL1, adxL0, Color.MAGENTA, Color.CURRENT);
AddCloud(vpcL1, vpcL0, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(ttiL1, ttiL0, Color.ORANGE, Color.VIOLET, yes);

#-- Signals
#/ Strategy entry/exit rules
def buy = ADX > adxThreshold and TTI > signal and VPCI > 0;
def buyCondition = buy and (buy!=buy[1]);
def stopAll = VPCI < 0;
def buyCond;
def closeBuy;
def inTrade;

if buyCondition and !inTrade[1] {
    inTrade = yes;
    buyCond = yes;
    closeBuy = no;
} else if stopAll and inTrade[1] {
    inTrade = no;
    buyCond = no;
    closeBuy = yes;
} else {
    inTrade = inTrade[1];
    buyCond = no;
    closeBuy = no;
}

AddVerticalLine(buyCond, "Buy", Color.GREEN);
AddVerticalLine(closeBuy, "Exit", Color.RED);

#-- END of CODE

Strategy:

CSS:
#// Indicator for TOS
#// © PineCodersTASC
#//  TASC Issue: August 2024 - Vol. 42
#//     Article: Volume Confirmation For A Trend System.
#//              The Trend Thrust Indicator And
#//              Volume Price Confirmation Indicator.
#//  Article By: Buff Pelz Dormeier
#//    Language: TradingView's Pine Script™ v5
#// Provided By: PineCoders, for tradingview.com
#string title = "TASC 2024.08 Volume Confirmation For A Trend System"
# converted by Sam4Cok@Samer800 - 07/2024 (Strategy)

input adxThreshold = 30.0;
input adxLength  = 14;#, "ADX Length", 1)
input adxSmoothingLength = 14;#, "ADX Smoothing", 1, 50)
input ttiFastLength = 13;#, "TTI Fast Average", 1)
input ttiSlowLength = 26;#, "TTI Slow Average", 1)
input ttiSignalLength  = 9;#  "TTI Signal Length", 1)
input vpciFastLength = 5;#,  "VPCI Short-Term Average", 1)
input vpciSlowLength  = 25;#, "VPCI Long-Term Average", 1)

#vwma(source, length)
script VWMA {
    input src = close;
    input len = 14;
    input vol = volume;
    def nom = Average(src * vol, len);
    def den = Average(vol, len);
    def VWMA = nom / den;
    plot result = if isNaN(VWMA) then 0 else VWMA;
}
#// TTI
#// See also: https://www.tradingview.com/script/B6a7HzVn/
script tti {
    input price = close;
    input fast = 13;
    input slow = 26;
    def fastMA = vwma(price, fast);
    def slowMA = vwma(price, slow);
    def VWMACD = fastMA - slowMA;
    def vMult  = Power((fastMA / slowMA), 2);
    def VEFA   = fastMA * vMult;
    def VESA   = slowMA / vMult;
    def TTI    = VEFA - VESA;
    plot out = TTI;
}
#// VPCI
#// See also: https://www.tradingview.com/script/lmTqKOsa-Indicator-Volume-Price-Confirmation-Indicator-VPCI/
script vpci {
    input long = 25;
    input short = 5;
    def VPC  = vwma(close, long)  - Average(close, long);
    def VPR  = vwma(close, short) / Average(close, short);
    def VM   = Average(volume, short) / Average(volume, long);
    def VPCI = VPC * VPR * VM;
    plot out = if isNaN(VPCI) then 0 else VPCI;
}
#// Calculations
def "DI+"   = DMI(Length = adxLength)."DI+";
def "DI-"   = DMI(Length = adxLength)."DI-";
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX = WildersAverage(DX, adxSmoothingLength);
def TTI = tti(close, ttiFastLength, ttiSlowLength);
def signal = Average(TTI, ttiSignalLength);
def VPCI   = vpci(vpciSlowLength, vpciFastLength);


#-- Signals
#/ Strategy entry/exit rules
def buy = ADX > adxThreshold and TTI > signal and VPCI > 0;
def buyCondition = buy and (buy != buy[1]);
def stopAll = VPCI < 0;
def buyCond;
def closeBuy;
def inTrade;

if buyCondition and !inTrade[1] {
    inTrade = yes;
    buyCond = yes;
    closeBuy = no;
} else if stopAll and inTrade[1] {
    inTrade = no;
    buyCond = no;
    closeBuy = yes;
} else {
    inTrade = inTrade[1];
    buyCond = no;
    closeBuy = no;
}

AddOrder(OrderType.BUY_TO_OPEN, buyCond, open[-1], 1, Color.CYAN, Color.CYAN, "BUY");
AddOrder(OrderType.SELL_TO_CLOSE, closeBuy, open[-1], 1, Color.MAGENTA, Color.MAGENTA, "Exit");
#-- END of CODE
 
Last edited by a moderator:
find below the indicator and strategy. * Paste the strategy under the strategy tab.

Indicator :
CSS:
#// Indicator for TOS
#// © PineCodersTASC
#//  TASC Issue: August 2024 - Vol. 42
#//     Article: Volume Confirmation For A Trend System.
#//              The Trend Thrust Indicator And
#//              Volume Price Confirmation Indicator.
#//  Article By: Buff Pelz Dormeier
#//    Language: TradingView's Pine Script™ v5
#// Provided By: PineCoders, for tradingview.com
#string title = "TASC 2024.08 Volume Confirmation For A Trend System"
# converted by Sam4@Samer800    - 07/2024
declare lower;

input adxThreshold = 30.0;
input adxLength  = 14;#, "ADX Length", 1)
input adxSmoothingLength = 14;#, "ADX Smoothing", 1, 50)
input ttiFastLength = 13;#, "TTI Fast Average", 1)
input ttiSlowLength = 26;#, "TTI Slow Average", 1)
input ttiSignalLength  = 9;#  "TTI Signal Length", 1)
input vpciFastLength = 5;#,  "VPCI Short-Term Average", 1)
input vpciSlowLength  = 25;#, "VPCI Long-Term Average", 1)

def na = Double.NaN;
def last = IsNaN(close);

#vwma(source, length)
script VWMA {
    input src = close;
    input len = 14;
    input vol = volume;
    def nom = Average(src * vol, len);
    def den = Average(vol, len);
    def VWMA = nom / den;
    plot result = if isNaN(VWMA) then 0 else VWMA;
}
#// TTI
#// See also: https://www.tradingview.com/script/B6a7HzVn/
script tti {
    input price = close;
    input fast = 13;
    input slow = 26;
    def fastMA = vwma(price, fast);
    def slowMA = vwma(price, slow);
    def VWMACD = fastMA - slowMA;
    def vMult  = Power((fastMA / slowMA), 2);
    def VEFA   = fastMA * vMult;
    def VESA   = slowMA / vMult;
    def TTI    = VEFA - VESA;
    plot out = TTI;
}
#// VPCI
#// See also: https://www.tradingview.com/script/lmTqKOsa-Indicator-Volume-Price-Confirmation-Indicator-VPCI/
script vpci {
    input long = 25;
    input short = 5;
    def VPC  = vwma(close, long)  - Average(close, long);
    def VPR  = vwma(close, short) / Average(close, short);
    def VM   = Average(volume, short) / Average(volume, long);
    def VPCI = VPC * VPR * VM;
    plot out = if isNaN(VPCI) then 0 else VPCI;
}
#// Calculations
def "DI+"   = DMI(Length = adxLength)."DI+";
def "DI-"   = DMI(Length = adxLength)."DI-";
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX = WildersAverage(DX, adxSmoothingLength);
def TTI = tti(close, ttiFastLength, ttiSlowLength);
def signal = Average(TTI, ttiSignalLength);
def VPCI   = vpci(vpciSlowLength, vpciFastLength);

def ttiL1 = TTI; #,    "TTI", #ff7f00)
def ttiL0 = signal; #, "TTI Signal", #ff7f0050)
def vpcL1 = VPCI * 10; #,"VPCI", #377eb8)
def vpcL0 = if last then na else 0; #,      "VPCI Zero", #377eb850)

plot adxL1 = ADX; #,    "ADX", #984ea3)
plot adxL0 = if last then na else adxThreshold; #,     "ADX Threshold", #984ea350)

adxL0.SetStyle(Curve.SHORT_DASH);
adxL1.SetDefaultColor(Color.MAGENTA);
adxL0.SetDefaultColor(Color.PLUM);

AddCloud(adxL1, adxL0, Color.MAGENTA, Color.CURRENT);
AddCloud(vpcL1, vpcL0, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(ttiL1, ttiL0, Color.ORANGE, Color.VIOLET, yes);

#-- Signals
#/ Strategy entry/exit rules
def buy = ADX > adxThreshold and TTI > signal and VPCI > 0;
def buyCondition = buy and (buy!=buy[1]);
def stopAll = VPCI < 0;
def buyCond;
def closeBuy;
def inTrade;

if buyCondition and !inTrade[1] {
    inTrade = yes;
    buyCond = yes;
    closeBuy = no;
} else if stopAll and inTrade[1] {
    inTrade = no;
    buyCond = no;
    closeBuy = yes;
} else {
    inTrade = inTrade[1];
    buyCond = no;
    closeBuy = no;
}

AddVerticalLine(buyCond, "Buy", Color.GREEN);
AddVerticalLine(closeBuy, "Exit", Color.RED);

#-- END of CODE

Strategy:

CSS:
#// Indicator for TOS
#// © PineCodersTASC
#//  TASC Issue: August 2024 - Vol. 42
#//     Article: Volume Confirmation For A Trend System.
#//              The Trend Thrust Indicator And
#//              Volume Price Confirmation Indicator.
#//  Article By: Buff Pelz Dormeier
#//    Language: TradingView's Pine Script™ v5
#// Provided By: PineCoders, for tradingview.com
#string title = "TASC 2024.08 Volume Confirmation For A Trend System"
# converted by Sam4Cok@Samer800 - 07/2024 (Strategy)

input adxThreshold = 30.0;
input adxLength  = 14;#, "ADX Length", 1)
input adxSmoothingLength = 14;#, "ADX Smoothing", 1, 50)
input ttiFastLength = 13;#, "TTI Fast Average", 1)
input ttiSlowLength = 26;#, "TTI Slow Average", 1)
input ttiSignalLength  = 9;#  "TTI Signal Length", 1)
input vpciFastLength = 5;#,  "VPCI Short-Term Average", 1)
input vpciSlowLength  = 25;#, "VPCI Long-Term Average", 1)

#vwma(source, length)
script VWMA {
    input src = close;
    input len = 14;
    input vol = volume;
    def nom = Average(src * vol, len);
    def den = Average(vol, len);
    def VWMA = nom / den;
    plot result = if isNaN(VWMA) then 0 else VWMA;
}
#// TTI
#// See also: https://www.tradingview.com/script/B6a7HzVn/
script tti {
    input price = close;
    input fast = 13;
    input slow = 26;
    def fastMA = vwma(price, fast);
    def slowMA = vwma(price, slow);
    def VWMACD = fastMA - slowMA;
    def vMult  = Power((fastMA / slowMA), 2);
    def VEFA   = fastMA * vMult;
    def VESA   = slowMA / vMult;
    def TTI    = VEFA - VESA;
    plot out = TTI;
}
#// VPCI
#// See also: https://www.tradingview.com/script/lmTqKOsa-Indicator-Volume-Price-Confirmation-Indicator-VPCI/
script vpci {
    input long = 25;
    input short = 5;
    def VPC  = vwma(close, long)  - Average(close, long);
    def VPR  = vwma(close, short) / Average(close, short);
    def VM   = Average(volume, short) / Average(volume, long);
    def VPCI = VPC * VPR * VM;
    plot out = if isNaN(VPCI) then 0 else VPCI;
}
#// Calculations
def "DI+"   = DMI(Length = adxLength)."DI+";
def "DI-"   = DMI(Length = adxLength)."DI-";
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX = WildersAverage(DX, adxSmoothingLength);
def TTI = tti(close, ttiFastLength, ttiSlowLength);
def signal = Average(TTI, ttiSignalLength);
def VPCI   = vpci(vpciSlowLength, vpciFastLength);


#-- Signals
#/ Strategy entry/exit rules
def buy = ADX > adxThreshold and TTI > signal and VPCI > 0;
def buyCondition = buy and (buy != buy[1]);
def stopAll = VPCI < 0;
def buyCond;
def closeBuy;
def inTrade;

if buyCondition and !inTrade[1] {
    inTrade = yes;
    buyCond = yes;
    closeBuy = no;
} else if stopAll and inTrade[1] {
    inTrade = no;
    buyCond = no;
    closeBuy = yes;
} else {
    inTrade = inTrade[1];
    buyCond = no;
    closeBuy = no;
}

AddOrder(OrderType.BUY_TO_OPEN, buyCond, open[-1], 1, Color.CYAN, Color.CYAN, "BUY");
AddOrder(OrderType.SELL_TO_CLOSE, closeBuy, open[-1], 1, Color.MAGENTA, Color.MAGENTA, "Exit");
#-- END of CODE
Thanks Samer, your work is appreciated, on this and many other projects
 
Looking for the:
“Volume Confirmation For A Trend System.”
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
362 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top