create account

Moving Average Crossover on Hive Price (A Brief Look) by kedi

View this thread on: hive.blogpeakd.comecency.com
· @kedi · (edited)
$12.91
Moving Average Crossover on Hive Price (A Brief Look)
When it comes to trading cryptocurrencies, one of the most popular technical indicators used by traders is the Moving Average (MA). The MA is a trend-following indicator that calculates the average price of an asset over a certain period of time. As you know, by plotting multiple MAs on a price chart, traders can identify trends and potential buying and selling opportunities.

*One specific trading strategy that uses the MA is the Moving Average Crossover (MAC) algorithm. This strategy is simple yet effective, and it can be used in any market, including the volatile cryptocurrency market. In this post, I will take a closer look at the MAC algorithm and how I used it with Hive price history.*


![pexelsannanekrashevich6801648.jpg](https://i.imgur.com/ApU2WQo.jpg)

<center><sup>Photo by Anna Nekrashevich from [Pexels](https://www.pexels.com/photo/magnifying-glass-on-top-of-document-6801648/)</sup></center>

---


To briefly mention for those who hear this concept for the first time, the MAC algorithm is a trend-following strategy that uses two MAs with different time periods. The most commonly used MAs in this strategy are the 50-day MA and the 200-day MA. When the shorter-term MA (50-day) crosses above the longer-term MA (200-day), it generates a buy signal, and when the shorter-term MA crosses below the longer-term MA, it generates a sell signal. This strategy is based on the assumption that when the price of an asset is above its MA (uptrend) and when the price is below its MA (downtrend). The MAC algorithm can identify both short-term and long-term trends in the market by using two MAs with different time periods.

## Using the MAC Algorithm on Hive Price History

We will need to plot two MAs on a price chart to use the MAC algorithm. There are many option (trading platforms, charting softwares etc.) to do this. Once we have plotted the MAs, we can look for crossovers between them. When the short-term MA crosses above the long-term MA, it's a bullish signal, and we should consider buying the asset. When the short-term MA crosses below the long-term MA, it's a bearish signal, and we should consider selling the asset according the model.

However, this is an assumption. It's important to note that the MAC algorithm can generate false signals in volatile markets. Mostly, it's recommended to use this strategy in conjunction with other technical indicators and trading tools to confirm the signals. But, in this post, I will only handle MAC algorithm here.

In the code below, I first use the [yfinance](https://pypi.org/project/yfinance/) library to download Hive price data for the last 6 months. After that, I calculated the 50-day and 200-day moving averages of the price data using the rolling() method. Also, I created a new column for buy and sell signals based on the MAC algorithm. So, if the 50-day MA is greater than the 200-day MA, I assign a value of 1.0 to the Signal column that indicating a buy signal. If the 50-day MA is less than the 200-day MA vice-versa.

At the first step I used matplotlib library to plot the buy and sell signals on a price chart. But I will use different option for better view. I first create a figure and set the y-axis label to 'Hive Price in USD'. Then plot the Hive price, 50-day MA, and 200-day MA on the chart. I also plot the buy signals as upward-pointing triangles and the sell signals as downward-pointing triangles.

```
import pandas as pd
import yfinance as yf

# Hive price data for the last 6 months
hive = yf.download("HIVE-USD", start="2022-08-19", end="2023-02-19")

# 50-day and 200-day MA
hive['MA50'] = hive['Close'].rolling(window=50).mean()
hive['MA200'] = hive['Close'].rolling(window=200).mean()

# New column for buy and sell signals
hive['Signal'] = 0.0
hive['Signal'] = np.where(hive['MA50'] > hive['MA200'], 1.0, 0.0)
hive['Position'] = hive['Signal'].diff()

# Buy and sell signals on a price chart
import matplotlib.pyplot as plt # Probably I will use different plotting library
fig = plt.figure()
ax1 = fig.add_subplot(111, ylabel='Hive Price in USD')
hive['Close'].plot(ax=ax1, color='r', lw=2.)
hive['MA50'].plot(ax=ax1, color='b', lw=2.)
hive['MA200'].plot(ax=ax1, color='g', lw=2.)

# Plot buy and sell signals
ax1.plot(hive.loc[hive.Position == 1.0].index, 
         hive.Close[hive.Position == 1.0],
         '^', markersize=10, color='m')
ax1.plot(hive.loc[hive.Position == -1.0].index, 
         hive.Close[hive.Position == -1.0],
         'v', markersize=10, color='k')
plt.show()
```

<center>
![download 2.png](https://i.imgur.com/kbNtnly.png) </center>

It looks like the price continues above the moving average. I leave it up to you to interpret the rest. In the code below I used the Plotly library to create an interactive chart that allows us to zoom in and out, hover over data points to see their values etc. 

Here first I created four different traces using the go.Scatter function: one for Hive price, one for the 50-day MA, one for the 200-day MA, and two for the buy and sell signals. The x and y parameters of each trace are set to the corresponding columns in the Hive dataframe. 

```
import plotly.graph_objs as go

# Traces for Hive price, 50-day MA, 200-day MA, buy signal and sell signal
trace_price = go.Scatter(
    x=hive.index,
    y=hive['Close'],
    name='Hive Price'
)

trace_ma50 = go.Scatter(
    x=hive.index,
    y=hive['MA50'],
    name='50-day MA'
)

trace_ma200 = go.Scatter(
    x=hive.index,
    y=hive['MA200'],
    name='200-day MA'
)

trace_buy = go.Scatter(
    x=hive[hive['Position'] == 1].index,
    y=hive['Close'][hive['Position'] == 1],
    name='Buy',
    mode='markers',
    marker=dict(
        symbol='triangle-up',
        size=10,
        color='green'
    )
)

trace_sell = go.Scatter(
    x=hive[hive['Position'] == -1].index,
    y=hive['Close'][hive['Position'] == -1],
    name='Sell',
    mode='markers',
    marker=dict(
        symbol='triangle-down',
        size=10,
        color='red'
    )
)

# Combine all traces into a data list
data = [trace_price, trace_ma50, trace_ma200, trace_buy, trace_sell]

# Layout for the chart
layout = go.Layout(
    title='Hive Price with Moving Average Crossover Signals',
    yaxis=dict(
        title='Hive Price in USD'
    )
)

# Fig object and plot the chart
fig = go.Figure(data=data, layout=layout)
fig.show()
```

<center>
![newplot.png](https://i.imgur.com/Caiw0vk.png) </center>


**Important Note: The code I provided does not include any predictions or forecasting for the Hive price. The code simply generates buy and sell signals based on the Moving Average Crossover algorithm and visualizes the resulting signals on a chart. It is not an investment advice.**

In fact, predicting future prices of cryptocurrencies is a complex and challenging task that requires more than just simple technical analysis. It involves a combination of factors such as market sentiment, news events, global economic conditions, more, more and more. I will be able to touch into various methods and models available for cryptocurrency price prediction, such as machine learning algorithms, time series analysis, and sentiment analyssis when I dive into them. Remember that predicting prices with high accuracy is still an active area of research and is subject to a high degree of uncertainty.

Thank you for stopping by,
Yaser

Posted Using [LeoFinance <sup>Beta</sup>](https://leofinance.io/@kedi/moving-average-crossover-on-hive-price-a-brief-look)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 56 others
👎  
properties (23)
authorkedi
permlinkmoving-average-crossover-on-hive-price-a-brief-look
categoryhive-167922
json_metadata{"app":"leofinance/0.2","format":"markdown","tags":["cryptocurrencies","algorithmic-trading","python","hive","tr","leofinance","broofofbrain"],"canonical_url":"https://leofinance.io/@kedi/moving-average-crossover-on-hive-price-a-brief-look","links":["https://www.pexels.com/photo/magnifying-glass-on-top-of-document-6801648/","https://pypi.org/project/yfinance/"],"image":["https://i.imgur.com/ApU2WQo.jpg","https://i.imgur.com/kbNtnly.png","https://i.imgur.com/Caiw0vk.png"],"users":["kedi"]}
created2023-02-19 12:39:15
last_update2023-02-19 13:14:30
depth0
children4
last_payout2023-02-26 12:39:15
cashout_time1969-12-31 23:59:59
total_payout_value6.471 HBD
curator_payout_value6.441 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7,470
author_reputation35,093,878,622,748
root_title"Moving Average Crossover on Hive Price (A Brief Look)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id120,920,050
net_rshares21,210,351,497,518
author_curate_reward""
vote details (121)
@hivebuzz ·
Congratulations @kedi! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

<table><tr><td><img src="https://images.hive.blog/60x70/http://hivebuzz.me/@kedi/upvotes.png?202302201227"></td><td>You distributed more than 14000 upvotes.<br>Your next target is to reach 15000 upvotes.</td></tr>
</table>

<sub>_You can view your badges on [your board](https://hivebuzz.me/@kedi) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



**Check out our last posts:**
<table><tr><td><a href="/hive-139531/@hivebuzz/proposal-2324"><img src="https://images.hive.blog/64x128/https://i.imgur.com/RNIZ1N6.png"></a></td><td><a href="/hive-139531/@hivebuzz/proposal-2324">The Hive Gamification Proposal</a></td></tr></table>
properties (22)
authorhivebuzz
permlinknotify-kedi-20230220t132206
categoryhive-167922
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2023-02-20 13:22:06
last_update2023-02-20 13:22:06
depth1
children0
last_payout2023-02-27 13:22:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length901
author_reputation369,213,166,930,843
root_title"Moving Average Crossover on Hive Price (A Brief Look)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id120,950,467
net_rshares0
@proofofbrian ·
Here is your Proof of Brian. I think you meant #ProofOfBrain
![Brian](https://upload.wikimedia.org/wikipedia/commons/thumb/f/f1/Professor_Brian_Cox_OBE_FRS.jpg/320px-Professor_Brian_Cox_OBE_FRS.jpg)
[Source](https://commons.wikimedia.org/wiki/File:Professor_Brian_Cox_OBE_FRS.jpg)
properties (22)
authorproofofbrian
permlinkre-moving-average-crossover-on-hive-price-a-brief-look-20230219t123920z
categoryhive-167922
json_metadata"{"app": "beem/0.24.26"}"
created2023-02-19 12:39:21
last_update2023-02-19 12:39:21
depth1
children0
last_payout2023-02-26 12:39:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length280
author_reputation707,015,257,900
root_title"Moving Average Crossover on Hive Price (A Brief Look)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id120,920,051
net_rshares0
@trliste ·
@tipu curate 5
properties (22)
authortrliste
permlinkre-kedi-rqcbs4
categoryhive-167922
json_metadata{"tags":["hive-167922"],"app":"peakd/2023.2.2"}
created2023-02-19 18:38:36
last_update2023-02-19 18:38:36
depth1
children1
last_payout2023-02-26 18:38:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length14
author_reputation67,270,310,991,216
root_title"Moving Average Crossover on Hive Price (A Brief Look)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id120,928,268
net_rshares0
@tipu ·
<a href="https://tipu.online/hive_curator?trliste" target="_blank">Upvoted  &#128076;</a> (Mana: 0/41) <a href="https://peakd.com/hive/@reward.app/reward-app-quick-guide-updated" target="_blank">Liquid rewards</a>.
properties (22)
authortipu
permlinkre-re-kedi-rqcbs4-20230219t183842z
categoryhive-167922
json_metadata"{"app": "beem/0.24.26"}"
created2023-02-19 18:38:42
last_update2023-02-19 18:38:42
depth2
children0
last_payout2023-02-26 18:38:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length214
author_reputation55,909,940,232,228
root_title"Moving Average Crossover on Hive Price (A Brief Look)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id120,928,272
net_rshares0