Correlation Percentile

Samus Aran

New member
hey everyone, I'm trying to make my own Correlation indicator with just adding as a modification the Mean & Percentile from the original indicator that ThinkorSwim provided . I got the mean to work, but I'm having trouble with the Percentile. I don't want the Percentile to be display on the graph; I want it display on the title of the indicator above its window, so I can get just coefficient Percentile of this instrument and compare the Percentile coefficient with other instruments.

sincerely

Code:
declare lower;

input length = 2000;
input correlationWithSecurity = "SPY";

plot Correlation = Correlation(close, close(correlationWithSecurity), length);
Correlation.SetDefaultColor(GetColor(5));

plot ratioAvg = ExpAverage(Correlation, length);

plot center = 0;

def currentCorrelation = Correlation(BarNumber(), close, length);


 CorrelationPercentile = AsPercent((currentCorrelation / length));
 
nevermind the code above, let me reword my question: I would like to make a counter to count how many bars were under 0 and how many bars were above 0 on the Correlation axis of 0. And then compare the two percentages of above 0 & below 0 to see if these two instruments compared with each other are "for example 60%" negatively correlated or they are more positively correlated. Again I don't want it to be 60%, its just an example; I just want to find if most of the time if they are positively correlated or negatively correlated & what's that specific percentage.

Ty for the ones who decide to help me

Code:
declare lower;

input length = 14;
input length2 = 11682;

input correlationWithSecurity = "SPY";

plot Correlation =  Correlation(close, close(correlationWithSecurity), length);
Correlation.SetDefaultColor(GetColor(5));

plot ratioAvg = ExpAverage(Correlation, length);

plot center = 0;

rec postive = if Correlation > 0 then postive + 1 else 0;

rec negative = if Correlation < 0 then negative + 1 else 0;

def temp = Max ( postive,  negative); 

plot PercentChg = 100 * ( temp / temp[length2] - 1);
 
Last edited:
@Samus Aran I don't really understand how counting the amount of bars above 0 will lead to correlation between 2 tickers. The Correlation study itself will tell you that from -1 to 1/ -100% to 100% based on some given length. So if length is 14 and study says .41 then correlation is 41% for the past 14 bars. Maybe I'm not getting it.
 
thank you for replying,
let me explain further, the correlation study just tells you what is the correlation for that candlestick at that given time "for example on Tuesday 2:00pm it had +0.05". That does not tell me if in its entirety is this instrument more negatively correlated or positively correlated . I would like to add up all the correlations at each candle stick and at the end I would like to determine that within a 6 month period which is the highest that the chart goes, how much in its entirety is this instrument more negatively correlated or positively correlated or they are exactly the same at 0.

entirety == 6 months
 

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
279 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