Percentile Nearest Rank Using Arrays [LuxAlgo]The new array feature is extremely powerful, as it will allow pinescript users to do more complex things, or compute existing calculations more efficiently, it will also be possible to shine some light to some already existing functions, one of them being percentile_nearest_rank .
We have been working on this new feature with our pal alexgrover, and made this script which computes a rolling percentile using the nearest rank method.
Settings
Length: Window of the rolling percentile, determine the number of past data to be used.
Percentage: Return the current value if Percentage % of the data fall below that value, the setting is in a range (0,100).
Src: Input source of the indicator.
Usage
A rolling percentile can have many usages when it comes to technical analysis, this is due to its ability to return the value of three common rolling statistics, the rolling median, which can be obtained using a percentage equal to 50, the rolling maximum, obtained with a percentage equal to 100, and the rolling minimum, obtained with a percentage equal to 0.
When we use our rolling percentile as a rolling median, we can obtain a robust estimation of the underlying trend in the price, while using it as a rolling maximum/minimum can allow us to determine if the market is trending, and at which direction. The rolling maximum/minimum is a rolling statistic used to calculate the well known stochastic oscillator and Donchian channel indicator.
We can also compute rolling quartiles, which can be obtained using a percentage of 25 or 75, with one of 25 returning the lower quartile and 75 the upper quartile.
In blue the upper rolling quartile (%75), in orange the lower rolling quartile (%25), both using a window size of 100.
Details
In order to compute a rolling percentile nearest rank, we must first take the most recent length closing prices, then order them in ascending order, we then return the value of the ordered observations at index (percentage/100*length) - 1 (we use - 1 because our array index starts at 0).
Median
Spread by//Every spread & central tendency measure in 1 script with comfortable visualization, including scrips's status line.
Spread measures:
- Standard deviation (for most cases);
- Average deviation (if there are extreme values);
- GstDev - Geometric Standard Deviation (exclusively for Geometric Mean);
- HstDev - Harmonic Deviation (exclusively for Harmonic Mean).
These modified functions will calculate everything right, they will take source, length, AND basis of your choice, unlike the ones from TW.
Central tendency measures:
- Mean (if everything's cool & equal);
- Median (values clustering towards low/high part of the rolling window);
- Trimean (3/more distinguishable clusters of data);
- Midhinhe (2 distinguishable clusters of data);
- Geometric Mean ( |low.. ... ... .. .... ... . . . . . . . . . . . .high| this kinda data); <- Exp law
- Harmonic Mean { |low. . . . . . . . . . . . . . .. . . .high| kinda data). <- Reciprocal law
Listen:
1) Don't hesitate using Standard Deviation with non-mean, like "Midhinge Standard Devition", despite what ol' stats gurus gonna say, it works when it's appropriate;
2) Don't check log space while using Geometric Mean & Geometric Standard Deviation, these 2 implement log stuff by design, I mean unless u wanna make it double xd
3) You can use this script, modify it how you want, ask me questions whatever, just make money using it;
4) Use Midrange & Midpoints in tandem when data follows ~addition law (like this . . . . . . . . . . . . . . . . . . . . .). <- just addition law
Look at the data, choose spread measure first, then choose central tendency measure, not vice versa.
!!!
Ain't gonna place ® sign on standard deviations like one B guy did in 1980s lmao, but if your wanna use Harmonic Deviations in science/write about/cite it/whatever, pls give me a lil credit at least, I've never seen it anywhere and unfortunately had to develop it by myself. it's useful when your data develops by reciprocals law (opposite to exponential).
Peace TW
Range identifier by medianThis study tries to highlight ranges
as they are defined by
TradingLatino TradingView user.
The study uses median values.
A range is defined as periods when the price does not move a lot.
Its default values are aimed at BTCUSDT pair and 4h timeframe.
HOW IT WORKS
For each of the bars a '5' median is calculated based on the 'highest of open and close'
For each of the bars a '5' median is calculated based on the 'lowest of open and close'
Thanks to the desviation setting both medians
have a tolerated maximum and a minimum
Condition 1:
The bar current 'highest of open and close'
needs to be between the respective tolerated
maximum and minimum
Condition 2:
The bar current 'lowest of open and close'
needs to be between the respective tolerated
maximum and minimum
If both conditions are met
then the bar is in a range
SETTINGS
Price range periods : How many previous periods are used to calculate the medians
Price range maximum desviation (%) ( > 0 ): Maximum positive desviation for range detection
Price range minimum desviation (%) ( > 0 ): Mininum negative desviation for range detection
Desviations should be both of them a positive number
WARNING
Despite the name indicator does not identify the entire range.
It identifies when you realise you are inside a range.
E.g. If a range length is 8 periods length this range indicator
will highlight only the last 6 periods of the range.
USAGE
If your strategy signals you an upwards trend
then you might use this range detector
to know when to exit your long position
Why?
Because most of the times
the price is found to be
in a range it goes down
FEEDBACK 1
My former attempt on calculating ranges
felt too much over complex that is why
I decided to implement it with medians.
It should be easier to modify if
I want to desviation inputs to be calculated
automatically in the future.
I'm interested on different approaches on how to detect ranges.
FEEDBACK 2
I have only used this identifier in BTCUSDT 4h timeframe.
Feel free to comment down below with your suggested settings
for your favourite pair and timeframe
PINE SCRIPT TRICK
This script simulates looping an string char by char
in pine script.
Rolling summaryStatistical methods based on mean cannot be effective all the time when attributed to financial data since it doesn't usually follow normal distribution, the data can be skewed or/and have extreme values which can be described as outliers.
In order to deal with this problem it is appropriate to use median-based techniques.
The most common one is called five-number summary/box plot, which plots median of the dataset, 25th (Q1) & 75th (Q3) percentiles (the medians of lower & upper parts of the original dataset divided by the original median), and whiskers calculated by taking range between Q1 and Q3, multiplying it by 1.5 and adding it to Q3 and subtracting it from Q1. The values which are outside the whiskers are considered outliers. Default settings of the script correspond to the classic box plot.
Seven-number summary can be also plotted by this script, by turning on 4 additional percentiles/Bowley’s seven-figure summary by turning on first 2 additional percentiles and changing their values to 10 and 90 respectively.
P.S.: Mean can be also turned in just to check the difference.
Recursive Median Oscillator & Fisher Transforms RibbonThis is a composite indicator made up of:
- modifided (rescaled) version of evergets version of recursive median oscillator.
- 1996anoojpatels Futur modification of Ehlers Fisher Transform Ribbons Indicator
I think Ehlers attempts to minimise latency in indicators are extremely valuable and some of my most use trading tools. Thanks to all the authors whose iterations keep moving these indicators toward perfection. Here is my contribution.
MCI and VCI - Modified CCI FormulasFor private peeps only
- Takes a modified version of the CCI formula into 2 parts
VCI - Volume Channel Index (Yellow Histogram)
- Measures accurate accumulation and distribution levels and times
MCI - Modified Channel Index
- Measures (when compared to VCI) levels where clearly buys are interested vs not interested.
Example:
If VCI > MCI
- Shows buyer's are more than interested in buying, you've either hit a bottom or heavy resistance
if MCI > VCI
- Show's buyer's aren't interested and will most likely result in a dump/lower price
Great for monitoring accumulation and distribution, these auto buy and sells look for the transition points over 0, works on EVERY commodity/stock/FOREX/Crypto
Results are from trading 1 BTC x25 leveraging. Not all trades will get in if put in at limit, but it does survive with profits after the massive 0.075 fee (results shown are after fees)
[RESEARCH] Custom Median vs Built-in MedianI compared custom median (using the sorting solution by @apozdnyakov) with built-in median (using percentile_nearest_rank function)
If you see the zero line this means the solutions give the same results.
The best results was achieved on the odd lengths.
Conclusions:
1) Do not try to reinvent the wheel.
2) Always check the Pine Script docs to find already implemented solutions.
Ehlers Smoothed Adaptive MomentumEhlers Smoothed Adaptive Momentum script.
This indicator was developed and described by John F. Ehlers in his book "Cybernetic Analysis for Stocks and Futures" (2004, Chapter 12: Adapting to the Trend).
Hampel FilterHampel Filter script.
This indicator was originally developed by Frank Rudolf Hampel (Journal of the American Statistical Association, 69, 382–393, 1974: The influence curve and its role in robust estimation).
The Hampel filter is a simple but effective filter to find outliers and to remove them from data. It performs better than a median filter.
Interquartile Range BandsInterquartile Range Bands script.
This indicator was originally developed by Alex Orekhov at his home.
The idea based on the interquartile range en.wikipedia.org
If price breaks out from the bands then it is `outlier` price.
After breakouts price always returns to its median.
Watch squeeze/expansion periods.
Anyway use it as a supplement to the other indicators.
I will glad to get your feedback.
Recursive Median FilterRecursive Median Filter indicator script.
This indicator was originally developed by John F. Ehlers (Stocks & Commodities V. 36:03 (8–11): Recursive Median Filters).
Recursive Median OscillatorRecursive Median Oscillator indicator script.
This indicator was originally developed by John F. Ehlers (Stocks & Commodities V. 36:03 (8–11): Recursive Median Filters).
Bill Williams Averages. 3Lines Strategy This indicator calculates 3 Moving Averages for default values of
13, 8 and 5 days, with displacement 8, 5 and 3 days: Median Price (High+Low/2).
The most popular method of interpreting a moving average is to compare
the relationship between a moving average of the security's price with
the security's price itself (or between several moving averages).
Function Mean Median Mode V0EXPERIMENTAL:
Request for GLAZ
Functions to handle Mean, Median, Mode Calculation.
% Median v1 This indicator shows the percentage amount the price is above or below the moving median value of the period.
This indicator is best used along with the moving median (set to the same period).
Based on the moving median developed with 4x4good
Moving MedianThis simple script was a collaborative effort with 4X4good.
It plots a moving median for the period using the 50th percentile value.
We wanted to know the median value of VIX but surprisingly, a median indicator wasn't yet available in the indicators library.
So we did a little research & put this together.
Simple Horizontal Value and Offsets [Auto Shift]Original (Simple Horizontal Value and Offsets/SHV) Requested by @TAFA94
Description:
Simple adjustable incremented horizontal offset lines extending up and down from a Median point.
Set full value for manual Median point control, or set an incremental rounding value for auto Median adjustment.
Source and look-back period inputs for fine tuning auto adjust.
Auto adjust on by default - can be toggled off for straight manual control.
**NOTE**
All values will likely need to be changed immediately on applying this script, in order to properly fit your charts specific price/value range and/or time resolution.
Cheers!
[RS]Temporal Median Price V1EXPERIMENTAL: previous custom time window median price and current time window open price in a neat package :p
(JeanLouisHardy) added option for bar count system, also added a donchian average.
[RS]JR Moving Average System V1.bupdate: changes to code, ma's now split over 3 sets fast, medium and slow, removed cloud and sl_lines(no use?), ma's visually display as shapes :p added option to toggle the ma's on/off.
[RS]Temporal Median Price V0EXPERIMENTAL: previous custom time window median price and current time window open price in a neat package :p