Spearman Rank Correlation - MetaTrader 5 Script | Trading Script Download - MT4/MT5 Resources




Spearman's rank correlation is a nonparametric method used for statistical analysis of correlations.
The actual calculation of the Spearman rank correlation ratio involves the following steps:

Where
is the sum of ranking differences,
are many pairs of observations.
When using rank correlation ratios, it is common to evaluate how closely the parameters are correlated. Ratio values equal to or less than 0.3 are considered to exhibit weak correlation closeness, values greater than 0.4 but less than 0.7 are considered to exhibit moderate correlation closeness, and values equal to or greater than 0.7 indicate high correlation closeness.
The power of the Spearman rank correlation is slightly lower than the power of the correlation parameter ratio. When there are few observations, it is reasonable to use the rank correlation ratio.
This indicator is a type of oscillator, but unlike oscillators, it is smoother and stochastic while not lagging at reversal points.
The only external parameter that affects the calculation algorithm is rangeN, which sets the number of bars for which we are looking for regularities. If rangeN = 14, we use the closing price sequence Close[i], Close[i+1], ... Close[i+rangeN-1] and create a ranked sequence of them, i.e. where each close price is (if the sequence is sorted). In this case, we have a real graph to compare to a graph of steady growth.
The direction parameter indicates sorting in descending order (true) or ascending order (false). A true parameter value displays a more traditional image, while false displays a mirrored image.
The CalculatedBars parameter is implemented to limit the number of bars on which calculations are performed and to save CPU resources (although it may not be that important). A value of zero means that the calculation involves the entire available history. The Maxrange parameter sets the maximum calculation period equal to 30. This parameter is also implemented to save resources and may be useful for some traders.

Spearman rank correlation index
Attachment download
📎 spearmanrankcorrelation.mq5 (7.23 KB)
Source: MQL5 #460
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •