Bayesian Trend Indicator [ChartPrime]Bayesian Trend Indicator
Overview:
In probability theory and statistics, Bayes' theorem (alternatively Bayes' law or Bayes' rule), named after Thomas Bayes, describes the probability of an event, based on prior knowledge of conditions that might be related to the event.
The "Bayesian Trend Indicator" is a sophisticated technical analysis tool designed to assess the direction of price trends in financial markets. It combines the principles of Bayesian probability theory with moving average analysis to provide traders with a comprehensive understanding of market sentiment and potential trend reversals.
At its core, the indicator utilizes multiple moving averages, including the Exponential Moving Average (EMA), Simple Moving Average (SMA), Double Exponential Moving Average (DEMA), and Volume Weighted Moving Average (VWMA) . These moving averages are calculated based on user-defined parameters such as length and gap length, allowing traders to customize the indicator to suit their trading strategies and preferences.
The indicator begins by calculating the trend for both fast and slow moving averages using a Smoothed Gradient Signal Function. This function assigns a numerical value to each data point based on its relationship with historical data, indicating the strength and direction of the trend.
// Smoothed Gradient Signal Function
sig(float src, gap)=>
ta.ema(source >= src ? 1 :
source >= src ? 0.9 :
source >= src ? 0.8 :
source >= src ? 0.7 :
source >= src ? 0.6 :
source >= src ? 0.5 :
source >= src ? 0.4 :
source >= src ? 0.3 :
source >= src ? 0.2 :
source >= src ? 0.1 :
0, 4)
Next, the indicator calculates prior probabilities using the trend information from the slow moving averages and likelihood probabilities using the trend information from the fast moving averages . These probabilities represent the likelihood of an uptrend or downtrend based on historical data.
// Define prior probabilities using moving averages
prior_up = (ema_trend + sma_trend + dema_trend + vwma_trend) / 4
prior_down = 1 - prior_up
// Define likelihoods using faster moving averages
likelihood_up = (ema_trend_fast + sma_trend_fast + dema_trend_fast + vwma_trend_fast) / 4
likelihood_down = 1 - likelihood_up
Using Bayes' theorem , the indicator then combines the prior and likelihood probabilities to calculate posterior probabilities, which reflect the updated probability of an uptrend or downtrend given the current market conditions. These posterior probabilities serve as a key signal for traders, informing them about the prevailing market sentiment and potential trend reversals.
// Calculate posterior probabilities using Bayes' theorem
posterior_up = prior_up * likelihood_up
/
(prior_up * likelihood_up + prior_down * likelihood_down)
Key Features:
◆ The trend direction:
To visually represent the trend direction , the indicator colors the bars on the chart based on the posterior probabilities. Bars are colored green to indicate an uptrend when the posterior probability is greater than 0.5 (>50%), while bars are colored red to indicate a downtrend when the posterior probability is less than 0.5 (<50%).
◆ Dashboard on the chart
Additionally, the indicator displays a dashboard on the chart , providing traders with detailed information about the probability of an uptrend , as well as the trends for each type of moving average. This dashboard serves as a valuable reference for traders to monitor trend strength and make informed trading decisions.
◆ Probability labels and signals:
Furthermore, the indicator includes probability labels and signals , which are displayed near the corresponding bars on the chart. These labels indicate the posterior probability of a trend, while small diamonds above or below bars indicate crossover or crossunder events when the posterior probability crosses the 0.5 threshold (50%).
The posterior probability of a trend
Crossover or Crossunder events
◆ User Inputs
Source:
Description: Defines the price source for the indicator's calculations. Users can select between different price values like close, open, high, low, etc.
MA's Length:
Description: Sets the length for the moving averages used in the trend calculations. A larger length will smooth out the moving averages, making the indicator less sensitive to short-term fluctuations.
Gap Length Between Fast and Slow MA's:
Description: Determines the difference in lengths between the slow and fast moving averages. A higher gap length will increase the difference, potentially identifying stronger trend signals.
Gap Signals:
Description: Defines the gap used for the smoothed gradient signal function. This parameter affects the sensitivity of the trend signals by setting the number of bars used in the signal calculations.
In summary, the "Bayesian Trend Indicator" is a powerful tool that leverages Bayesian probability theory and moving average analysis to help traders identify trend direction, assess market sentiment, and make informed trading decisions in various financial markets.
Bayesian
Probability Oscillator (Expo)█ Overview
The Probability Oscillator uses a Bayesian approach to measure the probability of a price movement and trend continuation. This approach considers the prior probability of a price movement and the current market conditions to identify trends, sentiment, momentum, and retracements.
█ How does the indicator work?
The Probability Oscillator is based on the idea of Bayesian probability , which is a way of using existing data to make predictions about the likelihood of an event occurring. This indicator uses the Bayesian probability model to analyze past trading activity and calculate the probability of a trend continuing. This function also considers the prior probability of a price movement and the current market conditions to analyze the likelihood of a retracement.
█ How to use
Investors can use this indicator to measure the market sentiment and the strength/direction of a trend. It does also give insights into momentum moves and retracements.
█ Indicator Customization
The user can change the trend approaches and input source as well as adjust the overbought and oversold areas to make the calculation more sensitive to retracements.
The user can change the sensitivity of the momentum function to adjust it only to identify the most significant momentum moves.
-----------------
Disclaimer
The information contained in my Scripts/Indicators/Ideas/Algos/Systems does not constitute financial advice or a solicitation to buy or sell any securities of any type. I will not accept liability for any loss or damage, including without limitation any loss of profit, which may arise directly or indirectly from the use of or reliance on such information.
All investments involve risk, and the past performance of a security, industry, sector, market, financial product, trading strategy, backtest, or individual's trading does not guarantee future results or returns. Investors are fully responsible for any investment decisions they make. Such decisions should be based solely on an evaluation of their financial circumstances, investment objectives, risk tolerance, and liquidity needs.
My Scripts/Indicators/Ideas/Algos/Systems are only for educational purposes!
Bayesian BBSMA + nQQE Oscillator + Bank funds (whales detector)Three trend indicators in one. Fork of Gunslinger2005 indicator, with a fix to display the nQQE oscillator correctly and clearly, and converted to pinescript v5 (allowing to set a different timeframe and gaps).
How to use: Essentially, nQQE is a long term trend indicator which is more adequate in daily or weekly timeframe to indicate the current market cycle. Banker Fund seems better suited to indicate current local trend, although it is sensitive to relief rallies. Bayesian BBSMA is an awesome tool to visualize the buildup in bullish/bearish sentiment, and when it is more likely to get released, however it is unreliable, so it needs to be combined with other indicators.
Please show the original indicators some love:
Bayesian BBSMA:
nQQE:
L3 Banker Fund Flow Trend:
Originally mixed together by Gunslinger2005:
The Bayesian Q OscillatorFirst of all the biggest thanks to @tista and @KivancOzbilgic for publishing their open source public indicators Bayesian BBSMA + nQQE Oscillator. And a mighty round of applause for @MarkBench for once again being my superhero pinescript guy that puts these awesome combination Ideas and ES stradegies in my head together. Now let me go ahead and explain what we have here.
I am gonna call it the Bayesian Q Oscillator I suppose. The goal of the script is to solve an issue both indicators on their own suffer from. QQE signals are not new and often the problem has always been false signals for them. They are good for scalping but the difference between a quality move and a small to nearly nonexistent move following a signal is not so clear. Kivanc made his normalized version to help reduce this problem by adding colors to his histogram type verision that would essentially represent if price was a trending move or in a ranging structure. As you can see I have kept this Idea but instead opted for lines as the oscillator. two yellow line (default color) is a ranging sideways area and when there is red or green it is trending up or down. I wanted to take this to the next level with combining the Bayesian probability oscillator that tista put together.
The Bayesian indicator is the opposite for its issue as it is a probability indicator that shows which candle or price movement is more likely to come next. Red rising means possibly down move soon and green means up soon. I will not go into the complex details of this indicator but will suggest others take a look at his and others to understand the idea behind them. The point I am driving at is that it show probabilities or likelyhood without the most effecient signal device to match it. This original was line form and now it is background filled colors.
The idea. is that you can potentially get some stronger and more accurate reversal signals with these two paired together. when you see a sell signal or cross with the towering or rising red... maybe it is a good jump potentially. The same for green. At the same time it is a double added filter effect from just having yellow represent it is ranging... but now if you get a buy signal (example) and have yellow lines (example) along wi5h a red rising or mountain color background... it not only is an indication of ranging, but also that there is potentially even a counter move coming based on the probabilities. Also if you get into a good trade and see dual yellow qqe crosses with no color represented by the bayesian background... it is possible it might only be noise.
I have found them to work decently in the 1 hour timframe. Let me know your experience.
I hope everyone takes a look at the originals to understand them. Full credit goes to those guys for this to be here. Let me know how it is working out for you.
Here are the original links.
bayesian
Normalized QQE
[Max] Volume Entropy Divergence FilteredAn indicator that represent in 3 line my Volume Entropy Divergence Heatmap indicator.
I've use a very basic sum with some weights like this : Long therm > Mid therm > short Therm, But short and mid therm can still have influence.
Some people did request this indicator to be able to use the heatmap in there indicators with the new tradingview link function. There still a problem that will be the subject of a future update, when the divergence is to high it's often mean that instead of a divergence, we have a continuation or a parabolic.
This indicator still also need a location checker to try to don't short the bottom.
There is 3 lines, 2 are the sum of the negative/positive divergences.
The third one is the result off a karman volatility filter, with differents weigths for each line off the heatmap, it can easily used to find reversals.
You have some options to play with the volatility filter, the defaults settings are the ones I think is the best.
This script will still private for the same reasons raised in the original heatmap.
My policy : If you can provide me nice updates, I will give you the source code, if within 3 month I don't use it anymore it will pass in public.
If you have any improvement idears I will be please to ear them.
Have a nice day !
Max
[Max] Volume Entropy Divergence HeatmapA divergence between volume and price indicator, based on custom filter function.
Each lines represent a length on wich the divergence is calculated. It goes to 60 len a the base to 2000 at the high. ( You have to decrease the timeframe if your looking on a new chart).
Colors represent a level of the oscillator who is calculated for each lengths.
What can you find, reversals, confirmation of continuation, divergences between volume and price,.. (if you find other usages I will be happy to hear it and share the code).
I recommand to be attentive to lower timeframes and confirm with higher ones and be attentive between different kind of clouds there is.
You are in charge to figure out how to use it, if you have some doubts on something you can DM me but I will not teach my way to use it.
It provide for me nice transformations, nice enough to share this indicator in private.
Big thanks to @midtownsk8rguy for the heatmap color function.
Have a nice daytrading all !
Bayesian BBSMA OscillatorSometime ago (very long ago), one of my tinkering project was to do a spam or ham classification type app to filter news I'd wanna read. So I built myself a Naive Bayes Classifier to feed me my relevant articles. It worked great, I can cut through the noise.
The hassle was I needed to manually train it to understand what I wanna read. I trained it using 50 articles and to my surprise, it's enough.
Complexity Theory
I've been reading a book called The Road to Ruin by Jim Rickards. He described how he got to his conclusion of how the stock market works by using Complexity Theory. Bill Williams would agree. Jim tells us that by using just enough data, we calculate the probability of an event to occur. We can't say for sure when but we know it's coming. This was my light bulb moment.
While Jim talks much about Bayesian Inference in which a probability of an event can always be updated as more evidence comes to light, I had my eyes set on binary probabilities of when prices are going up and down.
Assumptions
These are my assumptions:
Prices breaking up a Bollinger basis line will have fuel to go up even higher
Prices will go down when prices have broken up a Bollinger upper band
Scalping is the main method so we should use a lower period Moving Average (MA)
When prices are above MA, it's likelier a correction to the downside is imminent
When prices are below MA, it's likelier a correction to the upside is imminent
Optimize parameters for 1 hour timeframe which will give us time to react while still having more opportunities to trade
Building Blocks
Jim Rickards started with limited data (events) while in technical trading, data are plentiful. I decided to classify 2 events which are:
Next candles would be breaking up
Next candles would be breaking down
Key facts:
We won't know for sure when prices are going to break
We won't know for sure how much the prices movements are going to be
Formulas
Breaking up:
Pr(Up|Indicator) = Pr(Indicator|Up) * Pr(Up) / Pr(Indicator|Up) * Pr(Up) + Pr(Indicator|Down) * Pr(Down)
Breaking down:
Pr(Down|Indicator) = Pr(Indicator|Down) * Pr(Down) / Pr(Indicator|Down) * Pr(Down) + Pr(Indicator|Up) * Pr(Up)
Reading The Oscillator
Green is the probability of prices breaking up
Red is the probability of prices breaking down
When either green or red is flatlining ceiling, immediately on the next candle when the probability decreases go short or long based on which direction you're observing - Strong Signal
When either green or red is flatlining ceiling, take no action while it's ceiled
Usually when either green or red is flatlining bottom, the next candle when the probability increases, immediately take a short long position based on the direction you're observing - Weak Signal
When either green or red is flatlining bottom, take no action while it's bottomed
Alerts
Use Once per Bar option when generating alerts.