How to create a competent trading algorithm
This file is designed to improve the trading skills and develop the trader’s discipline. It explains how to create a manual trading algorithm and it will be useful for both beginners and experienced traders.
What is an algorithm?
Algorithm (script) is a document designed to automate individual’s actions and eliminate the psychological component when it comes to decision-making.
- Make sure that the green traffic light is on
- Look to the left
- Make sure that no cars are moving to your direction
- Start to cross the road
- Reach the centerline
- Look to the right
- Make sure that no cars are moving to your direction
- Finish crossing the road
- Get on the sidewalk
Do I need a trading algorithm?
When a person knows clearly what and under which circumstances (s)he should do, dramatic changes occur:
- It saves a lot of time to make a decision. In fact, the decision will be made almost instantly, as soon as all the necessary conditions of the external environment compose one image.
- It saves a colossal amount of energy.
- It saves a lot of mental energy. It makes no sense to reinvent the wheel, when a competent algorithm has been already sketched.
The exceptional importance of having the trading algorithm in Forex cannot be overestimated. Trading in the Forex market is an extremely emotional activity and the algorithm is the only one possibility to start using your head instead of the gut forecasts.
When it comes to trading, a bad algorithm is much better than a good improvisation. The algorithm does not guarantee a profitable result, but it definitely warrants an understanding of:
- why this month was closed with a significant loss,
- what was done incorrectly and
- which element of your strategy should be tested in order to improve the future results.
An example of a trading algorithm
1. Open the trades using the pending orders only. It helps to avoid opening the trades based on emotions and not the pragmatic calculation. If the analysis showed no presence of a potential entry, and then it became obvious that the signal to enter the trade exists – you have no right to open a trade using a market order – the possibility should be skipped.
2. Open the trades during the European and US sessions only. The Asian session should be passed as the least volatile.
3. Set the fixed size of the stop loss at the amount of 50 pips. Once a stop loss is set, it is prohibited to change its value. In other words, within this strategy, stop loss is always 50 pips, not even a pip less, not a pip more.
4. Set the fixed size of the take profit at the amount of 100 pips. As soon as the take profit is set, it is prohibited to alter its value.
5. The trades can be closed automatically only: either by stop loss or by take profit. Closing the orders manually is strictly forbidden.
6. It is allowed to risk no more than with 2% of the deposit in 1 trade. For example, if your deposit is $1,000, you can lose a maximum of $1,000 * 0.02 = $20 per trade.
7. It is allowed to risk no more than with 6% of the deposit in 1 month. For example, if your deposit is $1,000, you can lose a maximum of $1,000 * 0.06 = $60 per month.
8. EURUSD & GBPUSD currency pairs are the only instruments available for trading.
9. The strategic decision related to the trend direction is made on the H4 time frame, a tactical decision is made on the H1 time frame, the search for the ideal entry is made on the M15 time frame.
10. Buy orders are open only from the strong support levels whereas sell orders are open when the price reaches a strong resistance level.
11. The rules of how to find support/resistance levels:
11.1. Find the Price action’s "tweezers" pattern that consists of at least three candlesticks. "Tweezers" – is the set of candlesticks (bars), which low / high prices are exactly the same or differ by 1-2 pips. In this example, the low of the 1 st candle is at 1.1427, and the 2 nd and 3 rd are at 1.1426. Permission is granted to have an error of 3 pips on the H4, 2 pips on H1 and finally 1 pip on M15. In our case, the difference between our 3 candlesticks is just 1 pip so we can consider this pattern as an eligible one.
11.2. Set a buy limit order at 3 pips above the support line or set a sell limit at the 3 points below the resistance line.
11.3. Set a stop loss of 50 points, and take profit of 100 points.
11.4. Wait until the order is closed.
11.5. Record the results into a trading log.
11.6. If the price moved up to 50 points to another direction after the “tweezers” pattern is formed not giving the chance to activate the pending order, the non-activated limit order must be removed.
Important aspects of the trading algorithm
As you can see from the example above, a competent trading algorithm must include 3 tremendously important aspects:
- Trading Psychology (par. 1, 3, 4, 5)
- Money Management Rules (par. 3, 4, 6, 7)
- Trading Method (par. 2, 9, 10, 11)
Does it mean that this particular algorithm will bring you profit? Not at all. However, there are three very important points that characterize this and all other algorithms if you unquestioningly follow them:
- You can always keep track on the problem points of the algorithm.
- You can test the other logical alternatives.
- You can find what works in the best way.
For example, you have found 100 patterns, set 100 limit orders, but only 44 of them were activated. Most likely, it makes sense to revise the paragraph 11.2 and to amend the value of 3 pips to the values of 4 or even 5. After that, find one more 100 patterns, set another 100 limit orders and see whether the percentage of activated orders was increased. And most importantly, you need to keep track of whether your income increases. It may appear that 44 orders will bring more income than, say, 72 orders. In this case, the parameter increase from 3 to 5 resulted your strategy’s performance in a bad way. How to create a competent trading algorithm 6 If you notice that 72% of your trades are closed by stop loss, then it makes sense to test other values for your stop loss parameters. One can try to backtest the same period of historical data using the 55, 60, 65, 70 and other values. After that, you should compare the profit / loss statistics of the abovementioned values and choose the stop loss, which delivers the most significant profit. The same applies to the take profits.
The beauty of the trading algorithm
The main benefit of the algorithm is in ability to test different parameters and find the optimal values.
If today you have opened orders based on the moving averages crossover without stops losses; tomorrow you will open the trades based on Stochastic with a 30 pip stop loss; and the day after tomorrow – trades based on support/resistance levels with a stop loss of 70 pips – then surely there is a chance that you will close all 3 trades in profit. The real problem is how are you supposed to determine which methods worked best of all, and most importantly, which will work in the future?
Now when you know the most important moments to consider while creating the trading algorithm, when you know the critical importance of having the algorithm itself, you can create your own trading systems and test them on the historical data with Forex Tester. Pay attention that it is necessary to make tests on a large sample of data (at least a few years) in order to obtain adequate and reliable results.