Zero Lag Signals For Loop [QuantAlgo] For ThinkOrSwim

sunnybabu

Member
Plus
The author states: The foundation of this indicator rests on its zero-lag implementation and dynamic trend assessment. By utilizing a loop-driven scoring system alongside volatility-based filtering, each market movement is evaluated through multiple historical lenses while accounting for current market conditions. This multi-layered approach helps differentiate between genuine trend movements and market noise across timeframe and asset classes.

Tips
  • Fine-tune the Zero Lag length based on your timeframe:
    → Lower values (20-40) for more responsive signals
    → Higher values (60-100) for stronger trend confirmation
  • Adjust volatility multiplier based on market conditions:
    → Increase multiplier in volatile markets
    → Decrease multiplier in stable trending markets
  • Combine with:
    → Volume analysis for trade validation
    → Multiple timeframe analysis for broader context
    → Other technical tools for comprehensive analysis
oArwddW.png

Original Tradingview code
https://www.tradingview.com/script/jbhEadsV-Zero-Lag-Signals-For-Loop-QuantAlgo/

For the new ThinkOrSwim code, you must scroll down to the next post
 
Last edited by a moderator:
  • I'm watching this!
Reactions: sum

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

check the below:

CSS:
#// Indicator for TOS
#// © QuantAlgo
#indicator(title="Zero Lag Signals For Loop [QuantAlgo]", overlay=true)
# Converted by Sam4Cok@Samer800    - 01/2025

input timeframe = AggregationPeriod.MIN;
input show_signals = yes; #(true, "Show Signal Markers",
input ColorCandles = yes; # "Color Candles",
input showCloud = yes;
input zeroLagMovAvg = AverageType.EXPONENTIAL;
input length = 50; #, "Zero Lag Length",
input volatility_mult = 1.5; # "Volatility Multiplier",
input loop_start = 1; #, "Loop Start",
input loop_end = 70; #, "Loop End",
input threshold_up = 5; #, "Threshold Uptrend",
input threshold_down = -5; #, "Threshold Downtrend",


def na = Double.NaN;
def last = isNaN(close);
def cap = GetAggregationPeriod();
def tf = Max(cap, timeframe);

Script forloop_analysis {
input basis_price = close;
input loop_start = 1;
input loop_end = 70;
    def sum = fold i = loop_start to loop_end with p do
              p + (if basis_price > basis_price[i] then 1 else -1);
    plot out = sum;
}
#// ZERO LAG CALCULATIONS
def nATR = ATR(Length = length);
def lag = Floor((length - 1) / 2);
def zl_basis = MovingAverage(zeroLagMovAvg, 2 * close(Period = tf) - close(Period = tf)[lag], length);
def volatility = Highest(nATR, length * 3) * volatility_mult;
#// FOR LOOP ANALYSIS
def score = forloop_analysis(zl_basis, loop_start, loop_end);
#// SIGNAL GENERATION
def long_signal = score > threshold_up and close > zl_basis + volatility;
def short_signal = score < threshold_down and close < zl_basis - volatility;
#// Trend detectio
def trend = if long_signal then 1 else if short_signal then -1 else trend[1];
#// Track trend changes
def prev_trend;
def trend_changed = trend != prev_trend[1];
prev_trend = trend;
#// VISUALIZATION
def mid = (Open + Close) / 2;
def trnd = if trend then trend else na;
#/ Plot Zero Lag line
plot p_basis = if !last and zl_basis then zl_basis else na; # "Zero Lag Basis"

p_basis.SetLineWeight(2);
p_basis.AssignValueColor(if trend == 1 then Color.CYAN else if trend == -1 then Color.DARK_ORANGE else Color.GRAY);

AddCloud(if !showCloud then na else if (trnd == 1 or trnd[-1] == 1) then p_basis else na, mid, Color.DARK_GREEN, Color.DARK_GREEN);
AddCloud(if !showCloud then na else if (trnd ==-1 or trnd[-1] ==-1) then p_basis else na, mid, Color.DARK_RED, Color.DARK_RED);

#// Plot trend shift labels
plot sigUp = if show_signals and trend_changed and trend == 1 then zl_basis else na; # "Bullish Trend"
plot sigDn = if show_signals and trend_changed and trend ==-1 then zl_basis else na; # "Bearish Trend"
sigUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
sigDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

sigUp.SetDefaultColor(Color.CYAN);
sigDn.SetDefaultColor(Color.DARK_ORANGE);
#-- Bar Color

AssignPriceColor(if !ColorCandles then Color.CURRENT else
                 if trend == 1 then if close > p_basis then Color.GREEN else Color.DARK_GREEN else
                 if trend ==-1 then if close < p_basis then Color.RED else Color.DARK_RED else Color.GRAY);

#-- END of CODE
 
  • Love
Reactions: IPA

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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