avatarMichael Whittle

Summarize

Strong Signs that Bitcoin may Recover

Technical analysis is indicating a cryptocurrency market recovery may happen soon

Licenced Image from Adobe Stock

I’ve spent the afternoon carrying out technical analysis on Bitcoin. The cryptocurrency and stock market has been in a slump this year, but could we be on the verge of recovery?

Interestingly enough, since writing this article I saw in the Bittrex Global’s newsletter that Bloomberg also is reporting, “Bitcoin on Track for October Gains in Defiance of a Tough Stretch of Months”. There are other analysts who also believe there will be an upward trend until December. So it’s doesn’t just seem to be my imagination or wishful thinking :)

I’ll share my analysis, and you can decide for yourself…

I use Python a lot for trading data analysis. I wrote an article previously to help those get set up. It has instructions on how to use Google Colab, which we will be using here. If you want to do this locally on your desktop, it will work fine as well.

Let’s first import the Python libraries we’ll need.

import time
import requests
import pandas as pd
import dateutil.parser as parser
import matplotlib.pyplot as plt
from datetime import datetime, timedelta

I disabled this Pandas warning, and it’s not applicable here.

pd.options.mode.chained_assignment = None

I created a helper function to retrieve the BTC-GBP market data from Coinbase Pro. You will provide the “market” and “granularity” in seconds. The “start” and “end” time in ISO 8601 format.

def get_data(market: str = "BTC-GBP", granularity: int = 86400, start: str = "", end: str = "") -> pd.DataFrame():
  resp = requests.get(f"https://api.pro.coinbase.com/products/{market}/candles?granularity={granularity}&start={start}&end={end}")
  df = pd.DataFrame.from_dict(resp.json())
  df.columns = [ "epoch", "open", "high", "close", "low", "volume" ]
  tsidx = pd.DatetimeIndex(pd.to_datetime(df["epoch"], unit="s"), dtype="datetime64[ns]")
  df.set_index(tsidx, inplace=True)
  df = df.drop(columns=["epoch"])
  df.index.names = ["date"]
  df.index = pd.to_datetime(df.index)
  df = df[[ "open", "high", "close", "low", "volume"]]
  return df.iloc[::-1]

As an example, you use it like this.

df_daily = get_data("BTC-GBP", 86400)
df_hourly = get_data("BTC-GBP", 3600)

Coinbase Pro only provides 300 points of historical data at a time. On the daily granularity/interval it would be 300 days, and on the hourly it would be 300 hours.

The first step in my analysis is to determine the SMA200 weekly data. This is a little tricky, as Coinbase Pro only provides up to daily.

The way I got around this is to create another helper function.

def daily_to_weekly(market: str) -> pd.DataFrame():
    date_start = ""
    date_end = ""
    df = pd.DataFrame()
    for x in range(0, 5):
        df1 = get_data(market, 86400, date_start, date_end) 
        df = pd.concat([df1, df])
    
        date_start = parser.parse(str(df1.index[0] - pd.Timedelta("300 days"))).isoformat()
        date_end = parser.parse(str(df1.index[0] - pd.Timedelta("1 day"))).isoformat()
        time.sleep(0.5)
    
    return df

This function will retrieve 1500 days of data by retrieving 300 chunks and consolidating it. The first step would be to retrieve the last 300 days of data. The function then retrieves the 300 days before that and concatenates it to a master list. This process is repeated until we have a full dataset. I included a sleep timer of 0.5 seconds to be courteous to Coinbase Pro and not swamp their API.

df_1500_days = daily_to_weekly("BTC-GBP")
df_1500_days
Screenshot by Author

You may wonder why I want 1500 days of data. The reason is I want to calculate the SMA200 weekly. In order to do this I need at least 200 weeks of data. There are 1400 days in 200 weeks, therefore 300 multiplied by 5 is 1500.

I now want to use the 1500 days of data and turn these into weeks. This took me a while to figure out, but I got it working.

df_1500_days.index.rename("ts", inplace=True)
df_1500_days["date"] = df_1500_days.index
df_1500_days["date"] = pd.to_datetime(df_1500_days["date"])
df_1500_days["day_of_week"] = df_1500_days["date"].dt.weekday
df_1500_days["1st_day_of_week"] = df_1500_days["date"] - df_1500_days["day_of_week"] * timedelta(days=1)
df_weekly = df_1500_days.copy()
df_weekly.drop(columns=["date"], inplace=True)
df_weekly.rename(columns={"1st_day_of_week": "date"}, inplace=True)
df_weekly = df_weekly[["date", "open", "high", "low", "close", "volume"]].groupby(["date"]).agg({"open": "first", "high": ["max"], "low": ["min"], "close": "last", "volume": ["sum"]})
df_weekly.columns = ["open", "high", "low", "close", "volume"]
df_weekly["sma200_weekly"] = df_weekly["close"].rolling(200, min_periods=1).mean()
df_weekly

This may look complicated, but I’ll try and explain it. The first step is to add a new column called “day_of_week” to the DataFrame. This is a numeric value representing the days of the week. I then calculated the first day of the week, “1st_day_of_week” and made sure it is Monday. I renamed the “1st_day_of_week” to “date” and then aggregated all the data within the same week. The result was stored in a new DataFrame called, “df_weekly”. I then applied the SMA200 to the weekly closing price and the result looks like this.

Screenshot by Author

215 weeks of weekly data with the SMA200 calculation. The SMA200 weekly is incredibly important and hardly anyone uses it. It shows a really long term trend over nearly 4 years. In Bitcoin’s case, this takes into account of all the crazy bull and bear markets over the years.

Visually it looks like this…

Screenshot by Author

You may have noticed that Bitcoin has been increasing the last few days. The reason why I think this is more significant than usual is because the price is hovering over the SMA200 weekly. This is a big deal… a massive deal. If the price breaks through properly, we could see the markets go crazy again and the good times will role. It could also go terribly wrong if the price drops below the SMA200 weekly. This could see a significant crash, worse than now. I’m a crypto enthusiast and optimist when it comes to Blockchain and cryptocurrencies, so I’m hopeful we are on the verge of good things.

The next key part of my analysis is to find out what the SMA200 daily looks like, and where it is in relation to the SMA200 weekly. If the SMA200 daily crosses above the SMA200 weekly, the markets usually go crazy.

I created myself another function.

def chain_data(market: str, granularity: int, iterations: int) -> None:
    date_start = ""
    date_end = ""
    for x in range(0, iterations):
        df1 = get_data("BTC-GBP", 86400, date_start, date_end)
        df2 = get_data("BTC-GBP", 3600, date_start, date_end)
        df2["sma200"] = df2["close"].rolling(200, min_periods=1).mean()
        df1["sma200"] = df1["close"].rolling(200, min_periods=1).mean()
        df1.loc[df1["close"] > df1["sma200"], "closegtsma200"] = True
        df1["closegtsma200"].fillna(False, inplace=True)
        df1.loc[df1["close"] < df1["sma200"], "closeltsma200"] = True
        df1["closeltsma200"].fillna(False, inplace=True)
        df1["closegtsma200co"] = df1.closegtsma200.ne(df1.closegtsma200.shift())
        df1.loc[df1["closegtsma200"] == False, "closegtsma200co"] = False
        df1["closeltsma200co"] = df1.closeltsma200.ne(df1.closeltsma200.shift())
        df1.loc[df1["closeltsma200"] == False, "closeltsma200co"] = False
        buysignals = df1[df1["closegtsma200co"] == True]
        sellsignals = df1[df1["closeltsma200co"] == True]
        fig, axs = plt.subplots(2, figsize=(20, 20))
        fig.suptitle(f"Bitcoin Daily - {str(df1.index[0])} to {str(df1.index[len(df1) - 1])}")
        axs[0].title.set_text("Price vs. SMA200")
        axs[0].plot(df1["close"], color="black", label="price")
        axs[0].plot(df1["sma200"], color="blue", label="sma200 daily")
        axs[0].plot(df2["sma200"], color="green", label="sma200 hourly")
        for idx in buysignals.index.tolist():
            axs[0].plot(
               idx,
               df1.loc[idx]["close"],
               "g*",
               markersize=12
            )
        for idx in sellsignals.index.tolist():
            axs[0].plot(
                idx,
                df1.loc[idx]["close"],
                "r*",
                markersize=12
            )
        axs[0].plot(df1.index[292], 19250, "o", ms=128, mec="y", mfc="none", mew=2)
        axs[0].tick_params(labelrotation=90)
        axs[0].legend()
        axs[1].title.set_text("Volume")
        axs[1].plot(df1["volume"], color="black", label="volume")
        axs[1].tick_params(labelrotation=90)
        axs[1].legend()
        date_start = parser.parse(str(df1.index[0] - pd.Timedelta("300   days"))).isoformat()
        date_end = parser.parse(str(df1.index[0] - pd.Timedelta("1 day"))).isoformat()
chain_data("BTC-GBP", 86400, 1)

There is a lot to unwrap here. I’ve covered many parts of this in various articles in my Medium publication, Trading Data Analysis. Feel free to check it out and follow the publication for further information.

Screenshot by Author

This graph is showing the last 300 days of the Bitcoin GBP market on Coinbase Pro. The black line is the closing price, the blue line is the SMA200 daily, and the green line is the SMA200 hourly.

Before we get into this, we first want to check the SMA200 weekly and SMA200 daily.

SMA200 weekly = 18089.84020
SMA200 daily = 30869.45000

The SMA200 daily is way above the SMA200 weekly, which is perfect. This is really important as well. If the SMA200 daily is below the SMA200 weekly, I would say it’s likely the crypto markets are done for.

If you look at the graph above you will see I’ve circled the closing price, SMA200 daily, and SMA200 hourly. If the SMA200 hourly crosses above the SMA200 daily, it’s very likely we will see the next crypto bull market. If Bitcoin recovers all the others will as well.

I suggest you keep an eye on that SMA200 hourly line. By eye it’s difficult to tell where it will intersect but it looks roughly £21,000 is where we could potentially see big things happen. Get your PyCryptoBot’s ready people… ;)

I hope you found this article interesting and useful. If you would like to be kept informed, please don’t forget to follow me and sign up to my email notifications.

Michael Whittle

Bitcoin
Investing
Market Analysis
Cryptocurrency
Python
Recommended from ReadMedium