I wrote an automated trading bot within 3 months, here is how you can do it too

Kuegi
3 min readNov 20, 2021

They always say that the most important thing for an automated trading bot is a profitable strategy. And they are right, without a successful strategy, everything else is worthless. But just because you got an automatable strategy doesn’t mean that you will make it. If you ever wondered how such a bot evolves, search no more! Just read on.

After my initial period of gambling on bitcoin exchanges (Yes, gambling. Whatever I did there, it wasn’t trading in the beginning. You can read more about it here) I came up with a simple strategy. It evolved from just watching the chart move. In a nutshell: If the price forms a triangle: enter a trade on the break of the triangle and trail the stop. Easy as that.
And then the hard work started.

First I developed a TradingView indicator to help me visually to stick to the plan. The indicator prints the levels where to enter the trade. After that I put this indicator into a TradingView strategy to backtest it. If you never built a tradingbot and have no framework whatsoever, this is a perfect opportunity to get quick results. Yes, PineScript has a lot of limitations, but you can still do a lot and you don’t have to worry about management of chartdata and all that. Just define the pure logic, analyze it visually and let it run in a backtest.

Once you got that, you can move on to a “real” (Sorry PineScript) programming language. I used Python, just because it’s super easy to use, runs nearly everywhere and you have heaps of sample implementations for exchange APIs. Now you have to decide if you want to use any framework (for technical analysis, handling data, connecting to APIs etc.) or not. I decided that I want to know *exactly* what this thing is doing and have the freedom to make it do whatever I want. So I ignored basically all frameworks (except for the API-connectors provided by some exchanges themself) and build it from scratch.

Of course this was only possible because my strategy doesn’t use any fancy indicators. It’s usually not too hard to implement them yourself, and I did it for a few. But if you use a combination of 100 indicators, you might wanna use a TA-lib that already has them. And you might wanna rethink that strategy…

Now to the good stuff: how to code the bot. Back then I traded on Bitmex, and they offered an open source example-bot that used their API. And since I never did anything like that from scratch (or anything in Python), I started there. I soon realized that a production-ready bot needs far more than just logic and connection to an API. So my framework evolved from that to the final stage it is today.

You are lucky, you don’t need to start on a sample-demo project like me, but can look at my production-ready (and running) code on github. You can read more about the steps I took there in the anatomy of a trading bot.

I went from a new project to the first deploy on real money within 3 months. If you use my sample code, you can probably do it in 1 month. But that’s not the end of the journey, it’s the beginning. Even though you don’t have to fix all the rookie bugs that I had in my code, you still have to learn to deal with the reality of running a bot. For me, it was nothing like I imagined it. (Of course I wrote about that). And beside that, you still have to keep your emotions in check. Because even though a bot is supposedly taking the emotions out of the picture, my emotions still found a way back into the equation.

With that you are prepared for your own journey now. Let me know in the comments if you have any questions or wanna get more detailed insights on some specific topic.

--

--