tista

Bayesian BBSMA Oscillator

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.
Release Notes:
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.
Release Notes: 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/
Remove from Favorite Scripts Add to Favorite Scripts

Comments

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

Thanks.
+14 Reply
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!
+2 Reply
tista PineCoders
@PineCoders, cool and thanks for the pick, cheers!
Reply
what the blue line for?
+1 Reply
Wow, great!!

Gr, JD.
+1 Reply
Thanks for your work on this!

"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"

does this mean - red decreasing off of ceiling = short and green decreasing off of ceiling = long?
Reply
Very good!!!!Thank you!!
Reply
To me, it just seems like a mediocre bollinger bands strategy. I have tried to implement this idea in some strategies but am completely unable to find success unless you know in advance an asset will be ranging between certain prices, in which case there are dozens of ways to profit off of that information such as drawing more static forms of support and resistance such as channel lines.

I think it's a good contribution because it demonstrates the extent of what's possible with Pine Script but not easy to generate a profit implementing this. Of course, I would be extremely glad to be proven wrong in this case!
Reply
Never thought about this idea. Excellent work of you, congratulations ! Do you have this script available also in Easy Language for TradeStation?
Reply
Wow this is very well done! Thank you for sharing
Reply
Home Stock Screener Forex Screener Crypto Screener Economic Calendar How It Works Chart Features Pricing Refer a friend House Rules Help Center Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Blog & News Twitter
Profile Profile Settings Account and Billing Referred friends Coins My Support Tickets Help Center Ideas Published Followers Following Private Messages Chat Sign Out