Repaints Zero Lag Trend Signals (MTF) [AlgoAlpha] For ThinkOrSwim

Repaints

chewie76

Well-known member
VIP
VIP Enthusiast
Author states: this study blends zero-lag EMA (ZLEMA) logic with volatility bands, trend-shift markers, and dynamic alerts. The result? Timely signals with minimal noise for clearer decision-making, whether you're trading intraday or on longer horizons.
  • Zero-Lag Trend Detection: Uses a zero-lag EMA (ZLEMA) to smooth price data while minimizing delay.
  • Multi-Timeframe Signals: Displays trends across up to 5 timeframes (from 5 minutes to daily) on a sleek table.
  • Volatility-Based Bands: Adaptive upper and lower bands, helping you identify trend reversals with reduced false signals.

bSBZFK0.png


original Tradingview script:
https://www.tradingview.com/script/tHK4O1Fi-Zero-Lag-Trend-Signals-MTF-AlgoAlpha/
new ThinkOrSwim code found in the next post
 
Last edited by a moderator:

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

I'd like to request a conversion of the open source indicator Zero Lag Trend Signals found at the below link. Thanks,

https://www.tradingview.com/script/tHK4O1Fi-Zero-Lag-Trend-Signals-MTF-AlgoAlpha/
check the below:

CSS:
#// Indicator for TOS
#// © AlgoAlpha
#indicator("Zero Lag Trend Signals (MTF) [AlgoAlpha]", shorttitle="AlgoAlpha - 0️⃣Zero Lag Signals", overlay=true)
#Hint length: "The Look-Back window for the Zero-Lag EMA calculations"
#Hint BandMultiplier: "This value controls the thickness of the bands, a larger value makes the indicato less noisy"
# Converted by Sam4Cok@Samer800    - 11/2024

input showDashboard = yes;
input movAvgType = AverageType.EXPONENTIAL;
input length = 70; # "Length",
input BandMultiplier = 1.2; #, "Band Multiplier",
input timeframe1 = AggregationPeriod.FIVE_MIN;     # "Time frame 1"
input timeframe2 = AggregationPeriod.FIFTEEN_MIN;  # "Time frame 2"
input timeframe3 = AggregationPeriod.HOUR;         # "Time frame 3"
input timeframe4 = AggregationPeriod.FOUR_HOURS;   # "Time frame 4"
input timeframe5 = AggregationPeriod.DAY;          # "Time frame 5"


def na = Double.NaN;
def last = IsNaN(close);
def oc2 = (open + close) / 2;
def current = GetAggregationPeriod();
def t1 = Max(current, timeframe1);
def t2 = Max(current, timeframe2);
def t3 = Max(current, timeframe3);
def t4 = Max(current, timeframe4);
def t5 = Max(current, timeframe5);

def atr = Atr(Length = length);
def lag = floor((length - 1) / 2);
def diff = (2 * close) - close[lag];
def zlema = MovingAverage(movAvgType, diff, length);
def volatility = highest(atr, length*3) * BandMultiplier;
def bandUp = zlema + volatility;
def bandDn = zlema - volatility;
def crossover  = (close > bandUp) and (close[1] <= bandUp[1]);
def crossunder = (close < bandDn) and (close[1] >= bandDn[1]);
def trend = if crossover then 1 else
            if crossunder then -1 else trend[1];
def trendCrossUp = (close > zlema) and (close[1] <= zlema) and trend == 1 and trend[1] == 1 ;
def trendCrossDn = (close < zlema) and (close[1] >= zlema) and trend == -1 and trend[1] == -1;
def crossUp = (trend > 0) and (trend[1] <= 0);
def crossDn = (trend < 0) and (trend[1] >= 0);

#-- PLots
plot ptUp = if crossUp then bandDn else na;
plot ptDn = if crossDn then bandUp else na;
plot BearishEntry = if trendCrossDn then high else na;
plot BullishEntry = if trendCrossUp then low else na;
plot basis = if zlema then zlema else na; #, title="Zero Lag Basis"
plot upper = if (trend < 0) then bandUp else na; # "Upper Deviation Band"
plot lower = if (trend > 0) then bandDn else na; # "Lower Deviation Band"

ptUp.SetDefaultColor(Color.GREEN);
ptDn.SetDefaultColor(Color.RED);
ptUp.SetStyle(Curve.POINTS);
ptDn.SetStyle(Curve.POINTS);
BearishEntry.SetDefaultColor(Color.MAGENTA);
BullishEntry.SetDefaultColor(Color.CYAN);
BearishEntry.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
BullishEntry.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

basis.SetLineWeight(2);
basis.AssignValueColor(if trend>0 then Color.GREEN else Color.RED);
upper.SetDefaultColor(Color.DARK_RED);
lower.SetDefaultColor(Color.DARK_GREEN);

#-- Label
AddChartBubble(crossUp, bandDn, "UP", Color.GREEN, no);
AddChartBubble(crossDn, bandUp, "DN", Color.RED);
#-- Cloud
AddCloud(Min(basis, oc2), lower, Color.DARK_GREEN, Color.DARK_GREEN);
AddCloud(upper, Max(basis, oc2), Color.DARK_RED, Color.DARK_RED);

#--
Script trend {
input movAvgType = AverageType.EXPONENTIAL;
input tf = 300000;
input length = 70;
input mult = 1.2;
    def closeTf = close(Period = tf);
    def tr = TrueRange(high(Period = tf), closeTf, low(Period = tf));
    def atr = WildersAverage(tr, length);
    def lag = floor((length - 1) / 2);
    def diff = 2 * closeTf - close(Period = tf)[lag];
    def zlema = MovingAverage(movAvgType, diff, length);
    def volatility = highest(atr, length * 3) * mult;
    def bandUp = zlema + volatility;
    def bandDn = zlema - volatility;
    def crossover  = (closeTf > bandUp) and (close(Period = tf)[1] <= bandUp[1]);
    def crossunder = (closeTf < bandDn) and (close(Period = tf)[1] >= bandDn[1]);
    def trend = if crossover then 1 else
                if crossunder then -1 else trend[1];
    plot out = trend;
}
def s1 = trend(movAvgType, t1, length, BandMultiplier);
def s2 = trend(movAvgType, t2, length, BandMultiplier);
def s3 = trend(movAvgType, t3, length, BandMultiplier);
def s4 = trend(movAvgType, t4, length, BandMultiplier);
def s5 = trend(movAvgType, t5, length, BandMultiplier);

def s1a = if last[-1] then s1 else s1a[1];
def s2a = if last[-1] then s2 else s2a[1];
def s3a = if last[-1] then s3 else s3a[1];
def s4a = if last[-1] then s4 else s4a[1];
def s5a = if last[-1] then s5 else s5a[1];

AddLabel(showDashboard, "(" + t1 / 60000 + " Min, " + (if s1a > 0 then "Bullish" else "Bearish") +")",
               if s1a>0 then Color.GREEN else Color.RED);
AddLabel(showDashboard, "(" + t2 / 60000 + " Min, " + (if s2a > 0 then "Bullish" else "Bearish") +")",
               if s2a>0 then Color.GREEN else Color.RED);
AddLabel(showDashboard, "(" + t3 / 60000 + " Min, " + (if s3a > 0 then "Bullish" else "Bearish") +")",
               if s3a>0 then Color.GREEN else Color.RED);
AddLabel(showDashboard, "(" + t4 / 60000 + " Min, " + (if s4a > 0 then "Bullish" else "Bearish") +")",
               if s4a>0 then Color.GREEN else Color.RED);
AddLabel(showDashboard, "(" + t5 / 60000 + " Min, " + (if s5a > 0 then "Bullish" else "Bearish") +")",
               if s5a>0 then Color.GREEN else Color.RED);

#-- END of CODE
 
I like what I'm seeing so far with this. I added some target levels on both sides of this. Band Multiplier levels are adjustable in the settings.

1731531156418.png

Code:
#// Indicator for TOS
#// © AlgoAlpha
#indicator("Zero Lag Trend Signals (MTF) [AlgoAlpha]", shorttitle="AlgoAlpha - 0️⃣Zero Lag Signals", overlay=true)
#Hint length: "The Look-Back window for the Zero-Lag EMA calculations"
#Hint BandMultiplier: "This value controls the thickness of the bands, a larger value makes the indicato less noisy"
# Converted by Sam4Cok@Samer800    - 11/2024

input showDashboard = no;
input bands = yes;
input movAvgType = AverageType.EXPONENTIAL;
input length = 70; # "Length",
input BandMultiplier = 1.0; # 1.2, "Band Multiplier",
input BandMultiplier2 = 2.0;
input BandMultiplier3 = 3.0;
input timeframe1 = AggregationPeriod.FIVE_MIN;     # "Time frame 1"
input timeframe2 = AggregationPeriod.FIFTEEN_MIN;  # "Time frame 2"
input timeframe3 = AggregationPeriod.HOUR;         # "Time frame 3"
input timeframe4 = AggregationPeriod.FOUR_HOURS;   # "Time frame 4"
input timeframe5 = AggregationPeriod.DAY;          # "Time frame 5"


def na = Double.NaN;
def last = IsNaN(close);
def oc2 = (open + close) / 2;
def current = GetAggregationPeriod();
def t1 = Max(current, timeframe1);
def t2 = Max(current, timeframe2);
def t3 = Max(current, timeframe3);
def t4 = Max(current, timeframe4);
def t5 = Max(current, timeframe5);

def atr = ATR(Length = length);
def lag = Floor((length - 1) / 2);
def diff = (2 * close) - close[lag];
def zlema = MovingAverage(movAvgType, diff, length);
def volatility = Highest(atr, length * 3) * BandMultiplier;
def bandUp = zlema + volatility;
def bandDn = zlema - volatility;
def crossover  = (close > bandUp) and (close[1] <= bandUp[1]);
def crossunder = (close < bandDn) and (close[1] >= bandDn[1]);
def trend = if crossover then 1 else
            if crossunder then -1 else trend[1];
def trendCrossUp = (close > zlema) and (close[1] <= zlema) and trend == 1 and trend[1] == 1 ;
def trendCrossDn = (close < zlema) and (close[1] >= zlema) and trend == -1 and trend[1] == -1;
def crossUp = (trend > 0) and (trend[1] <= 0);
def crossDn = (trend < 0) and (trend[1] >= 0);

def volatility2 = Highest(atr, length * 3) * BandMultiplier2;
def volatility3 = Highest(atr, length * 3) * BandMultiplier3;

#-- PLots
plot ptUp = if crossUp then bandDn else na;
plot ptDn = if crossDn then bandUp else na;
plot BearishEntry = if trendCrossDn then high else na;
plot BullishEntry = if trendCrossUp then low else na;
plot basis = if zlema then zlema else na; #, title="Zero Lag Basis"
plot upper = if (trend < 0) then bandUp else na; # "Upper Deviation Band"
plot lower = if (trend > 0) then bandDn else na; # "Lower Deviation Band"

#Band1
plot u = if bands then bandUp else double.nan;
plot d = if bands then bandDn else double.nan;

#Band2
plot bandUp2 = if bands then zlema + volatility2 else double.nan;
plot bandDn2 = if bands then zlema - volatility2 else double.nan;

#Band3
plot bandUp3 = if bands then zlema + volatility3 else double.nan;
plot bandDn3 = if bands then zlema - volatility3 else double.nan;


ptUp.SetDefaultColor(Color.CYAN);
ptDn.SetDefaultColor(Color.MAGENTA);
ptUp.SetStyle(Curve.POINTS);
ptDn.SetStyle(Curve.POINTS);
BearishEntry.SetDefaultColor(Color.MAGENTA);
BullishEntry.SetDefaultColor(Color.CYAN);
BearishEntry.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
BullishEntry.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

basis.SetLineWeight(3);
basis.AssignValueColor(if trend > 0 then Color.GREEN else Color.RED);
upper.SetDefaultColor(Color.MAGENTA);
lower.SetDefaultColor(Color.CYAN);
upper.SetLineWeight(2);
lower.SetLineWeight(2);

u.setDefaultColor(color.light_gray);
d.setdefaultColor(color.light_gray);
bandUp2.setDefaultColor(color.dark_orange);
banddn2.setdefaultColor(color.light_green);
bandup3.SetDefaultColor(Color.red);
banddn3.SetDefaultColor(Color.green);

#-- Label
#AddChartBubble(crossUp, bandDn, "UP", Color.GREEN, no);
#AddChartBubble(crossDn, bandUp, "DN", Color.RED);
#-- Cloud
AddCloud(Min(basis, oc2),   lower,   Color.DARK_GREEN,   Color.DARK_GREEN);
AddCloud(upper, Max(basis, oc2), Color.DARK_RED, Color.DARK_RED);

#--
script trend {
    input movAvgType = AverageType.EXPONENTIAL;
    input tf = 300000;
    input length = 70;
    input mult = 1.2;
    def closeTf = close(Period = tf);
    def tr = TrueRange(high(Period = tf), closeTf, low(Period = tf));
    def atr = WildersAverage(tr, length);
    def lag = Floor((length - 1) / 2);
    def diff = 2 * closeTf - close(Period = tf)[lag];
    def zlema = MovingAverage(movAvgType, diff, length);
    def volatility = Highest(atr, length * 3) * mult;
    def bandUp = zlema + volatility;
    def bandDn = zlema - volatility;
    def crossover  = (closeTf > bandUp) and (close(Period = tf)[1] <= bandUp[1]);
    def crossunder = (closeTf < bandDn) and (close(Period = tf)[1] >= bandDn[1]);
    def trend = if crossover then 1 else
                if crossunder then -1 else trend[1];
    plot out = trend;
}
def s1 = trend(movAvgType, t1, length, BandMultiplier);
def s2 = trend(movAvgType, t2, length, BandMultiplier);
def s3 = trend(movAvgType, t3, length, BandMultiplier);
def s4 = trend(movAvgType, t4, length, BandMultiplier);
def s5 = trend(movAvgType, t5, length, BandMultiplier);

def s1a = if last[-1] then s1 else s1a[1];
def s2a = if last[-1] then s2 else s2a[1];
def s3a = if last[-1] then s3 else s3a[1];
def s4a = if last[-1] then s4 else s4a[1];
def s5a = if last[-1] then s5 else s5a[1];

AddLabel(showDashboard, "(" + t1 / 60000 + " Min, " + (if s1a > 0 then "Bullish" else "Bearish") + ")",
               if s1a > 0 then Color.GREEN else Color.RED);
AddLabel(showDashboard, "(" + t2 / 60000 + " Min, " + (if s2a > 0 then "Bullish" else "Bearish") + ")",
               if s2a > 0 then Color.GREEN else Color.RED);
AddLabel(showDashboard, "(" + t3 / 60000 + " Min, " + (if s3a > 0 then "Bullish" else "Bearish") + ")",
               if s3a > 0 then Color.GREEN else Color.RED);
AddLabel(showDashboard, "(" + t4 / 60000 + " Min, " + (if s4a > 0 then "Bullish" else "Bearish") + ")",
               if s4a > 0 then Color.GREEN else Color.RED);
AddLabel(showDashboard, "(" + t5 / 60000 + " Min, " + (if s5a > 0 then "Bullish" else "Bearish") + ")",
               if s5a > 0 then Color.GREEN else Color.RED);

#-- END of CODE
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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