# Bayesian BBSMA Oscillator

8301 vues
Sometime 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.
Notes de version:
This update changes how the oscillator is read. After tinkering with the indicator for a bit, I added a new probability called Prime Probability which is a combination of bot classifiers probabilities. A lower threshold is also added to define uncertainty or sideways movements. By adding these, we read the oscillator like below:

• Sideways or uncertainty is represented when the lower threshold area is colored gray, be very cautious when entering trades in this condition
• When prime probability changes from zero to a value above the lower threshold, a long signal is fired
• When breaking up probability changes from 100% to a value less than 100%, a long signal is fired
• When prime probability changes from a value above the lower threshold to zero, a short signal is fired
• When breaking down probability changes from 100% to a value less than 100%, a short signal is fired

All the long and short signals are strong signal provided that at the time the signal fires, probabilities tells us we're not in a sideways movement. Weaker signals although excluded from the indicator signals can be determined like below:

• When prime probability changes from zero or close to zero to a value within the lower threshold, this is a weak long signal
• When breaking up probability changes from a value above the lower threshold to a value less than the previous candle, this is a weak long signal
• When prime probability changes from a value within the lower threshold to zero or close to zero, this is a weak short signal
• When breaking down probability changes from a value above the lower threshold to a value less than the previous, this is a weak short signal

Play around with the lower threshold to find a suitable value. The default values in this indicator are derived from BTCUSDT in Binance at 1H timeframe.
Notes de version: This update adds Bill WIlliams indicators to confirm moves. It is disabled by default, more readings about Bill Williams indicators on my blog post below:

https://bango29.com/studying-chaos-and-learning-from-bill-williams/
Script open-source

Dans le plus pur esprit de TradingView, l'auteur de ce texte l'a publié en open-source, afin que les traders puissent le comprendre et le vérifier. Bravo à l'auteur ! Vous pouvez l'utiliser gratuitement, mais la réutilisation de ce code dans une publication est régie par les règles internes. Vous pouvez le mettre en favori pour l'utiliser sur un graphique.

Vous voulez utiliser ce script sur un graphique ?

## Commentaires

Répondre
Could you please share few examples how to take a trade based on it.

Thanks.
Répondre
bhavasarhemang
@bhavasarhemang, from his post (and read the recent updates to how some of this has changed)

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
Répondre
This publication will be featured in our "Best Scripts of The Month" selection. Thank you for your valuable contribution to the TradingView community, and congrats!
Répondre
PineCoders
@PineCoders, cool and thanks for the pick, cheers!
Répondre
what the blue line for?
Répondre
Wow, great!!

Gr, JD.
Répondre
wow.... this is very interesting one .... seems to be very useful in spotting possible reversals... Great work.... Thank you
Répondre
Hot Diggity, this is some amazing work. Thanks for your contribution mate.
Répondre
It gives good accurate signals. Thanks for your contribution!
Répondre