Entropy-Based Adaptive SuperTrendOverview:
Introducing the Entropy-Based Adaptive SuperTrend – a groundbreaking trading indicator designed to adapt dynamically to market conditions using market entropy. This enhanced SuperTrend indicator adjusts its sensitivity according to the level of chaos (or order) in price movements, providing more stable signals during volatile periods and more responsive signals when the market becomes orderly.
Key Features:
Entropy-Adaptive Mechanism: By incorporating an entropy measure, this indicator estimates the degree of unpredictability in the market. During high entropy periods (more chaotic), signals are made less sensitive, while during low entropy periods, the indicator reacts more quickly to price changes.
Adaptive ATR Multiplier: Unlike traditional SuperTrend indicators that use a fixed ATR multiplier, this version calculates a dynamic ATR multiplier based on the entropy score, ensuring more flexibility and adaptability in setting stop levels.
Visual Clarity: The indicator is overlayed on the price chart with customizable visual elements. The bullish and bearish trends are color-coded for ease of use, and optional entry signals ("L" for long and "S" for short) are plotted to clearly mark potential entry opportunities.
Alerts for Key Opportunities : Never miss an opportunity with built-in alerts for buy and sell signals. Traders can easily configure these alerts to be notified instantly when market conditions trigger a new trend.
How It Works:
Entropy Calculation: The entropy of the price data is calculated over a user-defined period, giving an indication of the degree of randomness in the price movements. The result is then smoothed to reduce noise and create a meaningful trend indication.
Dynamic ATR Adjustment: The ATR (Average True Range) multiplier, which controls the distance of the trailing stop, is adjusted based on the entropy score. This allows the SuperTrend line to widen in chaotic times, reducing false signals, while tightening in orderly times, allowing quicker trend captures.
Parameters Explained:
Entropy Settings: Control the sensitivity of entropy calculations, including the look-back period, number of bins for price distribution, and smoothing length.
Adaptive Settings: Adjust how the indicator adapts to different levels of entropy, including the adaptation period and the filtering weight.
SuperTrend Settings : Customize the ATR period and the dynamic multiplier range to fine-tune the trailing stops for your trading style.
Visual Settings: Choose your preferred colors for bullish and bearish trends, and decide if you want the entry labels displayed directly on the chart.
Use Cases:
Swing Traders can utilize the indicator to capture trend reversals while filtering out the noise during high entropy periods.
Intraday Traders can adapt the settings for shorter time frames to benefit from dynamic adjustments that reduce overtrading and false signals.
Risk Management: The entropy-based adaptive feature provides an edge in risk management by reducing sensitivity during times of increased chaos, thus helping to limit unnecessary trades.
How to Use It:
Look for entry labels ("L" for long, "S" for short) to identify potential opportunities.
Use the color-coded trendlines to determine market bias: greenish hue for bullish trends, reddish hue for bearish trends.
Customize the input settings to align with your preferred market timeframe and risk profile.
Alerts & Notifications:
Built-in alerts notify you of significant trend changes. Simply enable these alerts to receive updates when a new long or short opportunity is detected, helping you stay ahead without needing to watch the screen constantly.
Customization Tips:
Longer Timeframes : Increase the Entropy Period to better capture macro trends in high timeframe charts.
Higher Volatility Markets: Increase the ATR Max Multiplier to ensure stops are set farther away during high entropy.
Lower Volatility Markets: Use a lower ATR Base Multiplier and tighter entropy thresholds to capture rapid price movements.
Final Thoughts:
The Entropy-Based Adaptive SuperTrend indicator merges traditional trend-following logic with an adaptive mechanism driven by market entropy, aiming to address the challenges of whipsaws and false signals common in conventional SuperTrend setups. This indicator offers an intelligent and flexible way to track market trends, suitable for both beginners and experienced trade
Entropy
Volume EntropyKey Components :
📍 Natural Logarithm Function : The script starts by employing a custom Taylor Series approximation for natural logarithms. This function serves to calculate entropy with higher accuracy than conventional methods, laying the foundation for further calculations.
📍 Entropy Calculation : The core of this indicator is its entropy function. It employs the custom natural log function to compute the randomness of the trading volume over a user-defined micro-pattern length, offering insights into market stability or volatility.
📍 Micro-Pattern Length : This is the parameter that sets the stage for the level of detail in the entropy calculation. Users can adjust it to suit different time frames or market conditions, thus customizing the indicator's sensitivity to randomness in trading volume.
Adaptive Two-Pole Super Smoother Entropy MACD [Loxx]Adaptive Two-Pole Super Smoother Entropy (Math) MACD is an Ehlers Two-Pole Super Smoother that is transformed into an MACD oscillator using entropy mathematics. Signals are generated using Discontinued Signal Lines.
What is Ehlers; Two-Pole Super Smoother?
From "Cycle Analytics for Traders Advanced Technical Trading Concepts" by John F. Ehlers
A SuperSmoother filter is used anytime a moving average of any type would otherwise be used, with the result that the SuperSmoother filter output would have substantially less lag for an equivalent amount of smoothing produced by the moving average. For example, a five-bar SMA has a cutoff period of approximately 10 bars and has two bars of lag. A SuperSmoother filter with a cutoff period of 10 bars has a lag a half bar larger than the two-pole modified Butterworth filter.Therefore, such a SuperSmoother filter has a maximum lag of approximately 1.5 bars and even less lag into the attenuation band of the filter. The differential in lag between moving average and SuperSmoother filter outputs becomes even larger when the cutoff periods are larger.
Market data contain noise, and removal of noise is the reason for using smoothing filters. In fact, market data contain several kinds of noise. I’ll group one kind of noise as systemic, caused by the random events of trades being exercised. A second kind of noise is aliasing noise, caused by the use of sampled data. Aliasing noise is the dominant term in the data for shorter cycle periods.
It is easy to think of market data as being a continuous waveform, but it is not. Using the closing price as representative for that bar constitutes one sample point. It doesn’t matter if you are using an average of the high and low instead of the close, you are still getting one sample per bar. Since sampled data is being used, there are some dSP aspects that must be considered. For example, the shortest analysis period that is possible (without aliasing)2 is a two-bar cycle.This is called the Nyquist frequency, 0.5 cycles per sample.A perfect two-bar sine wave cycle sampled at the peaks becomes a square wave due to sampling. However, sampling at the cycle peaks can- not be guaranteed, and the interference between the sampling frequency and the data frequency creates the aliasing noise.The noise is reduced as the data period is longer. For example, a four-bar cycle means there are four samples per cycle. Because there are more samples, the sampled data are a better replica of the sine wave component. The replica is better yet for an eight-bar data component.The improved fidelity of the sampled data means the aliasing noise is reduced at longer and longer cycle periods.The rate of reduction is 6 dB per octave. My experience is that the systemic noise rarely is more than 10 dB below the level of cyclic information, so that we create two conditions for effective smoothing of aliasing noise:
1. It is difficult to use cycle periods shorter that two octaves below the Nyquist frequency.That is, an eight-bar cycle component has a quantization noise level 12 dB below the noise level at the Nyquist frequency. longer cycle components therefore have a systemic noise level that exceeds the aliasing noise level.
2. A smoothing filter should have sufficient selectivity to reduce aliasing noise below the systemic noise level. Since aliasing noise increases at the rate of 6 dB per octave above a selected filter cutoff frequency and since the SuperSmoother attenuation rate is 12 dB per octave, the Super- Smoother filter is an effective tool to virtually eliminate aliasing noise in the output signal.
What are DSL Discontinued Signal Line?
A lot of indicators are using signal lines in order to determine the trend (or some desired state of the indicator) easier. The idea of the signal line is easy : comparing the value to it's smoothed (slightly lagging) state, the idea of current momentum/state is made.
Discontinued signal line is inheriting that simple signal line idea and it is extending it : instead of having one signal line, more lines depending on the current value of the indicator.
"Signal" line is calculated the following way :
When a certain level is crossed into the desired direction, the EMA of that value is calculated for the desired signal line
When that level is crossed into the opposite direction, the previous "signal" line value is simply "inherited" and it becomes a kind of a level
This way it becomes a combination of signal lines and levels that are trying to combine both the good from both methods.
In simple terms, DSL uses the concept of a signal line and betters it by inheriting the previous signal line's value & makes it a level.
Included:
Bar coloring
Alerts
Signals
Loxx's Expanded Source Types
Basic Shannon Entropy & DerivativesThis script performs the basic Shannon entropy on the closing value of the stock. Additionally, it performs the trailing first and second derivatives of the Shannon Entropy, giving you more information about its movement.
You can change the "Source" to be whatever value you like.
ProbabilityLibrary "Probability"
erf(value) Complementary error function
Parameters:
value : float, value to test.
Returns: float
ierf_mcgiles(value) Computes the inverse error function using the Mc Giles method, sacrifices accuracy for speed.
Parameters:
value : float, -1.0 >= _value >= 1.0 range, value to test.
Returns: float
ierf_double(value) computes the inverse error function using the Newton method with double refinement.
Parameters:
value : float, -1. > _value > 1. range, _value to test.
Returns: float
ierf(value) computes the inverse error function using the Newton method.
Parameters:
value : float, -1. > _value > 1. range, _value to test.
Returns: float
complement(probability) probability that the event will not occur.
Parameters:
probability : float, 0 >=_p >= 1, probability of event.
Returns: float
entropy_gini_impurity_single(probability) Gini Inbalance or Gini index for a given probability.
Parameters:
probability : float, 0>=x>=1, probability of event.
Returns: float
entropy_gini_impurity(events) Gini Inbalance or Gini index for a series of events.
Parameters:
events : float , 0>=x>=1, array with event probability's.
Returns: float
entropy_shannon_single(probability) Entropy information value of the probability of a single event.
Parameters:
probability : float, 0>=x>=1, probability value.
Returns: float, value as bits of information.
entropy_shannon(events) Entropy information value of a distribution of events.
Parameters:
events : float , 0>=x>=1, array with probability's.
Returns: float
inequality_chebyshev(n_stdeviations) Calculates Chebyshev Inequality.
Parameters:
n_stdeviations : float, positive over or equal to 1.0
Returns: float
inequality_chebyshev_distribution(mean, std) Calculates Chebyshev Inequality.
Parameters:
mean : float, mean of a distribution
std : float, standard deviation of a distribution
Returns: float
inequality_chebyshev_sample(data_sample) Calculates Chebyshev Inequality for a array of values.
Parameters:
data_sample : float , array of numbers.
Returns: float
intersection_of_independent_events(events) Probability that all arguments will happen when neither outcome
is affected by the other (accepts 1 or more arguments)
Parameters:
events : float , 0 >= _p >= 1, list of event probabilities.
Returns: float
union_of_independent_events(events) Probability that either one of the arguments will happen when neither outcome
is affected by the other (accepts 1 or more arguments)
Parameters:
events : float , 0 >= _p >= 1, list of event probabilities.
Returns: float
mass_function(sample, n_bins) Probabilities for each bin in the range of sample.
Parameters:
sample : float , samples to pool probabilities.
n_bins : int, number of bins to split the range
@return float
cumulative_distribution_function(mean, stdev, value) Use the CDF to determine the probability that a random observation
that is taken from the population will be less than or equal to a certain value.
Or returns the area of probability for a known value in a normal distribution.
Parameters:
mean : float, samples to pool probabilities.
stdev : float, number of bins to split the range
value : float, limit at which to stop.
Returns: float
transition_matrix(distribution) Transition matrix for the suplied distribution.
Parameters:
distribution : float , array with probability distribution. ex:.
Returns: float
diffusion_matrix(transition_matrix, dimension, target_step) Probability of reaching target_state at target_step after starting from start_state
Parameters:
transition_matrix : float , "pseudo2d" probability transition matrix.
dimension : int, size of the matrix dimension.
target_step : number of steps to find probability.
Returns: float
state_at_time(transition_matrix, dimension, start_state, target_state, target_step) Probability of reaching target_state at target_step after starting from start_state
Parameters:
transition_matrix : float , "pseudo2d" probability transition matrix.
dimension : int, size of the matrix dimension.
start_state : state at which to start.
target_state : state to find probability.
target_step : number of steps to find probability.
Function - Entropy Gini Indexfunction to retrieve Gini Impurity / Gini Index.
reference:
- victorzhou.com
- en.wikipedia.org
Function - Shannon Entropyfunctions for shannon's entropy
reference:
- en.wiktionary.org
- machinelearningmastery.com
Bernoulli Process - Binary Entropy FunctionThis indicator is the Bernoulli Process or Wikipedia - Binary Entropy Function . Within Information Theory, Entropy is the measure of available information, here we use a binary variable 0 or 1 (P) and (1-P) (Bernoulli Function/Distribution), and combined with the Shannon Entropy measurement. As you can see below, it produces some wonderful charts and signals, using price, volume, or both summed together. The chart below shows you a couple of options and some critical details on the indicator. The best part about this is the simplicity, all of this information in a couple of lines of code.
Using the indicator:
The longer the Entropy measurement the more information you are capturing, so the analogy is, the shorter the signal, the less information you have available to utilize. You'll run into your Nyquist frequencies below a length of 5. I've found values between 9 and 22 work well to gather enough measurements. You also have an averaging summation that measures the weight or importance of the information over the summation period. This is also used for highlighting when you have an information signal above the 5% level (2 sigma) and then can be adjusted using the Percent Rank Variable. Finally, you can plot the individual signals (Price or Volume) to get another set of measurements to utilize. As can be seen in the chart below, the volume moves before price (but hopefully you already knew that)
At its core, this is taking the Binary Entropy measurement (using a Bernoulli distribution) for price and volume. I've subtracted the volume from the price so that you can use it like a MACD, also for shorter time frames (7, 9, 11) you can get divergences on the histogram. These divergences are primarily due to the weekly nature of the markets (5 days, 10 days is two weeks,...so 9 is measuring the last day of the past two weeks...so 11 is measuring the current day and the past two weeks).
Here are a couple of other examples, assuming you just love BTC, Stocks, or FOREX. I fashioned up a strategy to show the potential of the indicator.
BTC-Strategy
Stock-Strategy (#loveyouNFLX)
FOREX - (for everyone hopped up on 40X leverage)
Shannon Entropy V2Version 2, Shannon Entropy
This update includes both a deadband (Plotting Optional) and PercentRank Indicating.
Here is a unique way of looking at your price & volume information. Utilize the calculated value of "Shannon Entropy". This is a measure of "surprise" in the data, the larger the move or deviation from the most probable value, the higher the new information gain. What I think is so interesting about this value, is the smoothness that it displays the information without using moving averages. There is a lot of meat on this bone to be incorporated in other scripts.
H = -sum(prob(i) * log_base2(prob(i)))
I've included the typical way that I've been experimenting with this, which is the difference between the volume information and price information. I've included the option to turn either price or volume data off to see the Shannon Entropy value of either value. There are a ton of complex scripts out there trying to do what this calculation is doing in 3 lines. As with anything, there are no free lunches, so you can nicely see as you lower the lengths you'll quickly learn where your nyquist frequencies are at, you'll want to work at about double the noisy value at a minimum.
Using this script is based on "Information" and it highlights places that need your attention, either because there is a large amount of change (new information) or there is minimal new information (complacency, institutional movements). Buy and Sell points are up to the user, this is just showing you where you need to provide some attention.
You can use it with or without volume data, you can also isolate either the source and volume. Below are some options for printing:
It can also with BTC (better with volume data)
Big shoutout to yatrader2 for great Shannon Entropy discussions.
And to Picte/ for his interesting inspiration STOCH-HVP-picte
Shannon EntropyHere is a unique way of looking at your price & volume information. Utilize the calculated value of "Shannon Entropy". This is a measure of "surprise" in the data, the larger the move or deviation from the most probable value, the higher the new information gain. What I think is so interesting about this value, is the smoothness that it displays the information without using moving averages. There is a lot of meat on this bone to be incorporated in other scripts.
H = -sum(prob(i) * log_base2(prob(i)))
I've included the typical way that I've been experimenting with this, which is the difference between the volume information and price information. I've included the option to turn either price or volume data off to see the Shannon Entropy value of either value. There are a ton of complex scripts out there trying to do what this calculation is doing in 3 lines.
As with anything, there are no free lunches, so you can nicely see as you lower the lengths you'll quickly learn where your nyquist frequencies are at, you'll want to work at about double the noisy value at a minimum.