DEV Community

Cover image for Algo-Trading Journey: Randomness Causes Support Levels
ProgrammerMoney.com
ProgrammerMoney.com

Posted on • Updated on

Algo-Trading Journey: Randomness Causes Support Levels

algo-trading bot

(this is part 7 of the Algo-Trading Journey series)

PROOF: Support and resistance levels are not created by supply and demand. 😲 Instead, they emerge from randomness itself. 🀯πŸ’₯πŸ“ˆ

Patterns Are Deceiving You

Even in ancient Greece, people were able to precisely calculate when the Sun would rise and set.

However...

Their interpretation of WHY this happens was... questionable, LOL.

Apparently, the god Appollo was carrying the Sun in his chariot across the sky. (and was extremely punctual) πŸ˜‚πŸ˜†

CONCLUSION: you can be excellent in recognizing patterns, and still be absolutely terrible in explaining (and understanding) them.

BUT... if you read this entire article, you will learn something about the market barely anyone else understands... so stick around... this will be fun πŸ˜‰πŸŽ‰

Support & Resistance Levels

support and resistance levels

Above is a Bitcoin price chart spanning more than 3 years.

I drew two of the biggest support and resistance levels during this period.

Now, you may think there is no way this has anything to do with randomness.

Especially on such a long timeframe.

It is "clearly" the result of overall market supply and demand.

BUT...

You would be wrong 😲

How can I be so sure?

Because I can prove it to you using very (very) simple math.

And you can't argue with math... 1 + 1 is 2.

Market "Atoms"

Let's make the simplest market exchange imaginable:

  • The smallest possible price change can be Β±1
  • The smallest possible candle will be 4 price points (4 trades)

Now, let's see what this looks like in practice...

+1, -1, -1, +1, +1, +1, -1, +1, ...
Enter fullscreen mode Exit fullscreen mode

Now we can gather all these price changes into candles (group by 4)...

0, +2, 0, 0, -2, +4, 0, -2, ...
Enter fullscreen mode Exit fullscreen mode

Also, here is a list of ALL possible candle values for each of the 4 trades:

T1 T2 T3 T4 SUM
+1 +1 +1 +1 +4
+1 +1 +1 -1 +2
+1 +1 -1 +1 +2
+1 +1 -1 -1 0
+1 -1 +1 +1 +2
+1 -1 +1 -1 0
+1 -1 -1 +1 0
+1 -1 -1 -1 -2
-1 +1 +1 +1 +2
-1 +1 +1 -1 0
-1 +1 -1 +1 0
-1 +1 -1 -1 -2
-1 -1 +1 +1 0
-1 -1 +1 -1 -2
-1 -1 -1 +1 -2
-1 -1 -1 +1 -4

Notice anything interesting in the SUM column?

How about... no matter what you do, or what the price action does, you will NEVER get to values Β±1 or Β±3.

(there is 0% statistical chance)

SUM ODDS PROBABILITY
+4 1/16 6.25%
+2 4/16 25.00%
0 6/16 37.50%
-2 4/16 25.00%
-4 1/16 6.25%

The candle price just "jumps" to Β±2 or Β±4.

And then just "sits" there 37.5% of the time.

Some might call this support and resistance levels. 😲πŸ’₯🀯😱

Simulation

But don't take my word for it... let's do a simulation.

100 random points simulation

Here are the first 100 points in a random simulation.

Now, if we just presented this price data to some market "expert", he would "clearly" see:

  • market forces in action
  • strong support and resistance levels
  • fake breakout around points 45-55
  • "obvious" price collapse below the support level
  • price is now trending down and is expected to go down because "the market has spoken"

But let's not forget... there is no market here... just randomness.

So, let's see what happens in the next 900 points:

1000 random market points

It turns out our "market expert" was correct... the price really did continue to fall for the next 100 points or so.

After that, it tried to break out to the upside again. This time, slightly exceding the previous high.

But unfortunately it was another fakeout and it solidified the down trend with double top formation which is usually a strong bearish sign.

And, over the next 700 points, the price continued its downward long-term trend.

Also notice how the price respected the downward converging trend lines (which is another market indicator) and touched them several times.

And I could go on and on...

Markets Are Fractal

The absolute truth in this example is that there is no "market".

In fact, I could even give you the code that generated this:

auto rnd = Random(3);
int marketValue = 0;

string[] csvArr = [
    "candle, value",
    "0, 0"
];
for (int i = 1; i <= 1000; i++) {
    int randomNumber = [-1, 1].choice(rnd);
    marketValue += randomNumber;
    csvArr ~= 
        to!string(i) ~ 
        ", " ~ 
        to!string(marketValue);
}
saveData(csvArr);
Enter fullscreen mode Exit fullscreen mode

Despite all of this, our "market expert" would continue to see market forces in this chart:

  • he would see long-term demand decrease
  • the fight between buyers and sellers
  • people putting stop-loss orders at certain price levels
  • etc.

But there is nothing. This is nothing more than a display of a coin toss experiment.

A 50:50 chance of getting +1 or -1.

And this is why price charts look similar regardless of the timeframe you're looking at them.

And since randomness is fractal, so are the pricing charts.

And now, you'll never be fooled by "market experts" on things that a simple coin toss can explain. πŸ‘

What's Next?

I plan to post my progress here on dev.to because I find it fun... and I enjoy it.

If you want to join me on this journey, then I suggest you:

  • follow my profile for more updates
  • bookmark this article for future reference
  • and like this post, so more people can see it

Now let's go and conquer the market :)

Will

P.S. here are some cool resources:

1. Best Programming Language For Finance
2. (FREE) AI For Finance Tutorial
3. Starter Code For Bot Building

Top comments (0)