It's official! Hive is a first class citizen of the internet.
We often go to the internet to find information we need: be it for educational, entertainment, business, or other purposes. In other words we try to find solutions for various problems. This is one of the greatest achievements of the internet and various platforms on the internet. It is a place where people can share their experiences and solutions they came up with for various problems.
While solutions on the internet are not limited to the topics of technology and programming, programmers of all levels do use this methodology in problem solving a lot. Having an error with a script? Google it or go straight to stackoverflow.
A couple of weeks ago, a stranger contacted me on discord saying:
- Hi, I found your post about EMA calculation. Something is not working right. Can you help?
The stranger was referring to a post I wrote last year - Simple Moving Average (SMA) vs Exponential Moving Average (EMA) in Pine Script & Python
In there past I did have experiences where people told me that they found one of my older posts useful. But mainly they were Hive users and friends. Just recently @pinkfloyd878 left me the following comment:
Not exactly the info I was looking for at this moment, but this is very good information.
Just a heads up.... your post is #1 result for "custom+json+hive+blockchain" on Google... It was for me.
#1 search result for Hive Blockchain's awesome Custom Json feature in google search? That is amazing. However, ordinary people and especially those don't even know about Hive would be searching these topics.
I only know one person on Hive who uses PineScript, and I talk to that person regularly. So, this stranger cannot be a Hive user, I thought. And I had to ask:
Me: Do you use Hive or Leofinance?
The Stranger: uhm, none of those
The stranger probably didn't even know what I was talking about, although they were able to look up my discord server in the Hive profile to contact me there.
People find information online all the time. What's the big deal?" - you may ask. Big deal to me is that someone was looking for a solution to a problem and they found it on Hive. I don't even consider myself a blogger. I just write about random things from time to time that I have no clue about half of the time. But there are may talented authors on Hive who share valuable knowledge, experiences and entertainment content. Random strangers of the internet finding content produced on Hive is a win and sign of success for the network.
The problem stranger was trying to find a solution for was calculating EMA in python and converting a PineScript code into a python code. I have used this function in many of my scripts. I have done proper testing in the past and everything seemed to work fine. Now I was curious, not only because I wanted to help the stranger, but also to make sure my old scripts were working as intended.
Last couple of months I spent traveling and was away from a computer for the most part and have used any of my codes. When I tried to run one of them, right away I started getting error and script would stop executing. I tried another code, same thing. And then another. Same thing. Errors everywhere. Finally I figured out what these error meant and was able to fix it. It turned out yfinance module wasn't working properly and had to be updated. If you use yfinance make sure to update it.
I was ready to test the EMA function. Opened up Tradingview bitcoin chart and compared with the results in python. Everything looked great. Then I tried stranger's pinescript code and compared with python results again. There was a big discrepancy in what EMA results were shown in pinescript vs python code results.
I kept reading the codes line by line over and over again. There are no logical errors. Everything should work. I spent hours and hours, and couldn't figure out. It was getting so frustrating. I started a new script file and wrote new python code to see maybe that would avoid any previous logical errors. Still results are not matching the ones in pinescript. Rewrote pinescript code. Still didn't help.
I was done. I gave up. Shut down the computer and walked away.
Shortly after, out of nowhere the solution came to my mind. I had to test it right away. I turned on the computer, made changed to the code. It worked. Well, sort of.
The problem was in all of my codes I was using data from yahoo finance and would take historical price data for at least a year. The strangers API was only getting data for last couple months in python but many more candles were being used in pinescript to calculate the EMA. Getting more data points brought the EMA values to almost identical, but not exactly. I suggested the stranger to rewrite their code to get more data points and see if that would work. The following day stranger responded:
thanks again, it worked!
had to do pagination to get more data, but it worked out
It was great learning experience. Now I know that my scripts may work now, but there is flaw in them. I will need to research more accurate ways of calculating EMA in python. If you have any suggestions feels free to share in the comments.