Is it possible, or even worth trying?
To answer this question I’ve spent a lot of time thinking and investigating neural science, algorithmic trading, crypto trading and found something really interesting.
Disclaimer: if you are reading this article, I assume that you’re acknowledged about stock/crypto markets and have basic understanding why you need a bot or you’re just interested in their theory. This article won’t contain any code parts and it’s for educational purposes.
Let’s start with facts. Trading bots are not new and there are plenty of publications about it, they are used by financial structures, but are they really helpful? I think so, but if you are a programmer or you acknowledged basic concepts of scripting, you are able to write your own bot in few hours. But will it earn enough money for you? Will it have stable earnings? Will it ever hit 100,000$ annual return? I’m going to answer these questions in this post and give you some shots to move forward.
1.What is a trading bot?
A trading bot is an algorithm that turns specific market conditions into order decisions (usually buy, sell or hold). That’s it, nothing special.
2. What types of trading bots exist?
All types that any trader could take, as the bot is an algorithm written by programmers, they could put any logic in it.
In general, we have different types of traders:
• Long-term traders — investors;
• Swing traders — those who place orders on a week, month, or year basis;
• Day traders — those who place few orders through the day without moving them overnight;
• Scalping traders — those who place many orders per day, an hour, or even a minute.
All these trader types could be implemented in a bot.
3. Where trading bot could place orders?
Anywhere you want and could get to broker’s API or through reverse engineering. But you may even simulate your own broker conditions, commissions, taxes, spread, price just by making simple random movements, this simulation won’t contain the psychological part of a market, but it will be a good start for testing a bot. More about designing a great bot I’ll publish separate writing.
1. How Conversational AI can Automate Customer Service
2. Automated vs Live Chats: What will the Future of Customer Service Look Like?
3. Chatbots As Medical Assistants In COVID-19 Pandemic
4. Chatbot Vs. Intelligent Virtual Assistant — What’s the difference & Why Care?
4. What about bot implementation types?
It’s better to say, types of algorithmic trading. As the bot is a complete program that implements the trading behavior of a trader in an automated way.
• Neural Network or Artificial Intelligence bots — could be simple single-perceptron bots based on few neurons, complex LSTM networks, or even artificial news analysis based on keywords heuristics and ranking.
• Quantitive trading — based on a strategy combining any criteria for making a decision, it could be comparing indicators, price action, finding patterns, etc.
• Semi-automatic bot — will use some algorithms to suggest to traders what to do. Indicators based on some strategy are part of this type.
• Genetic algorithms — it could be put into the machine learning/neural networks part, but it’s not really investigated enough to decide this type of algorithm as a machine learning approach. Genetic algorithm implementations differ from person to person and are investigated by universities throughout the world and are part of a bigger topic than this one (but I’ll discuss it later, stay tuned)
Alright, I’ve answered the above four basic questions you may think about before starting writing any bot. But what’s next? After understanding what is a bot, we may think about measuring their KPI.
To measure the bot’s quality we may use the back-testing technique, which assumes any time range on a specific timeframe to execute orders based on previously available data. Let’s take some heuristics to work with, such as available cash, a timeframe it works with, stop loss and take profit ranges. We may use any other based on any trading strategy we want (for example neural network bots could determine their heuristics based on market conditions).
The best way to determine strategy quality is to write your own using TradingView. Using their documentation you’re able to write a strategy on Pine Script (which has really simple syntax).
As you may see in the picture above, I’ve implemented a simple strategy based on entering a long position after each green bar.
It won’t work on Binance or similar crypto brokers as using 0.01% stop loss and 0.5% profit. It’s possible to automate trading on this percentage and even place a stop-limit order in its range, but it won’t be possible to survive with commissions that a broker proposes.
For example, Binance proposes a 0.04% commission for a maker order (any market order) on a basic VIP level. This will execute any stop-loss order in 0.01 + 0.04 * 2 = 0.09% loss for 0.5% profit. This strategy won’t survive with a 1:5 profit ratio, as we have only 2.79% profitable percent (that means only 2% of all placed orders are winning, others are executed with stop loss).
Using full statistics taken from TradingView we are able to design our bot or back-test strategies faster and easier before we will use real market or paper-trading for writing a program.
After you see something like this:
Where you have a good net profit in combination with a profitable percent higher than 60 (at least), you may think about implementing a real trading bot.
But wait, does it mean that bots are effective? Can we answer now on this question? Sure.
Of course yes. That’s why many hedge funds, banking structures, and big financial companies hire machine learning and algorithmic specialists. Those people are responsible for implementing automated trading bots to play in the real markets with big money.
So how much money do they make? Can we calculate and answer?
It depends on many factors. At least heuristics programmers put in it. Risk management, market conditions, available cash, etc.
You may find that a good prediction inside a trading day with low volatility could give about 0.6-1% of a stock move. If your bot won’t lose any trade in a trading month, you would earn about 20% each month, for the “all-in” strategy, a 10k$ account will earn 2000$.
We may use margin accounts with leveraged orders, risk managements, or pyramiding, using short stop loss or long take profits or different trading bot types, all of them will work differently.
A bad algorithm will just blow up whole your account if any mistake was written. So make sure you make all unit tests and use your bot on paper trading before starting using it with real money.
So could it make 100k$ in a year? Sure, proper risk management, strategy, and a proportional amount of money could give you this return.
It’s an important topic to discuss the difference between neural networks and quantitive analysis. What are the reasons to use machine learning or neural network algorithms? They could see patterns based on historical data better than people.
How do they determine patterns? It depends on a neural network type. You may implement an LSTM network or a single-layer perceptron. There are plenty of different investigations for other types of networks, so it depends solely on your choice.
Do they effective? Yes. They really find patterns with a properly written algorithm by using learning with a teacher or without a teacher. I was implementing a single-perceptron neural network and put few indicators in this bot (some of them my own indicators, some of them based on RSI, Bollinger Bands, and Stochastic RSI), I’ve created a function that takes a time range and runs neural network through candles finding a bar after which there’s a constant bullish or bearish movement. The second function was teaching neural networks using bar indicators and put a 1 or 0 as an output neuron (1 is buy prediction and 0 is hold).
Then I took neural weights and wrote a strategy using Pine Script to visually represent the bot’s predictions. And it worked better than I was thinking.
So this approach makes a big sense, but it requires more heuristics to learn, like where to put stop and take limit orders, what risk to use, etc. But this is a good example of using neural networks in practice and it works.
The quantitive approach is similar to neural networks, but instead of using machine learning to determine patterns, the programmer should determine them by himself. This makes it easier to determine the exact strategy, when to leave a position and how to manage risks. More than that, in a quantitive approach it’s possible to make not an automated bot, but a great indicator with a collection of compared conditions, and the trader will make his own decision using this analysis and overall market situation.
It depends. It depends on stock and market conditions, chosen strategy, and algorithm type. A bot could make a 2% return for a day and then the market will change its direction and it will blow up day’s profit and make a 3% loss.
Programmers should care about risk management.
For example, simply stop bot for the day if day’s loss or profit reached some mark (like 1% loss for the day and 2% profit is enough). Market conditions are changing between years, months, days, or even minutes. Fundamental news, panic on market, or market movers making big buys or sells (like Tesla on Bitcoin). These moments could break any algorithm including complex neural networks if they don’t implement risk management and proper stops.
Trading bots are an effective way of increasing your income with automated trading, but it should be made in a planned way, well tested before starting it on real money. Make sure you’re well acknowledged about technologies you’re using for making and algorithmic trading, aware of pre-made bots that are offered for some price (many of them are working on patterns for only 1–2 weeks they’re tested for promotion).
Later I’ll write some publications about practical usage of algorithmic bots, how to write proper strategies on Pine Script, also with examples of genetic trading and my investigations, so stay tuned!