Analysing Cryptocurrency Using the Gemini API - Part V

By yyknosekai | yyknosekai | 25 Sep 2021

(This is Part V of an ongoing series on how to analyse cryptocurrency trends using Python and the Gemini API - read Part I, Part II, Part III & Part IV if you haven't yet!)

Enough conceptual talk! Not sure about you, but I'm itching myself for some real-world examples. From the past few posts in this series, you should already have a good (albeit) generic grasp about the potential and aim of technical indicators. In Part V of this series, we examine the simplest indicator, price value, and the simplest mathematical transformation, simple moving averages

Moving Averages (MA)

A moving average is the simplest price value technical indicator you could think of - we've already encountered one such moving average, the 20 SMA, in Part III of this series. Mathematically, the MA takes the total price observed over the past X days and averages it over the same X days. Think of it as a constantly updated average price whose aim is to smooth out the price data.

Why would we want to smooth out the price data? Well, especially in a volatile investment product like cryptocurrency, the daily price movements fluctuate wildly, and there's too much noise for the raw price data to be useful. What you want to be able to see is a smoothened price curve without any distractions.

Let's see how to calculate a MA in Python using BTC closing prices (following from the codes in previous posts):

## Generating a series of moving averages...
btc_prices['20 SMA'] = btc_prices.close.rolling(20).mean()
btc_prices['50 SMA'] = btc_prices.close.rolling(50).mean()
btc_prices['100 SMA'] = btc_prices.close.rolling(100).mean()

To visualise what a MA achieves, let's take the 20 SMA and superimpose it against BTC closing prices:

## Generating a BTC Price vs Time graph with a 20day moving average...
fig = go.Figure(layout=go.Layout(title=go.layout.Title(text='BTC Prices with 20 SMA')))
    title='BTC Prices with 20 SMA',
    yaxis_title="BTC Price",
    font=dict(size=18, color='black')
fig.add_trace(go.Scatter(x=btc_close_raw['time'], y=btc_close_raw['close'],
                        name='BTC Closing Price',
                        line=dict(color='black', width=4)))
fig.add_trace(go.Scatter(x=btc_close_raw['time'], y=btc_close_raw['20 SMA'],
                        name='20 SMA',
                        line=dict(color='black', width=2, dash='dash')))

Executing this should yield the chart below. Notice how the raw closing prices are noisy, with too much variation that distracts you from the main trend. In contrast, the 20 SMA smoothens out the trend enough for you to see how the price is actually moving on a daily basis.


Support? Resistance? Huh?

For those of you who've been to Reddit threads and seeing terms like support, resistance and are confused - well, a MA provides a simple way to explain these terms to you. Let's shade the chart above green where the BTC price is above the 20 SMA and red where the BTC Price is below the 20 SMA:


In the green regions, you can think of the MA as being a support level, where the MA is kind of a floor for the price to bounce off. If the price falls below the MA, we generally describe this as a dip - we then enter the red regions where the MA is now a resistance level where the price now needs to bust through a ceiling in order to be on an uptrend again.

Hang On - Should I 20 SMA, 50 SMA or 100 SMA?

A common question to ask is which MA one should use. Well, it really depends on the market, the product as well as your trading approach! For short-term day trades who are extremely concerned about short-term price action, generally, your risk tolerance is quite low and you want something that's price sensitive; so the minute it dips below the 20 SMA you would be triggered to sell.

But if you were a long-term investor who isn't quite concerned about short-term price action, you probably wouldn't be too bothered by a 20 SMA. You might very well gun for a 100 SMA instead. So it really depends on what your intentions are.

Are 20 SMAs and 50 SMAs Useless for Long Term Investors?

Well, again the answer is no! Even if you're a long term investor, you'd still be interested in finding good entry points to buy your coin at a reasonable price to maximise long term capital gains. Here's where the 20 SMA and 50 SMA can help - let's plot them both against the BTC price, and then we shade the intersections between the 20 SMA and 50 SMA (a) green when 20 SMA > 50 SMA and (b) red when 20 SMA > 50 SMA:


  • Where the 20 SMA is above the 50 SMA, the short-term price action is higher than the long-term price action. It is thus a clearer indication that BTC is on an uptrend (i.e. green region).
  • Where the 20 SMA crosses the 50 SMA into a red region, this is known as a death cross (look at the black May 16 tag) - that means you're entering a downtrend. 
  • Where the 20 SMA crosses the 50 SMA into a green region, this is known as a golden cross (look at the red Aug 8 tag) - that means you're entering an uptrend. 

This way of looking at 20 SMA (shorter-term MA) and 50 SMA (longer-term MA) is called a crossover approach:

  • If you believe in buying the dip, then you should only buy between the May 16 and Aug 8 period (red region) - and then stop buying in green regions. You could then sell during the green regions when you have made a profit, or continue to hold long term.
  • If you believe in buying into momentum, then you should only buy in the green regions - and then be prepared to sell when you approach the end of a green region.

Crossovers are thus a good way to determine entry and exit points for both long term investors and short-term traders.

In the next post, we will examine whether it's wiser to buy the dip or buying into momentum for BTC. See you there!

How do you rate this article?



Just a Secondary School Physics teacher in Singapore, interested in cryptocurrency.


I'm a Physics teacher living in Singapore. Interested in Python, data analytics and putting it to good use in analysing cryptocurrency trends and movements. Excited about the potential of blockchain technology and cryptocurrency, and glad to have an opportunity to share more on Publish0X!

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.