My approach
# avg_gain - the average price gain over a period of time before present
# avg_loss - the average price loss over a period of time before present
RSvalue = (avg_gain / avg_loss) # relative strength
RSI = 100 - (100 / (1 + RSvalue)) # relative strenght index
Now that I had most of the foundational knowledge for the subject, and what I wanted to use to actually make my buy/sell decisions on, I could move on. Though it didn't take long until I hit another very obvious brick wall. How was I actually going to get any market information or buy and sell anything for that matter? So I took to the internet again, but this time, looking for an API that I could use (needed to be a Robinhood API since that is what I was using for my trading) to bridge the gap between my bot and the actual markets. Thas how I stumbled across the API called Robin Stocks. This API allowed me to access Robinhood, more specifically my own Robinhood account, in my code and interact with it in several different ways. This included: loging into my account, accessing historics (past information) on a stock or crypto and buy/selling both stocks and cryptos. Here is a little snippit of what using Robin Stocks might look like:
from robin_stocks import robinhood
TICKER = "DOGE" # the ticker that we want to get info on
SPAN = 'month' # how far back we are looking
INTERVAL = 'hour' # how often we sample past info while going back in time
# login to your own robinhood account (checkout robin stocks for details on the mfa_code)
robinhood.authentication.login(EMAIL, PASSWORD, mfa_code=CODE)
# historics contains 744 elements with each one being a collection of data from a specific point in time
# the robinhood function, in this case, will get info from every hour in the past month
Historics = robinhood.get_crypto_historicals(TICKER.upper(), interval=INTERVAL, span=SPAN)
print(Historics[0])
# output
# {'begins_at': '2021-12-03T02:00:00Z', 'open_price': '0.209573', 'close_price': '0.207278', 'high_price': '0.210370', 'low_price': '0.206136', 'volume': 0, 'session': 'reg', 'interpolated': False, 'symbol': 'DOGEUSD'}
Once I got familiar with the API and the functions that I knew that I would be needing I was able to start on the actual bot part. The first thing I wanted to do was put to use the RSI research I did. Putting together a lot of different helper functions to make my own little wrapper around the API and using those to make RSI calculations in a larger scale, but still using the formula above. Once I was able to produce a RSI for every point in time in my historics I was able to use the MatPlotLib library to make a line chart so the info was easier to see. Now with all the ground work layed out I needed to decide what all I wanted my bot to be able to do. The list I came up with looked something like:
1. All variables and paramaters need to be adjustable to cater to different cryptos and stocks
2. The Bot would check to see if it wants to purchase over a certain period determined by the user
3. The Bot would make its buy/sell decision based on the current RSI value of the ticker
4. There needs to be some kind of info shown to the user on the fly so at a glance they could tell what's happened
5. A summary of each program lifetime would get saved off to a file to keep a record for future look back
6. Some kind of manual buy/sell mode in case the user wants to manual take action
I was able to impliment everything that I had on my list for the bot. Full disclosure, however, making decisions souly based on a RSI can only be so accurate. This bot is by no means perfect and I would not recommend using it when large quantities of currency is in question. One other feature I decided to add was a way to check the accuracy of the algorithms used. I check a lot of different stats that the program comes up with. One way of checking these things is by counting the number of True/False Positives/Negatives and calculating the accuracy of the predictions. Jumping over a lot of the specifics the end results come out to be very good a majority of the time and not so good some of the other times. This is because I am only taking the RSI into account, and while this can yeild some good results a good portion of the time it is not perfect. This is why I wanted all the variables and parameters to be adjustable, because what might be a good span, interval and lookback period (inspect code on github for more details) for one ticker might not be good at all for another. This way with all the tools provided a user can find a set of parameters that work best for the ticker they are trading.