Basic algorithmic trading system design

Kirill Eremenko
A free video tutorial from Kirill Eremenko
Data Scientist
4.5 instructor rating • 119 courses • 1,576,804 students

Lecture description

Hello there! Today we will be looking at some examples of how you would use price levels in an Algorithmic Trading System. In fact, this approach can be used in manual trading strategies as well. The stuff we will be working with today is very basic, so you will find it very simple. At the same time, easy strategies are the best to practice programming for financial markets.

There won’t be any coding in today’s tutorial, so you can just watch it in relaxed mode :)We will turn one of the underlying strategies into code next time.

Learn more from the full course

Algorithmic Trading In Forex: Create Your First Forex Robot!

Trading With Forex Robots: Learn MQL4 Programming By Doing! Create Your First Algorithmic Trading System in MetaTrader 4

06:24:19 of on-demand video • Updated September 2020

  • Learn what forex algorithmic trading is
  • Quickly & simply learn basic MQL4 programming
  • Learn elementary concepts of forex trading system design
  • Send, modify, and close your first market order
  • Learn how to create, test, and optimize algorithmic trading systems (expert advisors)
English [Auto] Hello this is Carol from forewings about dot com. And welcome to this 13th tutorial in our course on algorithmic trading for complete beginners. And today we're starting a new section in our course which is going to be about system design and trading function and sending orders working with prices and so on. So is a very exciting part and I'm really glad that you've made it this far. We're going to be delving deeper into the actual Forex market and finally starts to do some basic algorithmic trading today in today's tutorial we're not going to actually code anything right away. We're going to focus on understanding how systems are designed and what what basically goes into the foundation of a programming system or an algorithmic trading system. And I think it is an important part and it illustrates this tutorial illustrate that if any kind of algorithmic system development you first have to sit down and understand what you need to do what you want to create. And sometimes I even recommend writing these things down on a paper for yourself so that you when you do start coding you understand exactly what the requirements are and what the algorithm will look like because clear requirements will always make your programming experience much more pleasurable and seamless and you won't have to stop and rethink things along the way. So here I have a Eurodollar chart open in front of me. And pretty lucky that today is actually the weekend it's Saturday so the markets are not working and we're going to take advantage of that. So the prices are still and we're going to just discuss what would happen what what we'd want to do if we could trade now. But because the market is still we will not have this problem the price moving around so it kind of discussing a freeze frame of the market. This is a bar chart and I'm just going to change it to a line line graph so that it's easier to discuss. So there's less clutter on the chart. Right now the price prices 1.3 6 0 8 for your dollar and the big price is one point thirty six or six. So the surprise I'm sure you're aware of this but I'll just recap to ask prices are always higher than the bid price. And basically the ask price is the price and it's the dearer price. If you want to buy euros for dollars you're going to have to do it at the ask price. So for every one euro you're going to have to pay one point thirty six 0 8 American dollars and conversely the price is always less than ask price it's the cheaper of the two. So basically if you're one if you want to sell a euros for dollars you're going to get this amount of dollars for every euro. And the difference between them is called the spread so that in essence the spread is is what at what disadvantage are ordered that the price you pay for conducting these transactions has an important part. Because in how algorithms we're going to have to take into account both the ask the big price and understand where to use which one. So let's see what oh let's try to understand what kind of system we would possibly want to design in this particular instance. We can really from from what we see we can't really tell whether the price is going to go up or is going to go down. So for argument's sake let's suggest that the price is going to go up. So what would we need in a algorithmic trading system that is going to buy euros euros against dollars. And because the prices are going up we want to buy Euro's cheap and then when the price goes up we want to sell them. So first of all we're going to have to understand how far do we think the prices go up by. And let's for example think say there's going to be 10 pips that the price is going to increase by. And so basically it will get to the level of 1.3 6 1 6. And if you notice here I'm using the bid price. So how this works is influenced by euros for dollars. We're going to have to use the ask price to buy them and for every for every one euro we are going to have to pay one point three six or eight dollars. But then if we want to sell them we're going to be selling at the big price. So this gap over here is it's already our disadvantages already what we lose just by initiating this transaction and therefore we have to take into account so if we want to earn 10 pips on the movement upward movement of your dollar we're going to have to base our calculations on the bid price. So their initial transaction will occur at the ask price but further on we are going to be dealing with the bid price and we will be trying to close the transaction at the bid price. So if we're 110 Pipps is going to be a 1.3 6 1 6. So that's the first part and you'd think that that is the full extent of the trading system but that wouldn't be correct because if we also have to take into account a possible downward movement and we have to protect our position from very high losses. So let's see what is the maximum that we can afford to lose. Let's say it's also 10 pips. So in that case we need to set a stop loss at bid minus 10 pips which is one point 3 5 9 6. So as you can see a simple trading system that suggests an upward movement has to have certain factors built into it. It has to open a position at the ask price then has to have a take profit at the bid price plus 10 pips and has to have a stop light and stop loss at the bid price minus tenpins. Now let's look at a different situation where for example here on the A Canadian dollar where we see more of the chart and we've made some. We're going to make some and now we can do some analysis and try to understand the future movements and predict exactly where it's going to where the Chaska is going to move. So here marked the asking price. And here you can see the differences a bit higher it's actually a Pip's between the Oskin bit and then because this is not a euro or Canadian dollar is not a major paper it's across. So here we can see that there's been a substantial move upward and the price has reached this level of uncertainty around the one point for six zeros is just across that and previous experience suggests that sometimes the price can turn around at this level and go backwards. And so that's what we're going to bet on. We're going to suggest we're going to speculate that the price is going to go down from here. And it is going to reach a certain level and we're going to try to capitalize on that. So here we here I've identified a level where there was another uncertainty at one point four five four or five or somewhere around there where historically the price has experienced you know turn turning points or some kind of uncertainty around where it's going to move. So what we will do is we'll use that level and we'll expect the price to go down to that level but we will exit the position just before the price gets there and that will put us on the safe side. So we'll exit the position at the blue line and then that way we can avoid getting into this. Getting close to this level where the price may turnaround and may not turn around so exiting at the blue line is being on the safe side. So if we have a sell position which will open here at the big price then the take profit we're going to set at one point 4 5 5 5 percent. As the previous example we need a stop loss and for sell position stop loss goes up to the top. So here we see a level where the price has previously turned around. So what we'll do is we will speculate that if the price does go up or against our position there is a probability that it will actually turn around at the yellow line and then go down like you do here and reach our take profits so we can actually still make money. So in that case we would want to set the Stop-Loss above the yellow line so we don't lose this opportunity of the price actually turning around and that says that means that the stop loss would be set at around 1 point 4 6 4 5. So in this case you see that take profit is around 50 pips and the stop loss is around 40 pips or basically to be more correct. We have to be working with the ask price. So the take profit is fifty seven pips up losses around 33 pips. So to sum up this strategy even though it is similar to the previous one which we discussed here these strategies have different requirements in the first strategy we would say choosing an entry level level based on the market price and then we were setting the stop loss and take profit take profit and stop loss based on a fixed number of pips which was 10 pips for both. In this strategy this approach is different. We are still using the market price to enter but to exit we're not using a fixed stop loss or take profit to exit. We're actually using prices price levels which we see on the market and we're moving away a little bit from them. So that means that the algorithmic trading systems will be similar but will be different from each other in the sense that the parameters of these systems in the first case it will be the levels or the absolute values distances of the stop loss and take profit from the market price. But in the second situation the input parameters will actually be fixed prices which the trader chooses based on his analysis of the current of the currency pair. So that's in a nutshell what algorithmic trading system design is about. And of course it gets more complex and more involved and has much more aspects to it. But these are the basics and I hope you found that helpful and maybe you could look at some of the charts in your trading platform and try to understand what strategy you would apply as in each situation and in the next tutorial we're going to look at how we can actually turn this logic into code and how we can create scripts will which will implement this logic for us. And I think you will find the next Tauriel very exciting. So that's it for the Statoil. And don't forget to click Subscribe if you're watching on YouTube and I hope you'll consider going to WWE for Expo dot com and subscribing to my new newsletter there as well. So for now until next time happy coding.