Trend Levels [ChartPrime] For ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
KzIqwjU.png


Author Message:

The Trend Levels [ChartPrime] indicator is designed to identify key trend levels (High, Mid, and Low) during market trends, based on real-time calculations of highest, lowest, and mid-level values over a customizable length. Additionally, the indicator calculates trend strength by measuring the ratio of candles closing above or below the midline, providing a clear view of the ongoing trend dynamics and strength.

CODE:

CSS:
# Indicator for TOS
#// © ChartPrime
#indicator("Trend Levels [ChartPrime]", overlay = true, max_labels_count = 500)
# Converted by Sam4Cok@Samer800    - 11/2024

input timeframe = AggregationPeriod.MIN;
input colorBars = yes;
input length = 30;


def na = Double.NaN;
def last = IsNaN(close);
def current = GetAggregationPeriod();
def tf = Max(current, timeframe);
#-- Color
DefineGlobalColor("up", Color.CYAN);
DefineGlobalColor("dn", Color.MAGENTA);
#// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
#// Calculate highest and lowest over the specified length
def h = Highest(high(Period = tf), length);
def l = Lowest(low(Period = tf), length);
#// Determine trend direction: if the current high is the highest value, set trend to true
def trend;
if h == high(Period = tf) {
    trend = yes;
#// If the current low is the lowest value, set trend to false
} else if l == low(Period = tf) {
    trend = no;
} else {
    trend = trend[1];
}
def change = trend - trend[1];
def bars = if change then 1 else if !trend then bars[1] + 1 else if trend then bars[1] + 1 else bars[1];

#// Calculate highest, lowest, and mid-level values based on the number of bars
def h11 = fold i = 0 to bars with p = high(Period = tf) do
         Max(p, GetValue(high(Period = tf), i));
def l11 = fold j = 0 to bars with q = low(Period = tf) do
         Min(q, GetValue(low(Period = tf), j));
def m11 = (h11 + l11) / 2;
def h1; def l1; def m1;
if bars == 1 {
    h1 = na;
    l1 = na;
    m1 = na;
} else {
    h1 = h11;
    l1 = l11;
    m1 = m11;
}
#// Update counters for up and down closes based on the mid-level value
def count_up = if isNaN(m1) then 1 else if close(Period = tf) > m1 then count_up[1] + 1 else count_up[1];
def count_dn = if isNaN(m1) then 1 else if close(Period = tf) < m1 then count_dn[1] + 1 else count_dn[1];

#// Calculate the delta percentage between up and down counts
def total         = count_up + count_dn;
def delta_percent = (count_up - count_dn) / total;
def col = if isNaN(delta_percent) then 0 else AbsValue(delta_percent) * 255;

#// Plot the high, low, and mid levels as lines
plot sigUp = if (trend and !trend[1]) then low else na;
plot sigDn = if (trend[1] and !trend) then high else na;
plot pl = if l1 then l1 else na;
plot ph = if h1 then h1 else na;
plot pm = if m1 then m1 else na;

sigUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
sigDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
sigUp.SetDefaultColor(GlobalColor("up"));
sigDn.SetDefaultColor(GlobalColor("dn"));
pm.SetStyle(Curve.SHORT_DASH);
ph.SetDefaultColor(GlobalColor("up"));
pl.SetDefaultColor(GlobalColor("dn"));
pm.SetDefaultColor(Color.GRAY);

#-- Cloud

AddCloud(if delta_percent > 0.25 then ph else na, Max(open, close), Color.DARK_GREEN);
AddCloud(if delta_percent < -0.25 then Min(open, close) else na, pl, Color.DARK_RED);

#-- Label
AddLabel(1, "Trend (" + AsPercent(delta_percent) + ")", if delta_percent>0 then Color.GREEN else Color.RED);

#-- Bar Color
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if delta_percent > 0.25 then CreateColor(0, col, col) else
                 if delta_percent < -0.25 then CreateColor(col, 0, col) else Color.DARK_GRAY);

#-- END of CODE
 
Hi has anyone created this indicator called Trend Levels by chart Prime in Trading View? Here is the YT video link :
I would love it if anyone can code this for TOS? Thanks in advance
 
Last edited by a moderator:

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
398 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