# Bitcoin Price Technical Analysis with Python Programming

This tutorial will take a look at Bitcoin to try and decide the trend of Bitcoin and if now would be a good time to possibly invest. To do so, I will use a simple simple technical analysis using 50 Day Moving Averages. First, lets be clear there are no 100% sure way to enter the market risk free or to predict future prices. If there was everyone would just use the same model and never been wrong or lose money and that is certainly not the case.

For this tutorial I will use the 50 Day High Moving Average , 50 Day Low Moving Average and 50 Day Moving Average for the Adjusted Closing price of Bitcoin. A 50 Day Moving Average is the sum total of the the 50 days Closing price divided by 50. This method is used to gauge what the average price is for that time frame. The same principle will be used for the other averages.

##### Ex .

Close Day 1+Close Day 2 + Close Day 3 …..Close Day 50 / 50 = X

Let load in the data and import the libraries. Here are the libraries used Matplotlib , Datetime , pandas and pandas_datareader

Here we are using pandas datareader to get the Bitcoin price data. The time frame ranges from January 1 , 2015 to present day.

```import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd

style.use('ggplot')

# Time Frame
start = dt.datetime(2015, 1, 1)
end = dt.datetime.now()

df = web.DataReader("BTC-USD", 'yahoo', start, end)
df.reset_index(inplace=True)
df.set_index("Date", inplace=True)
```
##### Creating Moving Averages

Here the moving averages are being created,so this is really the meat of this tutorial. Note : rolling() is used to get the first 50 consecutive days in a period the get the next after than and so on until its out of data.

```# Closing Price
# Mean High for the last 50 days
ma_high = df['High'].rolling(window=50,min_periods=0).mean()
# Mean Low for last 50 days
ma_low = df['Low'].rolling(window=50,min_periods=0).mean()
# 50 day Moving Average

```
##### Creating the Plot
```# plotting the last 550 days
plt.plot(price.tail(550))
# setting 50 MA to blue color
plt.plot(ma, color= "b")
# High MA color green
plt.plot(ma_high, color= "g")
# Low MA color yellow
plt.plot(ma_low,  color="y")
plt.legend()
# Showing the plot
plt.show()
```

Okay, so lets take a look at the output. The red line is the Price, Yellow Line 50 Day Low MA , Green Line is High 50 Day MA and the blue line is the 50 Day Closing Price MA.

Notes that the price is below the 50 Day Low MA. This is interesting, it could symbolize a possible entry point. Notice that if you look at the other areas where the price goes below the Yellow Line (50 Low MA) there is a large drop in the price. But once the price breaks above the Green Line (50 Day High MA) there are massive spikes in price. This could be a good potential strategy for trading Bitcoin. However, keep in mind this would be a long term style of trading or investing because it might take a few months for the price to correct into buying and selling points.

As a reminder, this is not a good investment method it is simply a fun way to use Python. This is a very broad and simple form of technical analysis so don’t just stop here.Play around with the code and the libraries above, you can do some really neat stuff with them.

##### Full Code
```import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd

style.use('ggplot')

# Time Frame
start = dt.datetime(2015, 1, 1)
end = dt.datetime.now()

df = web.DataReader("BTC-USD", 'yahoo', start, end)
df.reset_index(inplace=True)
df.set_index("Date", inplace=True)

# Closing Price
# Mean High for the last 50 days
mv_high = df['High'].rolling(window=50,min_periods=0).mean()
# Mean Low for last 50 days
mv_low = df['Low'].rolling(window=50,min_periods=0).mean()
# 50 day Moving Average