Trading Bot Trading Strategy

Trading Bot Trading Strategy (Setup, Rules, Backtest, Example, Video)

The advent of electronic trading and the high-frequency trading bot that follows it meant that the financial markets have become too efficient to successfully trade them with discretionary methods. This is why algorithmic trading has been on the rise among retail traders. But while many traders aspire to become algorithmic traders, a lot of them struggle to create a trading bot strategy that suits them. Want to know about the trading bot trading strategy?

A trading bot strategy is a method of trading in which a computer program is set up to monitor the markets, identify qualifying trade setups, execute the trades, and manage them based on preset rules and parameters. This mode of trading has become necessary because the financial markets have become too fast and efficient for humans to identify exploitable inefficiencies and trade them manually.

quantitative trading strategy

In this post, we answer some questions about the trading bot strategy, and we end the article with a backtest.

Related reading:We have many more trading bot strategies, and systems

What is a trading bot trading strategy?

Trading Bot Strategies

Also known as a trading robot or trading algorithm, a trading bot is a computer program that can develop and execute buy and sell orders in the financial markets.

The key elements of such trading algos are position size rules, which specify the amounts to buy or sell; entry rules indicating when to purchase or sell; exit rules showing when to end the existing position; and risk management modalities.

In other words, a trading bot is an algorithm that interprets market conditions and converts them into tradable choices such as buy, sell, or hold. Bots trade on your behalf around the clock using pre-built logic sets.

They can handle far more trades than any chosen trader due to the little downtime — provided there is stable power and an internet connection, bots trade 24/7 as long as the markets are open. In fact, the issues of power and internet connection can be bypassed with the use of VPS.

Another benefit of the trading bot strategy is that bots are not impacted by emotional trading, so it reduces the chances of fat-finger mistakes and the dangers of trading emotions, such as fear, greed, anger, and hope. In fact, individuals who do a ton of money, which can affect their emotions, tend to prefer the use of trading bots.

What are the key features of a trading bot trading strategy?

The main feature of a trading bot strategy is that the computer algorithm has the power to execute trade orders on behalf of the trader. To execute this function, the trading bot has trading rules that determine when to buy or sell and rules indicating when to close the position, as well as rules determining position size and portfolio allocation.

A good trading bot strategy should also have some overriding key to turn it off when the market condition is not suitable for the strategy it is built on, as well as a key to automatically close all positions and stop trading if there is a black swan event that leads to an unusually huge loss.

A trading bot strategy is based on backtesting:

How can I develop a profitable trading bot?

One of the first stages in building an algorithmic strategy is to consider some of the key characteristics that your algorithmic trading strategy should include. It starts with finding a market edge that is fundamentally solid from an economic and market perspective.

Your bot must be able to identify and seize enduring market inefficiencies in order to have an automated approach. The existence of a single instance of market inefficiency is insufficient to support the development of an algorithmic trading strategy since these methods adhere to a strict set of rules that capitalize on market behavior.

So, make sure your market edge makes sense market-wise. If the reason for the market inefficiency cannot be identified, there will be no way to determine whether or not the success or failure of the strategy was the result of chance.

Next, you develop a mathematical model that can take advantage of the edge. Your model should be based on reliable statistical techniques. The outcomes of individual trades are based on probabilities, so you should use the right statistical methods to determine the parameters with the best odds.

The next step is to code your bot by writing the rules and logic using the programming language of the platform you want to trade with. If you are trading with TradeStation, for example, the language is the Easy Language; whereas for MT4, the language is the MQL4. We like to use Amibroker and TradeStation.

The final step is to backtest, optimize, and possibly forward-test your bot. You backtest with historical market data, which you divide into two for in-sample and out-of-sample testing. Forward testing is done with a demo account but can be time consuming, especially if your bot is created to trade on higher timeframes; however, it may be suitable for confirming a scalping strategy in real-time.

How does a trading bot decide when to buy or sell?

A trading bot decides when to buy or sell based on preset rules in its code. This is how it happens: As you know, a trading bot is built based on a strategy that exploits a possible edge in the market. The creator first identifies an inefficiency in the market — say the price tends to reverse after falling 30% below the moving average.

So, the strategy could be to buy when the price falls more than 30% below the moving average and sell when the price moves more than 30% above the moving average.

In this case, the bot has the built-in codes that enable it to execute based on these rules — when the price falls by more than 30% below the moving average, the buy function executes, and likewise, when the price rises by more than 30% above the moving average, the sell function executes.

How do I set up a trading bot?

To set up a trading bot, you either code one yourself or buy from a bot vendor.

Coding one yourself would be much better than buying one because it is nearly impossible to buy a bot that is reliably profitable — nobody sells a highly profitable bot when they can deploy it in the market themselves and literally start printing money.

So, don’t get carried away by the hype on over-optimized bots and trading results. Choose to code your bot yourself or hire a coder to code your strategy. We strongly recommend to learn coding yourself, it’s not difficult. When er have managed to learn basic coding anyone can do it!

Whichever way you choose, when you have your trading bot, you can set it up on your computer or make use of a VPS. Setting it up on your computer means that it can only trade when your computers are on and are connected to your broker. That is to say that it requires a stable power supply and an internet connection to trade at all times.

But if you make use of a VPS through your broker or a third party, your bot runs all the time, as it won’t be dependent on your computer being powered on and connected to the internet for it to function. So, if you want to use a trading bot, go for a VPS subscription and set it up via a VPS.

What indicators should I use to create a trading bot trading strategy?

Any indicator can be used to create a trading bot strategy. What matters is that you find a market inefficiency you can exploit with the help of the indicator. Any indicator signal that gives you an edge in the market can be used to create a trading bot strategy.

If you like trading with the RSI, you can create a trading bot with it. Likewise, if your favorite indicator is the moving average, ADX, stochastic, or MACD, you can create a trading bot with any of them. You can even create a trading bot with price action patterns and market volume.

What timeframes should I consider when developing a trading bot trading strategy?

The timeframes to consider depends on your preferred trading style — scalping, day trading, swing trading, or position trading — which, in turn, depends on your trading personality. If you are the type that loves to take profits very quickly, no matter how small, scalping may be your style, and in that case, the timeframes you focus on would be the lowest ones like the 1-minute to 5-minute timeframes.

That said, our experience indicate that most scalpers lose money and waste their time.

On the other hand, if you prefer to just capture the main move of the day and don’t like leaving trades overnight, your style may be day trading; in that case, you focus on hourly to 15-minute timeframe. If you are a swing trader or position trader, you look towards the daily timeframe and higher.

What types of orders should I use when trading with a trading bot?

You can use any type of trade order — market orders, limit orders, stop orders, and so on. But the most common orders for bot trading are market and limit orders.

Each of them has its advantages and disadvantages. While limit orders can help you get in at a better price, the order may not get filled, and you miss the trade.

On the other hand, market orders, which allow you to get in at the best available market price can come with some huge slippage, getting you in at a poor price.

Again, you must keep detailed records in a trading journal to find out the best approach. Also, if you are trading very liquid assets slippage and commissions are not a big issue.

How does a trading bot react to changing market conditions?

A trading bot reacts to changing market conditions according to its built-in logic. At the basic level, when conditions to open a position are met, the bot opens a position, and when the condition changes and matches the one for closing a position, the bot closes the position.

The good thing about bots is that they monitor the market 24/7 to identify changing conditions and respond accordingly. Since bots can be designed to monitor the markets round-the-clock while we sleep, they respond to changing market circumstances faster than humans. Bots don’t only carry out commands. Depending on what you set your bot to do, it can also analyze price changes and spot trade trends and then notify you about them, instead of executing trades.

What type of risk management strategies should I use with a trading bot?

You can use any type of risk management strategies — including stop loss and take profit, diversification, and trading small position sizes (1% or less) — provided you backtest them. You are sure that they help your system to maximize profits while protecting your capital.

However, given the manipulations in the markets, the use of stop loss tends to minimize the profitability of trading bots. This is why many experienced bot traders make use of diversification methods. They diversify across strategies, timeframes, and markets.

What are the different types of market conditions a trading bot can handle?

A trading bot tends to work best in one specific market condition only such that a trading bot that is based on a trend-following strategy would not work well in a range-bound market, and similarly, a trading bot that is based on range or mean-reversion strategy may not work well in a trending market.

This is why experienced traders diversify across different strategies by creating bots for different market conditions. For example, you can have a trading bot based on a trend-following strategy and another based on a mean-reversion strategy.

How can I monitor the performance of my trading bot?

You can do that manually or create a script for tracking the performance of your bot. To monitor your bot manually, you can keep track of the profit and loss column and the number of trades taken. With those, you can estimate whether the bot is still performing optimally or the performance is dropping.

You may have a specified number of trades that constitute a sample size for you to analyze the trading results. Once that sample size is reached, you switch off the bot and analyze the trade sample, noting the profit factor, maximum drawdown, Sharpe Ratio, and so on.

What are the advantages and disadvantages of using a trading bot?

There are many advantages to using a trading bot. These are some of them:

  • No downtime: Algorithms can trade 24/7.
  • Lack of emotional trading: The use of a trading bot minimizes emotional trading.
  • Easy to backtest: A trading bot is easy to backtest compared to manually backtesting a discretionary strategy.
  • Easy to trade multiple markets: Because it is done by computers, you can trade multiple markets at the same time.

Some of the disadvantages of using a trading bot include the following:

  • There can be mechanical failures, and if you are set up on your computer; an unstable power supply and internet connection can worsen the situation.
  • You will need to regularly monitor it to be sure of functionality
  • It can perform poorly if it is based on a poor strategy without an edge

What are the most important components of a successful trading bot trading strategy?

The key components of a successful trading bot strategy include:

  • A strategy with an edge in the market: You must first have a strategy that tries to exploit an inefficiency in the market. It is the strategy that you convert to a trading bot using computer algorithms.
  • A well-written trading algo: The algo must be written to convert the strategy into executable entry rules that signal when to buy or sell, exit rules indicating when to close the current position, and position sizing rules defining the quantities to buy or sell. A poorly written bot would have bugs that cause problems.
  • A hitch-free execution platform: To achieve this, it is best to subscribe to a VPS service and have your trading bot run 24/7. If you want to run it on your PC, ensure you have a stable power supply and internet connection and be ready to have your system on all the time.

How often should I backtest my trading bot trading strategy?

You backtest as often as you need to tweak the strategy or create a new one. As a rule, you must backtest every new strategy before you deploy it in the market. If you tweak the parameters of an existing bot, it is as good as a new strategy, so you will have to backtest it to be sure that the new parameters are profitable.

We also recommend keeping your backtested strategies in incubation for at least 12 months before you start trading live.

To know when to tweak an existing bot, you need to establish a trading sample size and analyze the bot’s performance each time it hits that trading sample size. If the analysis shows that the performance has dropped significantly, you can tweak it and then backtest the new parameters.

What kind of data should I use for my backtests?

You backtest your strategy with historical data. Get as much data as is necessary to give you enough sample size for your testing.

You will need to divide the data into two: in-sample data and out-of-sample data. The in-sample data is used for the backtesting, while the out-of-sample data is used for optimization and validation. The aim is to have a strategy that is not curve-fitted but rather robust enough to be profitable in the live market environment.

When this is done, put the trading strategy in incubation for 12 months.

How can I analyze the results of my backtests?

There are many parameters to look at when analyzing the result of your backtests. Some of the most common ones are:

  • Number of trades
  • How long you are in the market
  • Profit factor
  • Cumulative returns
  • Annualized returns
  • Maximum drawdown
  • Sharpe Ratio

What are the different types of trading bot trading strategies?

There are as many trading bot strategies as there are different technical trading strategies. The point is that virtually any trading strategy that is based on technical analysis can be converted into a trading bot and executed automatedly. Based on this, the common trading bot strategies are as follows:

  • Mean-reversion strategy
  • Momentum strategy
  • Trend-following strategy
  • Breakout strategy
  • Moving average strategy
  • RSI strategy
  • Bollinger Bands strategy
  • Arbitrage trading strategy
  • Spread trading strategy

What factors should I consider when selecting a trading bot trading strategy?

While a bot trading strategy is all about identifying persistent market inefficiencies and creating a trading algorithm to exploit them, there are factors to consider when choosing a bot trading strategy. For example, you need to consider your trading personality, which influences your trading style — are you planning to scalp, day trade, swing trade, or have long-term positions?

Other factors, such as personal risk profile, time commitment, and trading capital, are also important to think about when developing a strategy.

How do I know if my trading bot trading strategy will be profitable?

The only way to verify that is by backtesting the strategy. This tells you how well the strategy performed in the past, which could give you an idea of how it might perform going forward.

However, there is one thing you should know: past performance is not often indicative of future performance. A strategy that performed well on backtesting can still flop in the live market. This is especially true if the backtest was curve-fitted and overoptimized. This is why we recommend using a 12 month incubation period.

What metrics can I use to measure the performance of my trading bot trading strategy?

There are many metrics you can use to analyze the result of your backtests. These are some of the common ones:

  • Number of trades
  • How long you are in the market
  • Profit factor
  • Cumulative returns
  • Annualized returns
  • Maximum drawdown
  • Sharpe Ratio

An easier way to assess the performance of your bot strategy, especially if you are trading a broad market index like the S&P 500 futures, is to compare your strategy’s performance with the performance of the index. By comparing the asset’s performance to your bot’s performance, you can see if your bot strategy is under or overperforming.

How can I optimize my trading bot trading strategy?

You can optimize your trading bot by tweaking the parameters of the strategy and backtesting it each time to see how it performs.

However, to avoid curve fitting, you need to divide your data into the in-sample and out-of-sample data. You validate your new parameters with the out-of-sample data.

If you avoid curve fitting, we believe trading strategy optimization gives you valuable input.

What are the common pitfalls to avoid when creating a trading bot trading strategy?

They include the following:

  • Bugs: Minor bugs may be difficult to notice but can wreck a trading system.
  • Curve fitting: The temptation of tweaking the strategy to appear perfect on backtesting.
  • Overoptimization: This leaves you with a strategy that is not robust enough to remain profitable in a live market environment.

Trading bot trading strategy backtest

Since we started this blog in 2012, we have backtested and published hundreds of articles. Most of them include specific setups and trading rules. Below, we’ll give you two examples of strategies:

Let’s show you the turn-of-the-month trading strategy – a straightforward seasonal trading strategy you can easily trade via your trading bot.

The trading rules are simple and work best for S&P 500:

We go long at the close on the fifth last trading day of the month, and we exit after seven days, i.e. at the close of the third trading day of the next month. Thus, the strategy is invested around 33% of the time.

How has the strategy performed? Pretty well. Below is the equity curve since 1960:

Trading bot trading strategy

The strategy beats buy and hold (!) despite being invested just 33% of the time. Because it’s invested less time than buy and hold, the max drawdown is reduced from 55 to 27%. It can also be improved, something we did for our paying members – please see trading strategy for sale #82.

The second bot trading strategy is a volatility strategy – trading strategy for sale #1. It works on a wide range of assets but is best for stocks.

Because it’s a premium member strategy, we don’t reveal the trading rules (obviously).

The strategy has worked well, and the equity below is for S&P 500 (SPY):

Trading bot trading strategy example

The same strategy performed even better for NASDAQ 100 (QQQ):

Trading bot trading strategy setup and rules

The average gain per trade for QQQ is 1.7%, 2.73% for winners and -2.31% for losers), the win rate is 79%, and CAGR is 13.3%. It worked best during the bear market of 2000-03, but it’s still performing well with fewer trades.

If you are interested in more potential trading bot strategies, please check out our article or video:

Similar Posts