Repaints Zig Zag Channels [LuxAlgo] For ThinkOrSwim

Repaints

Katsu

Member
VIP
This ZigZag is a useful indicator when it comes to visualizing past underlying trends in the price and can make the process of using drawing tools easier.

cUGFnnV.png


original Tradingview script:
https://www.tradingview.com/script/a2PJSO1p-Zig-Zag-Channels-LuxAlgo/
ThinkOrSwim script is in the next post.
 
Last edited by a moderator:

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

Can you please convert the Zig Zag indicator from tradingview? It is a useful indicator when it comes to visualizing past underlying trends in the price and can make the process of using drawing tools easier.
https://www.tradingview.com/script/a2PJSO1p-Zig-Zag-Channels-LuxAlgo/
check the below:

CSS:
#// Indicator for TOS
#// © LuxAlgo
#study("Zig Zag Channels [LuxAlgo]",overlay=true
# converted by Sam4Cok@Samer800    - 08/2024
input src = close;
input length      = 100; #
input extendLines     = yes;
input showRepaintedChannel = yes;
input ShowExtremities = yes; #(true,'Show Extremities')
input ShowLabels = yes; #(true,'Show Labels')

def na = Double.NaN;
def last = isNaN(close);
def n = BarNumber();
def extedn = if extendLines then yes else !last;

def upper = Highest(src, length);
def lower = Lowest(src, length);
def os = if src[length] > upper then 0 else
         if src[length] < lower then 1 else os[1];
def btm1 = os == 1 and os[1] != 1;
def top1 = os == 0 and os[1] != 0;
def btm = if isNaN(btm1[-length]) then btm[1] else btm1[-length];
def top = if isNaN(top1[-length]) then top[1] else top1[-length];
def dir = if !last then if btm then 0 else if top then 1 else dir[1] else dir[1];
def zigzag = if top then high else
             if btm then low else na;
#-- BaseLine
def startPrice = if btm then low else if top then high else startPrice[1];
def x1 = if top then n else if btm then n else x1[1];
def x2 = if !last then n else x2[1];
def y1 = if n == HighestAll(x1) then startPrice else y1[1];
def y2 = if n == HighestAll(x2) then src else y2[1];
def x11= highestall(x1);
def x22= highestall(x2);
def y22= highestall(y2);
def slope = (y22 - y1)/(x22 - x1);
def base = y1 + ((n - x11) * slope);
def baseLine = if n >= x11 then base else na;
def max = Max(close, open);
def min = Min(close, open);
def maxx = if isNaN(baseLine) then 0 else if max>baseLine then (max - baseLine) else maxx[1];
def minn = if isNaN(baseLine) then 0 else if min<baseLine then (baseLine - min) else minn[1];
def up = if !isNaN(baseLine) then highestAll(maxx) else up[1];
def lo = if !isNaN(baseLine) then highestAll(minn) else lo[1];

#--- plot
plot zigzagLine = zigzag;
zigzagLine.AssignValueColor(if dir[1] then GetColor(2) else GetColor(6));
zigzagLine.EnableApproximation();

plot trendLine = if showRepaintedChannel and extedn then baseLine else na;
plot UpChannel = if ShowExtremities and extedn then trendLine + up else na;
plot LoChannel = if ShowExtremities and extedn then trendLine - lo else na;
trendLine.AssignValueColor(if slope>0 then GetColor(6) else GetColor(2));
UpChannel.SetDefaultColor(GetColor(1));
LoChannel.SetDefaultColor(GetColor(0));
UpChannel.SetStyle(Curve.MEDIUM_DASH);
LoChannel.SetStyle(Curve.MEDIUM_DASH);


AddChartBubble(ShowLabels and top, high, AsDollars(high), Color.GREEN);
AddChartBubble(ShowLabels and btm, low, AsDollars(low), Color.RED, no);

AddLabel(ShowLabels, if slope>0 then "Trend Up" else "Trend Down", if slope>0 then Color.GREEN else Color.RED);

#-- END of CODE
 
check the below:

CSS:
#// Indicator for TOS
#// © LuxAlgo
#study("Zig Zag Channels [LuxAlgo]",overlay=true
# converted by Sam4Cok@Samer800    - 08/2024
input src = close;
input length      = 100; #
input extendLines     = yes;
input showRepaintedChannel = yes;
input ShowExtremities = yes; #(true,'Show Extremities')
input ShowLabels = yes; #(true,'Show Labels')

def na = Double.NaN;
def last = isNaN(close);
def n = BarNumber();
def extedn = if extendLines then yes else !last;

def upper = Highest(src, length);
def lower = Lowest(src, length);
def os = if src[length] > upper then 0 else
         if src[length] < lower then 1 else os[1];
def btm1 = os == 1 and os[1] != 1;
def top1 = os == 0 and os[1] != 0;
def btm = if isNaN(btm1[-length]) then btm[1] else btm1[-length];
def top = if isNaN(top1[-length]) then top[1] else top1[-length];
def dir = if !last then if btm then 0 else if top then 1 else dir[1] else dir[1];
def zigzag = if top then high else
             if btm then low else na;
#-- BaseLine
def startPrice = if btm then low else if top then high else startPrice[1];
def x1 = if top then n else if btm then n else x1[1];
def x2 = if !last then n else x2[1];
def y1 = if n == HighestAll(x1) then startPrice else y1[1];
def y2 = if n == HighestAll(x2) then src else y2[1];
def x11= highestall(x1);
def x22= highestall(x2);
def y22= highestall(y2);
def slope = (y22 - y1)/(x22 - x1);
def base = y1 + ((n - x11) * slope);
def baseLine = if n >= x11 then base else na;
def max = Max(close, open);
def min = Min(close, open);
def maxx = if isNaN(baseLine) then 0 else if max>baseLine then (max - baseLine) else maxx[1];
def minn = if isNaN(baseLine) then 0 else if min<baseLine then (baseLine - min) else minn[1];
def up = if !isNaN(baseLine) then highestAll(maxx) else up[1];
def lo = if !isNaN(baseLine) then highestAll(minn) else lo[1];

#--- plot
plot zigzagLine = zigzag;
zigzagLine.AssignValueColor(if dir[1] then GetColor(2) else GetColor(6));
zigzagLine.EnableApproximation();

plot trendLine = if showRepaintedChannel and extedn then baseLine else na;
plot UpChannel = if ShowExtremities and extedn then trendLine + up else na;
plot LoChannel = if ShowExtremities and extedn then trendLine - lo else na;
trendLine.AssignValueColor(if slope>0 then GetColor(6) else GetColor(2));
UpChannel.SetDefaultColor(GetColor(1));
LoChannel.SetDefaultColor(GetColor(0));
UpChannel.SetStyle(Curve.MEDIUM_DASH);
LoChannel.SetStyle(Curve.MEDIUM_DASH);


AddChartBubble(ShowLabels and top, high, AsDollars(high), Color.GREEN);
AddChartBubble(ShowLabels and btm, low, AsDollars(low), Color.RED, no);

AddLabel(ShowLabels, if slope>0 then "Trend Up" else "Trend Down", if slope>0 then Color.GREEN else Color.RED);

#-- END of CODE
Hi Samer800, can you please provide scanner for when the price crosses the lochannel and upchannel? Thanks
 
Last edited:
Hi Samer800, can you please provide scanner for when the price crosses the lochannel and upchannel? Thanks

Unfortunately, no.

Attempting to scan for repainting signals, is a wack-a-mole game that leaves most forum members frustrated.

As such, the forum does not support, nor provide support for, repainting scanners.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
334 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