Future Trend Channel [ChartPrime] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
NiO1k2q.png


Author Message:

he Future Trend Channel [ChartPrime] indicator is a dynamic tool for identifying trends and projecting future prices based on channel formations. The indicator uses SMA (Simple Moving Average) and volatility calculations to plot channels that visually represent trends. It also detects moments of lower momentum, indicated by neutral color changes in the channels, and projects future price levels for up to 50 bars ahead.

CODE:

CSS:
#// Indicator for TOS
#// © ChartPrime
#indicator("Future Trend Channel [ChartPrime]", overlay = true, max_lines_count = 500)
# Converted by Sam4Cok@Samer800     - 11/2024 - Not Exact Conv.

input colorBars = no;
input src = hl2;
input TrendLength = 100; #, "Trend Length")
input ChannelWidth  = 3.0; #, "Channel Width", step = 0.1)
input IndexOfFuturePrice = 50; #, "Index of future price")

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

def nATR = atr(Length = 200);
def atr = highest(nATR, 100);

#trend(length)=>
def sma = average(close, TrendLength);
def upper = sma + atr;
def lower = sma - atr;
def signal_up = (close > upper) and (close[1] <= upper[1]);
def signal_dn = (close < lower) and (close[1] >= lower[1]);
def trend = if signal_up then yes else if signal_dn then no else trend[1];
def bullTrend = if !last then (trend and !trend[1]) else bullTrend[1];
def bearTrend = if !last then (!trend and trend[1]) else bearTrend[1];
def changeTrend = if bullTrend then yes else if bearTrend then yes else no;


def low_src  = src - atr * ChannelWidth;
def high_src = src + atr * ChannelWidth;

def line_mid1 = if bullTrend then src else
                if bearTrend then src else
                if last[-1] then Average(close, 20) else line_mid1[1];
def line_top1 = if bullTrend then high_src else
                if bearTrend  then high_src else
                if last[-1] then Average(high_src, 20) else na;
def line_low1 = if bullTrend then low_src else
                if bearTrend then low_src else
                if last[-1] then Average(low_src, 20) else na;

def line_mid2 = if bullTrend then src else
                if bearTrend then src else Average(close, 20);

def change = CompoundValue(1, line_mid1!=line_mid1[1] and !last, yes);
def y2Mid;
def y1Mid;
def y1Top;
def y2Top;
def y1Low;
def y2Low;
def x2;
def x1;
if (change ) {
    y2Mid = y1Mid[1];
    y1Mid = line_mid1;
    y2Top = y1Top[1];
    y1Top = line_top1;
    y2Low = y1Low[1];
    y1Low = line_low1;
    x2 = x1[1];
    x1 = n;
    } else {
    y2Mid = y2Mid[1];
    y1Mid = y1Mid[1];
    y2Top = y2Top[1];
    y1Top = y1Top[1];
    y2Low = y2Low[1];
    y1Low = y1Low[1];
    x2 = x2[1];
    x1 = x1[1];
}

def cnt1 = if change then 0 else cnt1[1] + 1;
def cnt = cnt1; #if !cnt1 then cnt1[1] else cnt1;

def slopeM = (y1Mid - y2Mid) / (x1 - x2);
def slopeT = (y1Top - y2Top) / (x1 - x2);
def slopeL = (y1Low - y2Low) / (x1 - x2);
def mid = y2Mid + ((n - x2) * slopeM);
def top = y2Top + ((n - x2) * slopeT);
def Btm = y2Low + ((n - x2) * slopeL);

def col1 = if changeTrend then
           if trend  and line_mid2 > GetValue(line_mid2, cnt[1]) then  1 else
           if !trend and line_mid2 < GetValue(line_mid2, cnt[1]) then -1 else 0 else
           if !last[-1] then
           if trend  and line_mid2 > GetValue(line_mid2, cnt) then  1 else
           if !trend and line_mid2 < GetValue(line_mid2, cnt) then -1 else 0 else
           if last[-1] then
           if trend  and line_mid2 > GetValue(line_mid2, cnt) then  1 else
           if !trend and line_mid2 < GetValue(line_mid2, cnt) then -1 else 0 else col1[1];

def col = if !last[-1] then col1 else col[1];


plot extendMid = if last[-1] then mid else na;
plot extendTop = if last[-1] then top else na;
plot extendLow = if last[-1] then Btm else na;

plot midLine = if change    then line_mid1 else na;
plot topLine = if line_top1 then line_top1 else na;
plot lowLine = if line_low1 then line_low1 else na;

extendMid.AssignValueColor(if col > 0 then Color.GREEN else
                           if col < 0 then Color.RED else Color.GRAY);
extendTop.AssignValueColor(if col > 0 then Color.GREEN else
                           if col < 0 then Color.RED else Color.GRAY);
extendLow.AssignValueColor(if col > 0 then Color.GREEN else
                           if col < 0 then Color.RED else Color.GRAY);
midLine.AssignValueColor(if col > 0 then Color.GREEN else
                         if col < 0 then Color.RED else Color.GRAY);
topLine.AssignValueColor(if col > 0 then Color.GREEN else
                         if col < 0 then Color.RED else Color.GRAY);
lowLine.AssignValueColor(if col > 0 then Color.GREEN else
                         if col < 0 then Color.RED else Color.GRAY);
midLine.EnableApproximation();
topLine.EnableApproximation();
lowLine.EnableApproximation();

#-- trend change;
plot label_up = if bullTrend then low_src else na;
plot label_dn = if bearTrend then high_src else na;

label_up.SetPaintingStrategy(PaintingStrategy.SQUARES);
label_dn.SetPaintingStrategy(PaintingStrategy.SQUARES);
label_up.SetDefaultColor(Color.CYAN);
label_Dn.SetDefaultColor(Color.MAGENTA);

#-- Labels
def future = mid[-IndexOfFuturePrice+1];
AddLabel(1, "Future Price (" + AsDollars(future) + ")",
            if future > close then Color.GREEN else Color.RED);
AssignPriceColor(if !colorBars then color.CURRENT else
                 if col > 0 then Color.CYAN else
                 if col < 0 then Color.MAGENTA else Color.GRAY);
# ENd of 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
303 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