Kendall Rank Correlation For ThinkOrSwim

compupix

New member
Kendall Rank Correlation NET on SMA is an SMA that uses Kendall Rank Correlation to form a sort of noise elimination technology to smooth out trend shifts. You'll notice that the slope of the SMA line doesn't always match the color of the SMA line. This is behavior is expected and is the NET that removes noise from the SMA.

What is Kendall Rank Correlation?
Also commonly known as “Kendall’s tau coefficient”. Kendall’s Tau coefficient and Spearman’s rank correlation coefficient assess statistical associations based on the ranks of the data. Kendall rank correlation (non-parametric) is an alternative to Pearson’s correlation (parametric) when the data you’re working with has failed one or more assumptions of the test. This is also the best alternative to Spearman correlation (non-parametric) when your sample size is small and has many tied ranks.

Kendall rank correlation is used to test the similarities in the ordering of data when it is ranked by quantities. Other types of correlation coefficients use the observations as the basis of the correlation, Kendall’s correlation coefficient uses pairs of observations and determines the strength of association based on the patter on concordance and discordance between the pairs.

  • Concordant: Ordered in the same way (consistency). A pair of observations is considered concordant if (x2 — x1) and (y2 — y1) have the same sign.
  • Discordant: Ordered differently (inconsistency). A pair of observations is considered concordant if (x2 — x1) and (y2 — y1) have opposite signs.

Kendall’s Tau coefficient of correlation is usually smaller values than Spearman’s rho correlation. The calculations are based on concordant and discordant pairs. Insensitive to error. P values are more accurate with smaller sample sizes.

OxTp0qF.png



Has anyone translated the Kendall Rank Correlation NET study to ThinkScript? I've tried using several AI tools. None of them were able to produce something that would get past the ThinkorSwim syntax checker.
https://www.tradingview.com/script/neh5f526-Kendall-Rank-Correlation-NET-on-SMA-Loxx/

mod note:
script converted. see below
 
Last edited by a moderator:

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

Has anyone translated the Kendall Rank Correlation NET study to ThinkScript? I've tried using several AI tools. None of them were able to produce something that would get past the ThinkorSwim syntax checker.
check the below:
CSS:
#/ Indicator for TOS
#// © loxx
#indicator("Kendall Rank Correlation NET on SMA [Loxx]", shorttitle="KRCNETSMA [Loxx]",
# Converted by Sam4Cok@Samer800    - 07/2024
input movAvgType = averageType.SIMPLE;
input Source  = close; #, "Source", group = "Basic Settings")
input movAvgPeriod = 14; #, "SMA Period", group = "Basic Settings")
input netPeriod = 5; #, "NET Period", group = "Basic Settings", minval = 1)
input colorBars = no; #, "Color bars?", group = "UI Options")

def na = Double.NaN;

def smaperout = max(movAvgPeriod, 1);
def netperout = max(netPeriod, 2);
def netd = 0.5 * netperout * (netperout - 1);

def val = MovingAverage(movAvgType, Source, movAvgPeriod);

def netNum = fold k = 0 to netperout - 1 with p do
             fold j = 0 to k with q do
            q -  if ((sign(val[k] - GetValue(val, j))) > 0) then 1 else
                 if ((sign(val[k] - GetValue(val, j))) < 0) then -1 else 0;
      
def net = netNum / netd;

def valc = if (net > 0) then 0 else
           if (net < 0) then 1 else valc[1];
def col = if valc == 1 then -1 else if valc == 0 then 1 else 0;

plot Kendall = if val then val else na; #, color = colorout, linewidth = 3)
Kendall.SetLineWeight(2);
Kendall.AssignValueColor(if col > 0 then Color.CYAN else
                         if col < 0 then Color.MAGENTA else Color.GRAY);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if col > 0 then Color.GREEN else
                 if col < 0 then Color.RED else Color.GRAY);

#-- end of CODE
 
Last edited by a moderator:
Kendall Rank Correlation NET on SMA is an SMA that uses Kendall Rank Correlation to form a sort of noise elimination technology to smooth out trend shifts. You'll notice that the slope of the SMA line doesn't always match the color of the SMA line. This is behavior is expected and is the NET that removes noise from the SMA.

What is Kendall Rank Correlation?
Also commonly known as “Kendall’s tau coefficient”. Kendall’s Tau coefficient and Spearman’s rank correlation coefficient assess statistical associations based on the ranks of the data. Kendall rank correlation (non-parametric) is an alternative to Pearson’s correlation (parametric) when the data you’re working with has failed one or more assumptions of the test. This is also the best alternative to Spearman correlation (non-parametric) when your sample size is small and has many tied ranks.

Kendall rank correlation is used to test the similarities in the ordering of data when it is ranked by quantities. Other types of correlation coefficients use the observations as the basis of the correlation, Kendall’s correlation coefficient uses pairs of observations and determines the strength of association based on the patter on concordance and discordance between the pairs.

  • Concordant: Ordered in the same way (consistency). A pair of observations is considered concordant if (x2 — x1) and (y2 — y1) have the same sign.
  • Discordant: Ordered differently (inconsistency). A pair of observations is considered concordant if (x2 — x1) and (y2 — y1) have opposite signs.

Kendall’s Tau coefficient of correlation is usually smaller values than Spearman’s rho correlation. The calculations are based on concordant and discordant pairs. Insensitive to error. P values are more accurate with smaller sample sizes.

OxTp0qF.png



Has anyone translated the Kendall Rank Correlation NET study to ThinkScript? I've tried using several AI tools. None of them were able to produce something that would get past the ThinkorSwim syntax checker.


https://www.tradingview.com/script/neh5f526-Kendall-Rank-Correlation-NET-on-SMA-Loxx/
" I've tried using several AI tools. None of them were able to produce something that would get past the ThinkorSwim syntax checker" here you got the unique SUPER AI, Mr @samer800 🤣🤣
 
Last edited by a moderator:
As a financial analyst: Kaufman, Spearman, and Pearson's Correlations are the go-to instruments in my toolbox.

And while ToS has versions of these, as built-in indicators, even after hundreds of hours of customizing over the last six years, I have not been able to successfully incorporate these coefficients into my trading.

My conclusion is, when used in trading, with price and volume movement; the chaos and noise especially on the shorter aggregations clouds any chance of true statistical modeling.

My success rate in attempting to utilize correlations has been as poor as moving average strategies. 😖


My hope is, that with this amazing port of @samer800, new eyes will look at this awesome statistical tool and provide their input on successfully incorporating it into our strategies.
 
Last edited:
As a financial analyst: Kaufman, Spearman, and Pearson's Correlations are the go-to instruments in my toolbox.

And while ToS has versions of these, as built-in indicators, even after hundreds of hours of customizing over the last six years, I have not been able to successfully incorporate these coefficients into my trading.

My conclusion is, when used in trading, with price and volume movement; the chaos and noise especially on the shorter aggregations clouds any chance of true statistical modeling.

My success rate in attempting to utilize correlations has been as poor as moving average strategies. 😖


My hope is, that with this amazing port of @samer800, new eyes will look at this awesome statistical tool and provide their input on successfully incorporating it into our strategies.
@MerryDay , in your free time you should try Didi trading system ( ps: most of the related material is in Brazilian Portuguese). Worth
see my chart:
https://usethinkscript.com/threads/...-didi-index-for-thinkorswim.4793/#post-129590
 
Last edited by a moderator:
How do I create an alert for each time the price closes on the other side of a specific study?
In this case, the study is the Kendall Rank Correlation NET on SMA [Loxx] as shown at
https://usethinkscript.com/threads/kendall-rank-correlation-for-thinkorswim.18985/post-143683

Thanks!


To learn how to add alerts to your other studies:
https://usethinkscript.com/resources/how-to-add-alert-script-to-thinkorswim-indicators.9/

To add alerts to the Kendall Rank.
Append this code snippet to the bottom of the Kendall study:
Alert(close crosses above Kendall, "crosses above", Alert.Bar, Sound.ring);
Alert(close crosses below Kendall, "crosses below", Alert.Bar, Sound.ding);
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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