Trendilo (Open-Source) for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
Ckgpd7Q.png

Author Message:

The provided code is a custom indicator called "Trendilo" in TradingView. It helps traders identify trends in price data. The indicator calculates the percentage change of the chosen price source and applies smoothing to it. Then, it calculates the Arnaud Legoux Moving Average (ALMA) of the smoothed percentage change. The ALMA is compared to a root mean square (RMS) band, which represents the expected range of the ALMA values. Based on this comparison, the indicator determines whether the trend is up, down, or sideways. The indicator line is plotted in a color corresponding to the trend direction. The indicator also provides the option to fill the area between the indicator line and the RMS band. Additionally, users can choose to color the bars of the chart based on the trend direction. Overall, the "Trendilo" indicator helps traders visually identify trends and potential reversals in the price data.

CODE:
CSS:
#https://www.tradingview.com/v/h5kMWewu/
#//@version=5
#indicator('Trendilo', overlay=false)
# Converted by Sam4Cok@Samer800    - 07/2023
declare lower;

input src = close;                  # 'Source'
input Smoothing = 1;                # 'Smoothing'
input Lookback = 50;                # 'Lookback'
input almaOffset = 0.85;            # 'ALMA Offset'
input almaSigma = 6;                # 'ALMA Sigma'
input BandMultiplier = 1.0;         # 'Band Multiplier'
input useCustomBandLength = no;     # 'Custom Band Length ? (Else same as Lookback)')
input CustomBandLength = 20;        # 'Custom Band Length'
input highlightTrendLine = yes;
input showCloud = yes;
input barColor = yes;               # 'Bar Color'

def na = Double.NaN;
def last = isNaN(close);
#pine_alma(series, windowsize, offset, sigma) =>
script ALMA {
    input series = close;
    input windowsize = 9;
    input Offset = 0.85;
    input Sigma = 6;
    def m = Offset * (windowsize - 1);
    def s = windowsize / Sigma;
    def norm  = fold z = 0 to windowsize with CW do
         CW + Exp(-(Sqr(z - m)) / (2 * Sqr(s)));
    def sum  = fold y = 0 to windowsize with WS do
         WS + Exp(-(Sqr(y - m)) / (2 * Sqr(s))) * GetValue(series, windowsize - 1 - y);
    plot ALMA = sum  / norm ;
}
def change = src - src[Smoothing];
def pch = change / src * 100;
def avpch = alma(pch, Lookback, almaOffset, almaSigma);
def blength = if useCustomBandLength then CustomBandLength else Lookback;
def rms = BandMultiplier * Sqrt(Sum(avpch * avpch, blength) / blength);
def cdir = if avpch > rms then 1 else if avpch < -rms then -1 else 0;

#-- plot
plot fplot = avpch;
plot posrms = rms;
plot negrms = -rms;

fplot.SetLineWeight(2);
fplot.AssignValueColor(if !highlightTrendLine then Color.CYAN else
                       if cdir>0 then Color.GREEN else
                       if cdir<0 then Color.RED else Color.GRAY);
posrms.SetDefaultColor(Color.MAGENTA);
negrms.SetDefaultColor(Color.MAGENTA);

AddCloud(if showCloud and cdir > 0 then fplot else na, posrms, Color.DARK_GREEN);
AddCloud(if showCloud and cdir < 0 then fplot else na, negrms, Color.DARK_RED);

AssignPriceColor(if !barColor then Color.CURRENT else
                       if cdir>0 then Color.GREEN else
                       if cdir<0 then Color.RED else Color.GRAY);
plot zero = if last then na else 0;
zero.SetDefaultColor(Color.DARK_GRAY);
zero.SetStyle(Curve.SHORT_DASH);
#-- END OF CODE
 
I'm having the same problem with the scan set up for just a simple "fplot" crossing the "negrms" on the weekly. To complicated algo?
 
Plot crosses posrms/negrms doesn't yield any results on TOS scanner. Any help?
I've been trying to set this up as a scan, just a simple "fplot" crossing "posrms" but doesn't appear to work. Can I even set this up as a scan?
I'm having the same problem with the scan set up for just a simple "fplot" crossing the "negrms" on the weekly. To complicated algo?

scan would be difficult with ALMA moving average but with Hull Mov Avg can work. It wont be same but close.

try this . Change the CrossUp and CrossDn.

CSS:
#https://www.tradingview.com/v/h5kMWewu/
#//@version=5
# Scan indicator('Trendilo', overlay=false)
# Converted by Sam4Cok@Samer800    - 07/2023
declare lower;
input src = close;                  # 'Source'
input Smoothing = 1;                # 'Smoothing'
input Lookback = 50;                # 'Lookback'
input BandMultiplier = 1.0;         # 'Band Multiplier'

def change = src - src[Smoothing];
def pch = change / src * 100;

def avpch = HullMovingAvg(pch, Lookback);
def blength = Lookback;
def avMulti = avpch * avpch;
def sumv = Sum(avMulti, blength);
def sumDiv = sumv / blength;
def sqrVal = Sqrt(sumDiv);
def rms = BandMultiplier * sqrVal;
#-- plot
def fplot = avpch;
def posrms = rms;
def negrms = -rms;

def CrossUp = avpch Crosses Above posrms;
def CrossDn = avpch Crosses Below negrms;

plot scanT = CrossUp within 2 bars;


#-- END OF CODE
 
Last edited by a moderator:
Thank you Samer800. I just adjusted the CrossUp to the negrams and # out the CrossDn, set the aggregation period to weekly and it works perfectly. Awesome!
 
This looks really nice is there a way to keep top of chart separate from lower
what I am trying to say is not have the candles turning grey.
Thank you
 
Great indicator. Is there a way to change the cloud colors and indicator line colors to red at the overbought area and to green at the oversold area?
Thank you for sharing.
 
This works great for catching the C leg of the A + C symmetry on the higher time frames, using the 5 min, could you add the MTF preference for testing?
 
Last edited by a moderator:
I added some oversold/overbought levels. Also changed some inputs. http://tos.mx/TjQKgMI

1691701653770.png

Ruby:
#https://www.tradingview.com/v/h5kMWewu/
#//@version=5
#indicator('Trendilo', overlay=false)
# Converted by Sam4Cok@Samer800    - 07/2023
declare lower;

input src = close;                  # 'Source'
input Smoothing = 1;                # 'Smoothing'
input Lookback = 30;  #40 mid 50              # 'Lookback'
input almaOffset = 0.85;            # 'ALMA Offset'
input almaSigma = 6;                # 'ALMA Sigma'
input BandMultiplier = 1.0;         # 'Band Multiplier'
input useCustomBandLength = no;     # 'Custom Band Length ? (Else same as Lookback)')
input CustomBandLength = 14;  # 20      # 'Custom Band Length'
input highlightTrendLine = yes;
input showCloud = yes;
input barColor = no;               # 'Bar Color'

def na = Double.NaN;
def last = isNaN(close);
#pine_alma(series, windowsize, offset, sigma) =>
script ALMA {
    input series = close;
    input windowsize = 9;
    input Offset = 0.85;
    input Sigma = 6;
    def m = Offset * (windowsize - 1);
    def s = windowsize / Sigma;
    def norm  = fold z = 0 to windowsize with CW do
         CW + Exp(-(Sqr(z - m)) / (2 * Sqr(s)));
    def sum  = fold y = 0 to windowsize with WS do
         WS + Exp(-(Sqr(y - m)) / (2 * Sqr(s))) * GetValue(series, windowsize - 1 - y);
    plot ALMA = sum  / norm ;
}
def change = src - src[Smoothing];
def pch = change / src * 100;
def avpch = alma(pch, Lookback, almaOffset, almaSigma);
def blength = if useCustomBandLength then CustomBandLength else Lookback;
def rms = BandMultiplier * Sqrt(Sum(avpch * avpch, blength) / blength);
def cdir = if avpch > rms then 1 else if avpch < -rms then -1 else 0;

#-- plot
plot fplot = avpch;
plot posrms = rms;
plot negrms = -rms;

fplot.SetLineWeight(2);
fplot.AssignValueColor(if !highlightTrendLine then Color.CYAN else
                       if cdir>0 then Color.red else
                       if cdir<0 then Color.green else Color.light_GRAY);
posrms.SetDefaultColor(Color.MAGENTA);
negrms.SetDefaultColor(Color.MAGENTA);

#AddCloud(if showCloud and cdir < 0 then fplot else na, negrms, Color.dark_green);
AddCloud(if showCloud and cdir > 0 then fplot else na, posrms, Color.red);
AddCloud(negrms, fplot, Color.GREEN, Color.CURRENT);

#AssignPriceColor(if !barColor then Color.CURRENT else
#                       if cdir>0 then Color.GREEN else
#                       if cdir<0 then Color.RED else Color.GRAY);
plot zero = if last then na else 0;
zero.SetDefaultColor(Color.yellow);
#zero.SetStyle(Curve.SHORT_DASH);
#-- END OF CODE
# 2 Standard Deviation Full

input deviations = 2.0;
input deviations2 = 2.5;
input fullRange = Yes;
input length = 21;

def regression;
def stdDeviation;
if (fullRange) {
    regression = InertiaAll(fplot);
    stdDeviation = StDevAll(fplot);
} else {
    regression = InertiaAll(fplot, length);
    stdDeviation = StDevAll(fplot, length);
}

plot UpperLine = regression + deviations * stdDeviation;
#plot MiddleLine = regression;
plot LowerLine = regression - deviations * stdDeviation;

UpperLine.SetDefaultColor(Color.RED);
LowerLine.SetDefaultColor(Color.GREEN);
UpperLine.SetLineWeight(1);
LowerLine.SetLineWeight(1);
Upperline.HideBubble();
Upperline.Hidetitle();
Lowerline.HideBubble();
Lowerline.Hidetitle();


plot UpperLine2 = regression + deviations2 * stdDeviation;
plot LowerLine2 = regression - deviations2 * stdDeviation;

UpperLine2.SetDefaultColor(Color.RED);
LowerLine2.SetDefaultColor(Color.GREEN);
UpperLine2.SetLineWeight(1);
LowerLine2.SetLineWeight(1);
UpperLine2.HideBubble();
UpperLine2.Hidetitle();
LowerLine2.HideBubble();
LowerLine2.Hidetitle();

AddCloud(UpperLine2, UpperLine, Color.RED, Color.CURRENT);
AddCloud(LowerLine, LowerLine2, color.green, Color.CURRENT);
 
Last edited by a moderator:
Last edited:
Ckgpd7Q.png

Author Message:

The provided code is a custom indicator called "Trendilo" in TradingView. It helps traders identify trends in price data. The indicator calculates the percentage change of the chosen price source and applies smoothing to it. Then, it calculates the Arnaud Legoux Moving Average (ALMA) of the smoothed percentage change. The ALMA is compared to a root mean square (RMS) band, which represents the expected range of the ALMA values. Based on this comparison, the indicator determines whether the trend is up, down, or sideways. The indicator line is plotted in a color corresponding to the trend direction. The indicator also provides the option to fill the area between the indicator line and the RMS band. Additionally, users can choose to color the bars of the chart based on the trend direction. Overall, the "Trendilo" indicator helps traders visually identify trends and potential reversals in the price data.

CODE:
CSS:
#https://www.tradingview.com/v/h5kMWewu/
#//@version=5
#indicator('Trendilo', overlay=false)
# Converted by Sam4Cok@Samer800    - 07/2023
declare lower;

input src = close;                  # 'Source'
input Smoothing = 1;                # 'Smoothing'
input Lookback = 50;                # 'Lookback'
input almaOffset = 0.85;            # 'ALMA Offset'
input almaSigma = 6;                # 'ALMA Sigma'
input BandMultiplier = 1.0;         # 'Band Multiplier'
input useCustomBandLength = no;     # 'Custom Band Length ? (Else same as Lookback)')
input CustomBandLength = 20;        # 'Custom Band Length'
input highlightTrendLine = yes;
input showCloud = yes;
input barColor = yes;               # 'Bar Color'

def na = Double.NaN;
def last = isNaN(close);
#pine_alma(series, windowsize, offset, sigma) =>
script ALMA {
    input series = close;
    input windowsize = 9;
    input Offset = 0.85;
    input Sigma = 6;
    def m = Offset * (windowsize - 1);
    def s = windowsize / Sigma;
    def norm  = fold z = 0 to windowsize with CW do
         CW + Exp(-(Sqr(z - m)) / (2 * Sqr(s)));
    def sum  = fold y = 0 to windowsize with WS do
         WS + Exp(-(Sqr(y - m)) / (2 * Sqr(s))) * GetValue(series, windowsize - 1 - y);
    plot ALMA = sum  / norm ;
}
def change = src - src[Smoothing];
def pch = change / src * 100;
def avpch = alma(pch, Lookback, almaOffset, almaSigma);
def blength = if useCustomBandLength then CustomBandLength else Lookback;
def rms = BandMultiplier * Sqrt(Sum(avpch * avpch, blength) / blength);
def cdir = if avpch > rms then 1 else if avpch < -rms then -1 else 0;

#-- plot
plot fplot = avpch;
plot posrms = rms;
plot negrms = -rms;

fplot.SetLineWeight(2);
fplot.AssignValueColor(if !highlightTrendLine then Color.CYAN else
                       if cdir>0 then Color.GREEN else
                       if cdir<0 then Color.RED else Color.GRAY);
posrms.SetDefaultColor(Color.MAGENTA);
negrms.SetDefaultColor(Color.MAGENTA);

AddCloud(if showCloud and cdir > 0 then fplot else na, posrms, Color.DARK_GREEN);
AddCloud(if showCloud and cdir < 0 then fplot else na, negrms, Color.DARK_RED);

AssignPriceColor(if !barColor then Color.CURRENT else
                       if cdir>0 then Color.GREEN else
                       if cdir<0 then Color.RED else Color.GRAY);
plot zero = if last then na else 0;
zero.SetDefaultColor(Color.DARK_GRAY);
zero.SetStyle(Curve.SHORT_DASH);
#-- END OF CODE
@samer800 Could you please add MTF to this script, I tried a few times to do it myself and couldn't could you kindly add this thanks
 
I tried to convert this to MTF, Not able to get it right. Please advise.
 
Last edited by a moderator:
I tried to convert this to MTF, Not able to get it right. Please advise.

#https://www.tradingview.com/v/h5kMWewu/
#//@version=5
#indicator('Trendilo', overlay=false)
# Converted by Sam4Cok@Samer800 - 07/2023
declare lower;

input src = close; # 'Source'
input Smoothing = 1; # 'Smoothing'
input Lookback = 50; # 'Lookback'
input almaOffset = 0.85; # 'ALMA Offset'
input almaSigma = 6; # 'ALMA Sigma'
input BandMultiplier = 1.0; # 'Band Multiplier'
input useCustomBandLength = no; # 'Custom Band Length ? (Else same as Lookback)')
input CustomBandLength = 20; # 'Custom Band Length'
input highlightTrendLine = yes;
input showCloud = yes;
input barColor = yes; # 'Bar Color'
input UseChartTime = yes; # "Use Chart timeframe or Aggregation?"
input aggregation = AggregationPeriod.DAY;


def na = Double.NaN;
def last = isNaN(close(period = aggregation);
#pine_alma(series, windowsize, offset, sigma) =>
script ALMA {
input series = close;
input windowsize = 9;
input Offset = 0.85;
input Sigma = 6;
def m = Offset * (windowsize - 1);
def s = windowsize / Sigma;
def norm = fold z = 0 to windowsize with CW do
CW + Exp(-(Sqr(z - m)) / (2 * Sqr(s)));
def sum = fold y = 0 to windowsize with WS do
WS + Exp(-(Sqr(y - m)) / (2 * Sqr(s))) * GetValue(series, windowsize - 1 - y);
plot ALMA = sum / norm ;
}
def change = src - src[Smoothing];
def pch = change / src * 100;
def avpch = alma(pch, Lookback, almaOffset, almaSigma);
def blength = if useCustomBandLength then CustomBandLength else Lookback;
def rms = BandMultiplier * Sqrt(Sum(avpch * avpch, blength) / blength);
def cdir = if avpch > rms then 1 else if avpch < -rms then -1 else 0;

#-- plot
plot fplot = avpch;
plot posrms = rms;
plot negrms = -rms;

fplot.SetLineWeight(2);
fplot.AssignValueColor(if !highlightTrendLine then Color.CYAN else
if cdir>0 then Color.GREEN else
if cdir<0 then Color.RED else Color.GRAY);
posrms.SetDefaultColor(Color.MAGENTA);
negrms.SetDefaultColor(Color.MAGENTA);

AddCloud(if showCloud and cdir > 0 then fplot else na, posrms, Color.DARK_GREEN);
AddCloud(if showCloud and cdir < 0 then fplot else na, negrms, Color.DARK_RED);

AssignPriceColor(if !barColor then Color.CURRENT else
if cdir>0 then Color.GREEN else
if cdir<0 then Color.RED else Color.GRAY);
plot zero = if last then na else 0;
zero.SetDefaultColor(Color.DARK_GRAY);
zero.SetStyle(Curve.SHORT_DASH);
#-- END OF CODE
check the below

CSS:
#https://www.tradingview.com/v/h5kMWewu/
#indicator('Trendilo', overlay=false)
# Converted by Sam4Cok@Samer800    - 07/2023
# Update - MTF option added - Sam4Cok@Samer800    - 09 / 2023
declare lower;
input useChartTimeframe =  {default"Yes", "No"};
input manualTimeframe   = AggregationPeriod.FIFTEEN_MIN;
input Smoothing = 1;                # 'Smoothing'
input Lookback = 50;                # 'Lookback'
input almaOffset = 0.85;            # 'ALMA Offset'
input almaSigma = 6;                # 'ALMA Sigma'
input BandMultiplier = 1.0;         # 'Band Multiplier'
input useCustomBandLength = no;     # 'Custom Band Length ? (Else same as Lookback)')
input CustomBandLength = 20;        # 'Custom Band Length'
input highlightTrendLine = yes;
input showCloud = yes;
input barColor = yes;               # 'Bar Color'

def na = Double.NaN;
def last = isNaN(close);
def res = manualTimeframe;

def MTclose = Close(Period = res);

#-- MTF
def c;
Switch (useChartTimeframe) {
case "Yes" :
    c = close;
case "No"  :
    c = MTclose;
}
def src = c;

#pine_alma(series, windowsize, offset, sigma) =>
script ALMA {
    input series = close;
    input windowsize = 9;
    input Offset = 0.85;
    input Sigma = 6;
    def m = Offset * (windowsize - 1);
    def s = windowsize / Sigma;
    def norm  = fold z = 0 to windowsize with CW do
         CW + Exp(-(Sqr(z - m)) / (2 * Sqr(s)));
    def sum  = fold y = 0 to windowsize with WS do
         WS + Exp(-(Sqr(y - m)) / (2 * Sqr(s))) * GetValue(series, windowsize - 1 - y);
    plot ALMA = sum  / norm ;
}
def change = src - src[Smoothing];
def pch = change / src * 100;
def avpch_ = alma(pch, Lookback, almaOffset, almaSigma);
def avpch = avpch_;
def blength = if useCustomBandLength then CustomBandLength else Lookback;
def sumVal = Sum(avpch * avpch, blength);
def rms = BandMultiplier * Sqrt(sumVal / blength);
def cdir = if avpch > rms then 1 else if avpch < -rms then -1 else 0;

#-- plot
plot fplot = avpch;
plot posrms = rms;
plot negrms = -rms;

fplot.SetLineWeight(2);
fplot.AssignValueColor(if !highlightTrendLine then Color.CYAN else
                       if cdir>0 then Color.GREEN else
                       if cdir<0 then Color.RED else Color.GRAY);
posrms.SetDefaultColor(Color.MAGENTA);
negrms.SetDefaultColor(Color.MAGENTA);

AddCloud(if showCloud and cdir > 0 then fplot else na, posrms, Color.DARK_GREEN);
AddCloud(if showCloud and cdir < 0 then fplot else na, negrms, Color.DARK_RED);

AssignPriceColor(if !barColor then Color.CURRENT else
                       if cdir>0 then Color.GREEN else
                       if cdir<0 then Color.RED else Color.GRAY);
plot zero = if last then na else 0;
zero.SetDefaultColor(Color.DARK_GRAY);
zero.SetStyle(Curve.SHORT_DASH);
#-- END OF CODE
 
Can someone add a buy and sell signals when the FPLOT line turns from white to red and from white to green.
If color changes to green when below zero line = Reg Buy
If color changes to green when above zero line = Extreme Buy
If color changes to red when below zero line = Extreme Buy
If color changes to red when above zero line = Reg Buy
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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