RedK Trader Pressure Index (TPX) for ThinkOrSwim

samer800

Conversion Expert
VIP
Lifetime
0gQYP4i.png


check below link for release note with instruction
https://www.tradingview.com/script/v8sBugsW-RedK-Trader-Pressure-Index-TPX-v1-0/

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © RedKTrader
#//@version=5
#indicator('RedK Trader Pressure Index (TPX)', shorttitle='RedK_TPX v5.0'
#https://www.tradingview.com/script/v8sBugsW-RedK-Trader-Pressure-Index-TPX-v1-0/
# Converted by Sam4Cok@Samer800 - 08/2022
# Request from https://usethinkscript.com/ memeber

#// Inputs
#//============================================
input length  = 7;        # 'Avg Length'
input smooth  = 3;        # 'Smoothing'

#// CLevel is the "critical or control" level, whoever builds pressure that exceeds that level will be in control
input ControlLevel  = 30;       # 'Control Level'

#// version 3.0 - adding optional pre-smoothing - will cause a signal lag of ~1 bar @ value of 3 - will be off by default   
input UsePerSmooth = no;       # 'Pre-smoothing?'
input PreSmoothing  = 3;        # 'pre-smoothing'

#// version 4.0 adds Dominant Pressure Signal and enables basic Alerts
input SignalLine  = yes;    # 'Pressure Signal Line?'
input sigLevel      = 70;     # 'signal'
#==============================================
declare lower;
def na = Double.NaN;
script nz {
    input data = 0;
    input replacement  = 0;
    def ret_val = if IsNaN(data) then replacement else data;
    plot return = ret_val;
}
#// =========================================================================
#// Calculations
#// =========================================================================
#//R is the 2-bar range used as "baseline" or denominator
def R = Highest(high, 2) - Lowest(low, 2);

#// Bull pressure is represented by how far they can pull the high and the low of previous bar up relative to the 2-bar range
def hiup    = Max((high - high[1]), 0);
def loup    = Max((low - low[1]), 0);
def bulls   = Min((hiup + loup) / R, 1) * 100; # //prevent big gaps causing a % over 100%
def avgbull = WMA(bulls, length);

def avgbulls = if UsePerSmooth then WMA(avgbull, PreSmoothing) else avgbull;

#// Bear pressure is represented by how far they can push the high and the low of previous bar down relative to the 2-bar range
def hidn     = Min((high - high[1]), 0);
def lodn     = Min((low - low[1]), 0);
def bears    = Max((hidn + lodn) / R, -1) * -100;  #//convert to positive value
def avgbear  = WMA(bears, length);

def avgbears = if UsePerSmooth then WMA(avgbear, PreSmoothing) else avgbear;

def net      = avgbulls - avgbears;
def TPX      = WMA(net, smooth); # // final smoothing
#// ===============================================================
#//      Colors & plots
#// ===============================================================
DefineGlobalColor("col_bulls"  , CreateColor(51,255,0));
DefineGlobalColor("col_bears" , CreateColor(255,17,17));
DefineGlobalColor("col_level"  , Color.GRAY);
DefineGlobalColor("col_TPXup"  , Color.WHITE);
DefineGlobalColor("col_TPXdn" , Color.GRAY);
##########################################################

plot TPXLine = TPX;    # 'Net Pressure'
TPXLine.AssignValueColor( if TPX > 0 then GlobalColor("col_TPXup") else GlobalColor("col_TPXdn"));
TPXLine.SetLineWeight(3);

plot zeroLine = 0;
zeroLine.SetDefaultColor(GlobalColor("col_level"));
plot CLine = ControlLevel;    # 'Control Level'
CLine.SetDefaultColor(GlobalColor("col_level"));
CLine.SetPaintingStrategy(PaintingStrategy.DASHES);

plot Bearavg = avgbears;    # 'Bear Pressure'
Bearavg.SetDefaultColor(GlobalColor("col_bears"));
Bearavg.SetLineWeight(2);
plot Bullavg = avgbulls;    # 'Bull Pressure'
Bullavg.SetDefaultColor(GlobalColor("col_bulls"));
Bullavg.SetLineWeight(2);

#// version 4.0 adds Dominant Pressure Signal and enables basic Alerts

def maxbulls    = avgbulls >= ControlLevel;
def maxbears    = avgbears >= ControlLevel;
def TPXswing    = crosses(TPX, 0);

plot cold = if maxbears and SignalLine then sigLevel else na;   # 'Cold area'
cold.SetPaintingStrategy(PaintingStrategy.POINTS);
cold.SetDefaultColor(Color.RED);
cold.SetLineWeight(2);
plot hot = if maxbulls and SignalLine then sigLevel else na;    # 'Hot area'
hot.SetPaintingStrategy(PaintingStrategy.SQUARES);
hot.SetDefaultColor(Color.LIME);
hot.SetLineWeight(2);

addCloud(Bullavg,0,GlobalColor("col_bulls"));
addCloud(Bearavg,0,GlobalColor("col_bears"));

#### END Code
 
Can you please convert it to MTF ?
check the below

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © RedKTrader
#//@version=5
#indicator('RedK Trader Pressure Index (TPX)', shorttitle='RedK_TPX v5.0'
#https://www.tradingview.com/script/v8sBugsW-RedK-Trader-Pressure-Index-TPX-v1-0/
# Converted by Sam4Cok@Samer800 - 08/2022
# Request from https://usethinkscript.com/ memeber
# Update" Added MTF option - 06/2023

#// Inputs
#//============================================
input useChartTimeframe = {Default "Yes", "No"};
input manualTimeframe = AggregationPeriod.FIFTEEN_MIN;
input TrendLine  = yes;    # 'Pressure Signal Line?'
input showTPX = no;
input length  = 7;        # 'Avg Length'
input smooth  = 3;        # 'Smoothing'
#// CLevel is the "critical or control" level, whoever builds pressure that exceeds that level will be in control
input ControlLevel  = 30;       # 'Control Level'

#// version 3.0 - adding optional pre-smoothing - will cause a signal lag of ~1 bar @ value of 3 - will be off by default   
input UsePerSmooth = no;       # 'Pre-smoothing?'
input PreSmoothing  = 3;        # 'pre-smoothing'

#// version 4.0 adds Dominant Pressure Signal and enables basic Alerts

input sigLevel      = 70;     # 'signal'
#==============================================
declare lower;
def na = Double.NaN;
def last = isNaN(close);
def h; def l;
Switch(useChartTimeframe) {
Case "Yes":
    h = high;
    l = low;
Case "No":
    h = high(Period=manualTimeframe);
    l = low(Period=manualTimeframe);
}

script nz {
    input data = 0;
    input replacement  = 0;
    def ret_val = if IsNaN(data) then replacement else data;
    plot return = ret_val;
}
#// =========================================================================
#// Calculations
#// =========================================================================
#//R is the 2-bar range used as "baseline" or denominator
def R = Highest(h, 2) - Lowest(l, 2);

#// Bull pressure is represented by how far they can pull the high and the low of previous bar up relative to the 2-bar range
def hiup    = Max((h - h[1]), 0);
def loup    = Max((l - l[1]), 0);
def bulls   = Min((hiup + loup) / R, 1) * 100; # //prevent big gaps causing a % over 100%
def avgbull = WMA(nz(bulls), length);

def avgbulls = if UsePerSmooth then WMA(avgbull, PreSmoothing) else avgbull;

#// Bear pressure is represented by how far they can push the high and the low of previous bar down relative to the 2-bar range
def hidn     = Min((h - h[1]), 0);
def lodn     = Min((l - l[1]), 0);
def bears    = Max((hidn + lodn) / R, -1) * -100;  #//convert to positive value
def avgbear  = WMA(nz(bears), length);

def avgbears = if UsePerSmooth then WMA(avgbear, PreSmoothing) else avgbear;

def net      = avgbulls - avgbears;
def TPX      = WMA(net, smooth); # // final smoothing
#// ===============================================================
#//      Colors & plots
#// ===============================================================
DefineGlobalColor("col_bulls"  , CreateColor(51,255,0));
DefineGlobalColor("col_bears" , CreateColor(255,17,17));
DefineGlobalColor("col_level"  , Color.GRAY);
DefineGlobalColor("col_TPXup"  , Color.WHITE);
DefineGlobalColor("col_TPXdn" , Color.GRAY);
##########################################################

plot TPXLine = if last then na else TPX;    # 'Net Pressure'
TPXLine.AssignValueColor( if TPX > 0 then GlobalColor("col_TPXup") else GlobalColor("col_TPXdn"));
TPXLine.SetLineWeight(3);
TPXLine.SetHiding(!showTPX);

plot zeroLine = if last then na else 0;
zeroLine.SetDefaultColor(GlobalColor("col_level"));
plot CLine = ControlLevel;    # 'Control Level'
CLine.SetDefaultColor(GlobalColor("col_level"));
CLine.SetPaintingStrategy(PaintingStrategy.DASHES);

plot Bearavg = if last then na else avgbears;    # 'Bear Pressure'
Bearavg.SetDefaultColor(GlobalColor("col_bears"));
Bearavg.SetLineWeight(2);

plot Bullavg = if last then na else avgbulls;    # 'Bull Pressure'
Bullavg.SetDefaultColor(GlobalColor("col_bulls"));
Bullavg.SetLineWeight(2);

#// version 4.0 adds Dominant Pressure Signal and enables basic Alerts

def maxbulls    = avgbulls >= ControlLevel;
def maxbears    = avgbears >= ControlLevel;
def TPXswing    = crosses(TPX, 0);

plot cold = if last then na else
            if maxbears and TrendLine then sigLevel else na;   # 'Cold area'
cold.SetPaintingStrategy(PaintingStrategy.POINTS);
cold.SetDefaultColor(Color.RED);
cold.SetLineWeight(2);
plot hot = if last then na else
           if maxbulls and TrendLine then sigLevel else na;    # 'Hot area'
hot.SetPaintingStrategy(PaintingStrategy.SQUARES);
hot.SetDefaultColor(Color.LIME);
hot.SetLineWeight(2);

addCloud(Bullavg,0,GlobalColor("col_bulls"));
addCloud(Bearavg,0,GlobalColor("col_bears"));

#### END Code
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
576 Online
Create Post

Similar threads

Similar threads

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