Detrended Ehlers Leading Indicator [CC] For ThinkOrSwim

mbarcala

Active member
The Detrended Ehlers Leading Indicator(DELI) was authored by Jon Ehlers. The DELI uses highs, previous high, lows, previous lows and feedback to create two exponential moving averages. First, Detrended Synthetic Price (DSP) is plotted as their difference. Then a third exponential moving average is created from the DSP and the DELI is plotted as their difference

af2JjYC.png


I would like to see if some here can convert this to TOS please?
Original link: https://www.tradingview.com/script/XPZfVBWs-Detrended-Ehlers-Leading-Indicator-CC/
 
Last edited by a moderator:

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

I would like to study this indicator a little, I try to convert to TOS but as I expected I get stock in couple of lines! I would like to see if some here can convert this to TOS please?

Original link: https://www.tradingview.com/script/XPZfVBWs-Detrended-Ehlers-Leading-Indicator-CC/

Code:
//@version=5
// Copyright (c) 2019-present, Franklin Moormann (cheatcountry)
// Detrended Ehlers Leading Indicator [CC] script may be freely distributed under the MIT license.
indicator('Detrended Ehlers Leading Indicator [CC]', max_bars_back=3000, overlay=false)

f_security(_symbol, _res, _src, _repaint) =>
    request.security(_symbol, _res, _src[_repaint ? 0 : barstate.isrealtime ? 1 : 0])[_repaint ? 0 : barstate.isrealtime ? 0 : 1]
  
res = input.timeframe(title="Resolution", defval='')
rep = input.bool(title="Allow Repainting?", defval=false)
bar = input.bool(title="Allow Bar Color Change?", defval=false)
h = f_security(syminfo.tickerid, res, high, rep)
l = f_security(syminfo.tickerid, res, low, rep)
length = input.int(title='Length', defval=14, minval=1)

alpha = length > 2 ? 2.0 / (length + 1) : 0.67
price = (math.max(h, nz(h[1])) + math.min(l, nz(l[1]))) / 2

ma1 = 0.0
ma1 := (alpha * price) + ((1 - alpha) * nz(ma1[1], price))

ma2 = 0.0
ma2 := ((alpha / 2) * price) + ((1 - (alpha / 2)) * nz(ma2[1], price))

dsp = ma1 - ma2

ma3 = 0.0
ma3 := (alpha * dsp) + ((1 - alpha) * nz(ma3[1]))

deli = dsp - ma3

slo = dsp - deli
sig = slo > 0 ? slo > nz(slo[1]) ? 2 : 1 : slo < 0 ? slo < nz(slo[1]) ? -2 : -1 : 0
alertcondition(ta.crossover(sig, 1), "Strong Buy Signal", "Strong Bullish Change Detected")
alertcondition(ta.crossunder(sig, -1), "Strong Sell Signal", "Strong Bearish Change Detected")
alertcondition(ta.crossover(sig, 0), "Buy Signal", "Bullish Change Detected")
alertcondition(ta.crossunder(sig, 0), "Sell Signal", "Bearish Change Detected")
deliColor = sig > 1 ? color.green : sig > 0 ? color.lime : sig < -1 ? color.maroon : sig < 0 ? color.red : color.black
barcolor(bar ? deliColor : na)
hline(0)
plot(dsp, title="DSP", linewidth=2, color=deliColor)
plot(deli, title="DELI", linewidth=1, color=color.white)
check the below

CSS:
# https://www.tradingview.com/v/XPZfVBWs/
#//@cheatcountry
#// Copyright (c) 2019-present, Franklin Moormann (cheatcountry)
#// Detrended Ehlers Leading Indicator [CC] script may be freely distributed under the MIT license.
#indicator('Detrended Ehlers Leading Indicator [CC]', max_bars_back=3000, overlay=false)
# Converted by Sam4Cok@Samer800    - 04/2024
Declare lower;
input length = 14; #(title='Length', defval=14, minval=1)
#input timeframe = {Default "Chart", "Manual"};
input useManualTimeframe = no;
input ManualTimeframe = AggregationPeriod.FIFTEEN_MIN; # title="Resolution",
input AllowRepainting = no; #(title="Allow Repainting?", defval=false)
input AllowBarColorChange = no; #(title="Allow Bar Color Change?", defval=false)

def na = Double.NaN;
def last = isNaN(close);
Script f_security {
input mtf = no;
input res = AggregationPeriod.FIFTEEN_MIN;
input src = FundamentalType.CLOSE;
input repaint = no;
    def isrealtime = !isNaN(close);
    def tf = GetAggregationPeriod();
    def rep = if isrealtime then 1 else 0;
    def RepVal = Fundamental(FundamentalType = src, Period = if mtf then res else tf);
    def Val = GetValue(RepVal, rep);
    plot out = if repaint then RepVal else if isrealtime then Val else Val[1];
}
def h = f_security(useManualTimeframe, ManualTimeframe, FundamentalType.HIGH, AllowRepainting);
def l = f_security(useManualTimeframe, ManualTimeframe, FundamentalType.LOW, AllowRepainting);

def alpha = if length > 2 then 2.0 / (length + 1) else 0.67;
def mmax = max(h, h[1]);
def mmin = min(l, l[1]);
def price = (mmax + mmin) / 2;

def ma1 = (alpha * price) + ((1 - alpha) * if(isNaN(ma1[1]) or !ma1[1], price, ma1[1]));
def ma2 = ((alpha / 2) * price) + ((1 - (alpha / 2)) *if(isNaN(ma2[1]) or !ma2[1], price, ma2[1]));
def dsp = ma1 - ma2;
def ma3 = (alpha * dsp) + ((1 - alpha) * if(isNaN(ma3[1]), 0 , ma3[1]));
def deli = dsp - ma3;

def slo = deli - deli[1];
def sig = if slo > 0 then if slo > slo[1] then  2 else 1 else
          if slo < 0 then if slo < slo[1] then -2 else -1 else 0;

plot DELIline = if last then na else deli;   # "DELI"
plot DSPline = if last then na else dsp;     # "DSP"
plot ZEROline = if last then na else 0;
ZEROline.SetStyle(Curve.SHORT_DASH);
ZEROline.SetDefaultColor(Color.GRAY);
DSPline.SetDefaultColor(Color.WHITE);
DELIline.SetLineWeight(2);
DELIline.AssignValueColor(if sig > 1 then Color.DARK_GREEN else
                          if sig > 0 then color.GREEN else
                          if sig < -1 then Color.DARK_RED else
                          if sig < 0 then color.RED else color.GRAY);

AssignPriceColor(if !AllowBarColorChange then Color.CURRENT else
                 if sig > 1 then Color.DARK_GREEN else
                 if sig > 0 then color.GREEN else
                 if sig < -1 then Color.DARK_RED else
                 if sig < 0 then color.RED else color.GRAY);

plot buy = if DELIline > 0 and sig crosses Above 0 then DELIline else na;
plot sell = if DELIline < 0 and sig crosses below 0 then DELIline else na;
buy.SetLineWeight(5);
sell.SetlineWeight(5);
buy.SetPaintingStrategy(PaintingStrategy.SQUARES);
sell.SetPaintingStrategy(PaintingStrategy.SQUARES);
buy.SetDefaultColor(Color.CYAN);
sell.SetDefaultColor(Color.MAGENTA);

#-- END of CODE
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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