Weighted percentile nearest rankYo, posting it for the whole internet, took the whole day to find / to design the actual working solution for weighted percentile 'nearest rank' algorithm, almost no reliable info online and a lot of library-style/textbook-style solutions that don't provide on real world production level.
The principle:
0) initial data
data = 22, 33, 11, 44, 55
weights = 5 , 3 , 2 , 1 , 4
array(s) size = 5
1) sort data array, apply the sorting pattern to the weights array, resulting:
data = 11, 22, 33, 44, 55
weights = 2 , 5 , 3 , 1 , 4
2) get weights cumsum and sum:
weights = 2, 5, 3 , 1 , 4
weights_cum = 2, 7, 10, 11, 15
weights_sum = 15
3) say we wanna find 50th percentile, get a threshold value:
n = 50
thres = weights_sum / 100 * n
7.5 = 15 / 100 * 50
4) iterate through weights_cum until you find a value that >= the threshold:
for i = 0 to size - 1
2 >= 7.5 ? nah
7 >= 7.5 ? nah
10 >= 7.5 ? aye
5) take the iteration index that resulted "aye", and find the data value with the same index, that's gonna be the resulting percentile.
i = 2
data = 33
This one is not an approximation, not an estimator, it's the actual weighted percentile nearest rank as it is.
I tested the thing extensively and it works perfectly.
For the skeptics, check lines 40, 41, 69 in the code, you can comment/uncomment dem to switch for unit (1) weights, resulting in the usual non-weighted percentile nearest rank that ideally matches the TV's built-in function.
Shoutout for @wallneradam for the sorting function mane
...
Live Long and Prosper
Rank
Price-Filtered Spearman Rank Correl. w/ Floating Levels [Loxx]Price-Filtered Spearman Rank Correl. w/ Floating Levels is a Spearman Rank Correlation indicator with optional source filtering and floating levels.
What is Spearman rank correlation?
Spearman rank correlation, also known as Spearman coefficient is a formula used to identify the strength of the link between two datasets. This coefficient is a method that can be used to assess the strength of a relationship apart from the direction it takes. The formula, named after Charles Spearman, a mathematician, can only be used in circumstances where data can be categorized or put in order, for instance, the highest to the lowest.
For a better understanding of Spearman coefficient, it helps to get a sense of what monotonic function means. There’s a monotonic relationship under these circumstances:
– When the variable values rise together.
– When one variable value rises the other variable value lowers.
– The rate of movement of the variables need not necessarily be constant.
The Spearman correlation coefficient or rs, between +1 and -1, where +1 indicates a perfect strength between variables, while zero shows no association and -1 shows a perfect negative strength.
Spearman rank correlation theory:
A nonparametric (distribution-free) rank statistic proposed by Spearman in 1904 as a measure of the strength of the associations between two variables (Lehmann and D'Abrera 1998). The Spearman rank correlation coefficient can be used to give an R-estimate, and is a measure of monotone association that is used when the distribution of the data make Pearson's correlation coefficient undesirable or misleading.
Included:
Zero-line and signal cross options for bar coloring, signals, and alerts
Alerts
3 Signal types
Loxx's Expanded Source Types
Bitcoin Movement vs. Coin's Movement MTFThis script tracks the percent change of Bitcoin vs. the percent change of the coin on the chart. Crypto markets are usually affected greatly by Bitcoin swings so being able to see if the given coin is trending above or below Bitcoin is useful market data. All choices made with this script are your own! Thanks.
Price Range TableThe table shows the ranking of the price as a percentage relative to the past candles.
100 ~ highest price of the time frame
0 ~ lowest price of the time frame
Technical RankHello Traders,
Technical Rank (TR) was authored by John Murphy . Technical Rank shows how a security is performing relative to its peers. Multiple moving averages, rate of change and the Relative Strength Index (RSI) indicators are used to calculate the Technical Rank. These values are mathematically manipulated with percentage factors and then summed together. there are 3 parts, long term, middle term and short term. for Long term part Moving Average with length 200 (30%) and Rate of Change with the length 125 (30%) are used, for middle term part, Moving Average with length 50 (15%) and Rate of Change with the length 20 (15%) are used and for short term part, PPO (5%) and RSI (5%) used.
Technical Rank is created using the following formula and weightings:
Long-Term Indicators (weighting): Percent above/below the 200-day exponential moving average (EMA) (30% weight) and the 125-day rate-of-change (ROC) (30% weight).
Medium-Term Indicators (weighting): Percent above/below 50-day EMA (15%) and the 20-day rate-of-change (15%).
Short-Term Indicators (weighting): Three-day slope of percentage price oscillator histogram divided by three (5%) and the relative strength index (5%).
The scripts calculates Technical Rank for 10 different securities and sorts them by Technical Rank value. A ranking of zero indicates the stock is the weakest in the group technically. A rank of 100 indicates the stock ranks highest in terms of technical performance. An increasing Technical Rank means the stock's price performance is showing strength relative to the group of stock being analyzed. A decreasing Technical Rank shows deteriorating relative price performance. Securities in the top 3-4 will have a technical rank of 70 or higher. You should focus on these relatively strong securities for potential long positions on pullbacks. You can also use the technical rank to avoid weak securities (in the bottom 3-4). I recommend you to check Technical Rank for the securities in multiple time frames.
You can choose the symbols as you want but you should choose the symbols with the same session info. for example only Cryptos, only Stocks, only FX pairs etc. (not mix of them).
Enjoy!
Spearman Rank Correlation CoefficientI'm pleased to introduce this script in honor of the new array functions introduced to PineScript version 4.0. This update is a long time coming and opens the door to amazing scripting possibilities!
Definition
Named after Charles Spearman and denoted by the Greek letter ‘ ρ ’ (rho), the Spearman rank correlation coefficient is the nonparametric version of the Pearson correlation coefficient . Use the Spearman rank correlation when you have two ranked variables, and you want to see whether the two variables covary. That is, as one variable increases/decreases, the other variable tends to increase/decrease respectively.
It is best used to discover if two variables (and in this first version of the indicator, two ticker symbols) increase and decrease together. There are advantages to using this version of correlation vs. the Pearson R.
Interpretation
The value oscillates between +1 and -1.
A value of +1 means the two variables are perfectly correlated, that is they are increasing and decreasing together in perfect harmony.
A value of -1 means the two variables exhibit a perfect negative correlation, that is they increase and decrease oppositely.
A value of zero means the two variables are not correlated at all (noise).
Stochastic based on Closing Prices - Identify and Rank TrendsStochClose is a trend indicator that can be used on its own to measure trend strength, in a scan to rank a group of securities according to trend strength or as part of a trend following strategy. Moreover, it acts as a volatility-adjusted trend indicator that puts securities on an equal footing.
StochClose measures the location of the current close relative to the close-only high-low range over a given period of time. In contrast to the traditional Stochastic Oscillator, this indicator only uses closing prices. Traditional Stochastic uses intraday highs and lows to calculate the range. The focus on closing prices reduces signal noise caused by intraday highs and lows, and filters out errant or irrationally exuberant price spikes.
Here are some examples when the high or low was out of proportion and suspect. Perhaps most famously, there were errant spike lows in dozens of ETFs in August 2015 (XLK, IJR, ITB). There were other spikes in VMBS (October 2014), IJR (October 2008) and KRE (May 2011). Elsewhere, there were suspicious spikes in IEI (April 2020), CHD (March 2020), CCRN (March 2020) and FNB (March 2020)
The preferred setting to identify medium and long-term uptrends is 125 days with 5 days smoothing. 125 days covers around six months. Thus, StochClose(125,5) is a 5-day SMA of the 125-day Stochastic based on closing prices. Smoothing with the 5-day SMA introduces a little lag, but reduces whipsaws and signal noise.
StochClose fluctuates between 0 and 100 with 50 as the midpoint. Values above 80 indicate that the current price is near the high end of the 125-day range, while values below 20 indicate that price is near the low end of the range. For signals, a move above 60 puts the indicator firmly in the top half of the range and points to an uptrend. A move below 40 puts the indicator firmly in the bottom half of the range and points to a downtrend.
StochClose values can also be ranked to separate the leaders from the laggards. In contrast to Rate-of-Change and Percentage Above/Below a Moving Average, StochClose acts as a volatility-adjusted indicator that can identify trend strength or weakness. The Consumer Staples SPDR is unlikely to win in a Rate-of-Change contest with the Technology SPDR. However, it is just as easy for the Consumer Staples SPDR to get in the top of its range as it is for the Technology SPDR. StochClose puts securities on an equal footing.
StochClose measures trend direction and trend strength with one number. The indicator value tells us immediately if the security is trending higher or lower. Furthermore, we can compare this value against the values for other securities. Securities with higher StochClose values are stronger than those with lower values.
ADL-NDX Rank Difference-Buschi
English:
An expansion of the Advance Decline Line of the NASDAQ. It can be interesting to compare the Advance Decline Line with the corresponding benchmark index. I therefore made a ranking (0 to 100) based on the performance over the last days (default: 21 days). The difference is the target figure and ranges between -100 (bearish divergence) to +100 (bullish divergence).
Deutsch:
Eine Erweiterung der Advance Decline Line der NASDAQ. Oft möchte man den Verlauf der Advance Decline Line mit dem zugehörigen Leitindex vergleichen. Daher habe ich für beide ein Ranking (0 bis 100) erstellt auf Basis des Verlaufs über die letzten Tage (Standardwert: 21 Tage). Die Differenz stellt dabei die Zielgröße dar und schwankt zwischen -100 (bärische Divergenz) und +100 (bullische Divergenz).
ADL-SPX Rank Difference-Buschi
English:
An expansion of the Advance Decline Line of the NYSE. It can be interesting to compare the Advance Decline Line with the corresponding benchmark index. I therefore made a ranking (0 to 100) based on the performance over the last days (default: 21 days). The difference is the target figure and ranges between -100 (bearish divergence) to +100 (bullish divergence).
Deutsch:
Eine Erweiterung der Advance Decline Line der NYSE. Oft möchte man den Verlauf der Advance Decline Line mit dem zugehörigen Leitindex vergleichen. Daher habe ich für beide ein Ranking (0 bis 100) erstellt auf Basis des Verlaufs über die letzten Tage (Standardwert: 21 Tage). Die Differenz stellt dabei die Zielgröße dar und schwankt zwischen -100 (bärische Divergenz) und +100 (bullische Divergenz).
DWP_percentile_linear_interpolation
Hope this help to see the % of winners and losers in the market.
MoveTrap.
Skew Index Rank-Buschi
English:
a quick and simple tampering with the SKEW Index (also known as the "Black Swan Index")
Personally, I find it quite difficult to use the SKEW Index as a reliable indicator. Nevertheless I implemented a ranking system (from 0 to 100) with the option to include a certain time period (default: 252 trading days (units)) and a moving average (default: 21 days (units)).
Feedback is most welcome to modify / improve the script.
Deutsch:
eine schnelle und einfache Bearbeitung des SKEW Index (auch als "Schwarzer Schwan Index" bekannt)
Persönlich finde ich es recht schwierig, den SKEW Index als verlässlichen Indikator zu verwenden. Trotzdem habe ich hier einfach einmal ein Ranking-System (von 0 bis 100) aufgesetzt mit der Option, einen gewissen Zeitrahmen (Standardwert: 252 Handelstage (Einheiten)) und einen gleitenden Durchschnitt (Standardwert: 21 Tage (Einheiten)) einzubinden.
Feedback ist sehr willkommen, um das Skript zu überarbeiten / zu verbessern.
Historical Volatility RankSame formulation of IVR but based on Historical Volatility instead.
Serves the same purpose as IV rank.