Alpha Trading - Absolute Mean Entropy with A2 EPPAbsolute Mean Entropy with Alpha Squared Entropy Price Percentile
Entropy
The history of the word ―entropy can be traced back to 1865 when the German physicist Rudolf Clausius tried to give a new name to irreversible heat loss, what he previously called ―equivalent-value.
The word ―entropy was chosen because in Greek, “en+tropein” means “content transformative” or “transformation content”
Since then, entropy has played an important role in thermodynamics and many other scientific fields. Being defined as the sum of “heat supplied” divided by “temperature” it is central to the Second Law of Thermodynamics. It also helps measure the amount of order and disorder and/or chaos.
The application of entropy in finance can be regarded as an extension of “Information Entropy” and “Probability Entropy”
Entropy in Finance can be used in many ways such as Asset Selection, Asset Diversification, Measure an Assets Risk, inputs into Options pricing. While Entropy started in the field of Thermodynamics as aforementioned it has also found a home in Finance. However, studies with entropy in the field of Finance are still in their infancy.
• Entropy is a measure of randomness. Entropy is used to help model and represent the degree of uncertainty of a random variable.
• Entropy is used by financial analysts and market technicians to determine the chances of a specific type of behavior by a security or market.
• Entropy has long been a source of study and debate by market analysts and traders. It is used in quantitative analysis and can help predict the probability that a security will move in a certain direction or according to a certain pattern.
The concept of Entropy is explored in the book "A Random Walk Down Wall Street."
Entropy is plotted below the axis with negative values. Entropy can also colorize the candle color if selected.
R-squared (The Coefficient of Determination)
R-squared is a statistical measurement that examines how differences in one variable can be explained by the difference in a second variable, when predicting the outcome of a given event.
In other words, this coefficient, which is more commonly known as R-squared (or R2), assesses how strong the linear relationship is between two variables, and is heavily relied on by researchers when conducting trend analysis.
To cite an example of its application, this coefficient may contemplate the following question: if an indicator becomes pregnant on a certain day, what is the likelihood that this indicator would deliver a new indicator on a particular date in the future? In this scenario, this metric aims to calculate the correlation between two related events: conception of the indicator and the birth of the indicator.
• The coefficient of determination is a complex idea centered on the statistical analysis of models for data.
• The coefficient of determination is used to explain how much variability of one factor can be caused by its relationship to another factor.
• This coefficient is commonly known as R-squared (or R2) and is sometimes referred to as the "goodness of fit."
• This measure is represented as a value between 0.0 and 1.0, where a value of 1.0 indicates a perfect fit, and is thus a highly reliable model for future forecasts, while a value of 0.0 would indicate that the model fails to accurately model the data at all.
R2 and Price
The hypothesis that R2 is related to investors’ biases in processing information.
This theory motivates an empirical hypothesis that stocks with lower R2 should exhibit more pronounced overreaction-driven price momentum.
Alpha Trading AME/A2 EPP Settings
Settings for AME (Absolute Mean Entropy)
Length: Sample size.
Use as Barcolor: AME color as Price Action Candle color.
Show Entropy Flashes: If absolute value of entropy is very low, it gives yellow color for AME and Price Action Candle color if selected.
Band StdDev: (2 times) AME StdDev bands.1st and 2nd default.
Exponential Weighted Entropy: Weights the AME exponentially, is more reactive, but more noise.
Settings for EPP (Entropy Price Percentile)
Percentile Period: lookback for percentile range(relevant for flashes)
Background flashes: if EPP is below threshold default is below 10%, Flashes green in the background.
Std.err bands period: default 3 and multiplier 1.
EPP Column Meanings
Bright Green: Returns above the mean and increasing.
Dark Green: Returns above the mean and decreasing.
Bright Red: Returns below the mean and increasing.
Dark Red: Returns below the mean and decreasing.
Basic Trade Signal
Long – Value of AME is low, as you see EPP increasing with a coloration of green consider taking a long if you have confluence with other Alpha Trading Indicators.
Short – Value of AME is low, as you see EPP increasing with a coloration of red consider taking a short if you have confluence with other Alpha Trading Indicators.
The Chart below is showing Entries, Exponential Weighting input turned on, Percentile Period set to 30 instead of default 100, everything else is Default....
When using other Alpha Trading indicators in confluence, there are other entries available when the indicator isn't flashing and the indicator still supports the move.
References
www.investopedia.com
www.investopedia.com
www.wallstreetmojo.com
byjus.com
www.investopedia.com
en.wikipedia.org
papers.ssrn.com
Percentile
Momentum Performance This Indicator displays the momentum (performance) of the symbol in percent.
You can compare the performance with other symbols.
The default benchmarks are the S&P 500, the MSCI World and the FTSE All World EX US.
The default length corresponds to one year in the timeframes monthly, weekly and daily.
In intraday the default length is 200, but you can also set your own setting.
You have also the opportunity to display a average momentum performance of the main symbol.
P-Square - Estimation of the Nth percentile of a seriesEstimation of the Nth percentile of a series
When working with built-in functions in TradingView we have to limit our length parameters to max 4999. In case we want to use a function on the whole available series (bar 0 all the way to the current bar), we can usually not do this without manually creating these calculations in our code. For things like mean or standard deviation, this is quite trivial, but for things like percentiles, this is usually very costly. In more complex scripts, this becomes impossible because of resource restrictions from the Pine Script execution servers.
One solution to this is to use an estimation algorithm to get close to the true percentile value. Therefore, I have ported this implementation of the P-Square algorithm to Pine Script. P-Square is a fast algorithm that does a good job at estimating percentiles in data streams. Here's the algorithms original paper .
The chart
On the chart we see:
The returns of the series (blue scatter plot)
The mean of the returns of the series (orange line)
The standard deviation of the returns of the series (yellow line)
The actual 84.1th percentile of the returns (white line)
The estimatedl 84.1th percentile of the returns using the P-Square algorithm (green line)
Note: We can see that the returns are not normally distributed as we can see that one standard deviation is higher than the 84.1th percentile. One standard deviation should equal the 84.1th percentile if the data is normally distributed.
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.
Historical Volatility Percentile + SMAHistorical Volatility Percentile tells you the percentage of the days from the past year (252 trading days) that have lower volatility than the current volatility.
I included a simple moving average as a signal line to show you how volatile the stock is at the moment.
I have included simple colors to let you know when to enter or exit a position.
Buy when price higher than EMA & historical volatility higher than SMA
Sell when price lower than EMA & historical volatility higher than SMA
Please let me know if you would like me to publish any other indicators! I always love to hear from you guys.
Volatility IndexThis is a composite volatility index to show percentile of current volatility compared to that of the last 52 bars. As this is a weekly chart (and this script is intended for usage on weekly charts) we can see the yearly percentile rank of volatility.
As shown when volatility is in the lower 25%tile (viewed on weekly) the market is calm and likes to rise; when the volatility is above the 25%tile you can see that the market tends to have larger and 'choppier' moves.
This is /not/ 'just the vix' this takes into consideration the volatility of all major US indexes including the SPX500, Dow 30, Nasdaq 100, and Russel 2000.
Please remember that this is just plotting:( volatility index - lowest(index,52) )/( highest(index,52)-lowest(index,52) ) so for 'yearly percentile' check the weekly chart (52 weeks = 1yr)
Quantile BandsMiddle quantile/band color is set by confluence of the outer quantiles and not by it's own slope. Optional MTF.
Moving Gain Loss PercentTracks the percentage gain/loss in three ranges:
single candle (can be turned on or off)
custom range of candles
custom range of candles
For example, with a range of 3 candles, and the serie:
1 - close 10
2 - close 5
3 - close 20
The moving gain would be:
1 - close 10 - gain 10, infinite%
2 - close 5 - gain 5, infinite%
3 - close 18 - gain 8, 80%
Or, for example if the range is 12 candles on a monthly chart, then the result is the Year-To-Date gain/loss plotted as a percentage.
DWP_percentile_linear_interpolation
Hope this help to see the % of winners and losers in the market.
MoveTrap.
Percentile Trend Channel [DW]This is an experimental study designed to identify the trend of price action over a specified period using percentiles.
First, the 50th percentile is calculated over the sampling period using the nearest rank method. I've found that this calculation is useful as a proxy for moving averages and other filters of that class.
Next, the channel levels are calculated. In this study, there are three channel methods to choose from:
-Percentile Donchian, which calculates Donchian Channels using the 100th and 0th percentile ranks
-Percentile Keltner, which calculates the 50th percentile true range multiplied by a specified amount, then adds it to and subtracts it from the 50th percentile
-Percentile Bollinger, which calculates 50th percentile standard deviation multiplied by a specified amount, then adds it to and subtracts it from the 50th percentile
I also included a squeeze box option within this script, which is derived from my original Squeeze Box tool.
This option detects squeezes in the specified channel's range by a specific percentage, and plots the channel values where the squeeze begins.
The box also has a range multiplier, which can be used to expand or contract its range.
Custom bar colors are included. The color scheme is based on the perceived trend over the specified sampling period.
[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.
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.
_CM_BarRange_PercentileI know a Trader that went 18 months without a losing trade. This Trader averaged trading 700-800 contracts per month in the Futures markets.
The was not his only system but here were his rules.
He looked at the 60 minute bar and calculated the ranges of the bars over the last 3 months. IF the range of the Bar was Greater Than the 99th Percentile, He would Fade that move or take the trade in the opposite direction.
Thought process is If the Price Bar is Greater Than the 99th Percentile then typically the market reverses. This happens a lot of times at news events. If you’ve studied the markets long enough you know if a Nes based event causes a Huge Move, which we define as Greater than the 99th Percentile, the Market typically moves in the opposite direction.
***This is dependent on the Instrument your trading and the time frame your trading. Some Instruments and time frames this signals a continuation move.
I also added in the Low of the Range based on the 99th Percentile. Often times Low Range Bars…especially if they appear at the top of a swing move, or the bottom of a swing move…create a high probability entry once the High or Low of the bar is taken out in the opposite direction of the previous move…The Low Range bars show indecision after a strong move and create great reversal opportunities.
Works on All Time Frames…again depending on the instrument your trading.
On instruments that MOVE or have High Volatility like Crude and Oil you can get great signals on 1 minute bars.
***Code includes ability to pick ham many bars you want your Look Back Period To Be.
***You can change the percentages to use the 99th Percentile, or 95th percentile, etc…
***The Green Line is the Value of the High Range Percentile.
***The Red Line is the Value of the Low Range Percentile.
***Plots a Magenta Cross on the Red Line if the Range is Below the Low Range Percentile.
***Plots a yellow Cross on the Green Line if the Range is Greater Than the High Range Percentile.
***The Aqua line is the Midpoint of the Range. Or the Average Price Move.
***Colors the Price Bar Yellow if the Range exceeds the High Range Percentile.
***Colors The Bar Magenta if the Range is Less Than the Low Range Percentile
***All parameters can be turned on or off via Check Boxes in the Inputs Tab