Responsive, Non-Repainting Laguerre ZigZag For ThinkOrSwim

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

@whoDAT Do you have any idea why the up/down signals don't plot?

I am looking for a zigzag function that I can use in a custom watchlist column to provide a "heads up" that trend is shifting. I tried using criksdds AGAIG No Arrows but it is a repainter and does not work in a watchlist.

The goal is to change the background in the watchlist column based on trend direction and I think that if I can figure out why the up/down signals are not showing, I'll be able to capture the info.

View attachment 27075

Thanks.

Hi, I like your buy and sell signals. What indicator or thinkscript code are your buy and sell signals?
Thank you.
 
Last edited by a moderator:
To all participants: Well, done. For swing traders, the PSAR indicator developed by Wells Wilder can serve as an effective tool. The line function enables precise and visually distinct pivots with only minor adjustments. A limitation of the ZigZag indicator is that its input parameters are inherently subjective; whether you choose 3%, 5%, or 10% is based on individual preference rather than objective criteria. Try it.
1776246613093.png
 
Just for anyone interested I tweaked the EMA_TREND_METER for better reads and signals
Code:
# =========================================
# ANTWERKS UNIFIED ENGINE + SESSION INTELLIGENCE
# =========================================

declare lower;

# =========================
# INPUTS
# =========================
input fastLength = 9;
input slowLength = 21;
input atrLength = 14;
input expansionLevel = 0.3;
input stretchLevel = 0.8;
input higherAgg = AggregationPeriod.HOUR;

# 🔥 NEW SESSION CONTROLS
input useSessionFilter = yes;
input restrictToRTH = yes;

# =========================
# SESSION ENGINE (NEW)
# =========================
def isRTH =
    SecondsFromTime(0930) >= 0 and
    SecondsTillTime(1600) > 0;

def isEXT = !isRTH;

def sessionActive =
    if !useSessionFilter then 1
    else if restrictToRTH then isRTH
    else 1;

# =========================
# CURRENT TF
# =========================
def fastEMA = ExpAverage(close, fastLength);
def slowEMA = ExpAverage(close, slowLength);
def atr = Average(TrueRange(high, close, low), atrLength);

def spread = (fastEMA - slowEMA) / atr;

# 🔥 MOMENTUM ENGINE
def spreadSlope = spread - spread[1];
def accelerating = spreadSlope > 0;
def decelerating = spreadSlope < 0;

# 🔥 TREND + STATE
def bullishTrend = fastEMA > slowEMA;
def bearishTrend = fastEMA < slowEMA;

def compression = AbsValue(spread) < expansionLevel;
def expandingUp = spread > expansionLevel and spread > spread[1];
def expandingDown = spread < -expansionLevel and spread < spread[1];

def trendStrength = AbsValue(fastEMA - slowEMA);

# 🔥 QUALITY FILTER (UNCHANGED CORE)
def validCompression =
    compression and
    trendStrength > atr * 0.5;

# =========================
# HIGHER TF
# =========================
def hClose = close(period = higherAgg);
def hFast = ExpAverage(hClose, fastLength);
def hSlow = ExpAverage(hClose, slowLength);

def higherBull = hFast > hSlow;
def higherBear = hFast < hSlow;

# =========================
# LIQUIDITY SWEEP ENGINE (MERGED)
# =========================
input sweepLookback = 10;

def sweepRefHigh = Highest(high[1], sweepLookback);
def sweepRefLow  = Lowest(low[1], sweepLookback);

def sweepHigh =
    high > sweepRefHigh and
    close < sweepRefHigh and
    close < open;

def sweepLow =
    low < sweepRefLow and
    close > sweepRefLow and
    close > open;

# =========================
# PIVOT SWEEP ENGINE (MERGED)
# =========================
input pivotLength = 10;

def swingHigh =
    high[pivotLength] == Highest(high, pivotLength * 2 + 1);

def swingLow =
    low[pivotLength] == Lowest(low, pivotLength * 2 + 1);

rec lastHigh =
    if swingHigh then high[pivotLength]
    else lastHigh[1];

rec lastLow =
    if swingLow then low[pivotLength]
    else lastLow[1];

def bearSweep =
    high > lastHigh and
    close < lastHigh;

def bullSweep =
    low < lastLow and
    close > lastLow;

# =========================
# SIGNAL LOGIC (UNCHANGED CORE)
# =========================
def pullback =
    bullishTrend and
    higherBull and
    compression and
    spread > 0;

def qualifiedPullback =
    pullback and sweepLow;

def momentumFailure =
    spread > expansionLevel and
    spreadSlope < 0 and
    spreadSlope[1] < 0;

# =========================
# 🚫 SESSION FILTER APPLIED HERE (KEY)
# =========================
def finalLong =
    qualifiedPullback
    and sessionActive;

def finalShort =
    momentumFailure
    and sessionActive;

# =========================
# PLOTS
# =========================
plot SpreadATR = spread;
SpreadATR.SetLineWeight(2);

SpreadATR.AssignValueColor(
    if spread > stretchLevel then Color.GREEN
    else if spread > expansionLevel then Color.DARK_GREEN
    else if spread < -stretchLevel then Color.RED
    else if spread < -expansionLevel then Color.DARK_RED
    else Color.YELLOW
);

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.GRAY);

# =========================
# SIGNAL ARROWS (NOW SESSION-AWARE)
# =========================
plot LongSignal =
    if finalLong then spread else Double.NaN;

LongSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
LongSignal.SetDefaultColor(Color.CYAN);
LongSignal.SetLineWeight(3);

plot ShortSignal =
    if finalShort then spread else Double.NaN;

ShortSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ShortSignal.SetDefaultColor(Color.YELLOW);
ShortSignal.SetLineWeight(3);

# =========================
# SWEEP VISUALS (UNCHANGED)
# =========================
plot SweepUp =
    if sweepLow then spread else Double.NaN;

SweepUp.SetPaintingStrategy(PaintingStrategy.POINTS);
SweepUp.SetDefaultColor(Color.GREEN);

plot SweepDown =
    if sweepHigh then spread else Double.NaN;

SweepDown.SetPaintingStrategy(PaintingStrategy.POINTS);
SweepDown.SetDefaultColor(Color.RED);

# =========================
# SESSION LABELING (NEW)
# =========================
AddLabel(yes,
    if isRTH then "SESSION: RTH"
    else "SESSION: EXTENDED",
    if isRTH then Color.GREEN else Color.GRAY
);

AddLabel(useSessionFilter,
    if !sessionActive then "SIGNALS BLOCKED (EXT)"
    else "SIGNALS ACTIVE",
    if sessionActive then Color.GREEN else Color.RED
);

# =========================
# ORIGINAL LABELS PRESERVED
# =========================
AddLabel(higherBull and bullishTrend,
    "MTF ALIGN: BULL",
    Color.GREEN);

AddLabel(pullback,
    "PULLBACK READY",
    Color.YELLOW);

AddLabel(expandingUp,
    "EXPANSION TRIGGER",
    Color.CYAN);

# =========================
# MOMENTUM SHIFT DOTS (RESTORED)
# =========================

def momentumShiftUp =
    accelerating
    and spread > 0
    and spread[1] <= 0;

plot momentumShiftUp1 =
    if momentumShiftUp then spread else Double.NaN;

momentumShiftUp1.SetPaintingStrategy(PaintingStrategy.POINTS);
MomentumShiftUp1.SetDefaultColor(Color.CYAN);
MomentumShiftUp1.SetLineWeight(3);

plot MomentumShiftDown =
    if decelerating and spread > 0 then spread else Double.NaN;

MomentumShiftDown.SetPaintingStrategy(PaintingStrategy.POINTS);
MomentumShiftDown.SetDefaultColor(Color.YELLOW);
MomentumShiftDown.SetLineWeight(2);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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