Learn MQL4 from scratch and build your own Forex Trading Robots | Charlie Kang | Skillshare

Learn MQL4 from scratch and build your own Forex Trading Robots

Charlie Kang, Everyone should be able to invest.

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
29 Lessons (2h 21m)
    • 1. Promo video for EA course (noise removed)

      1:31
    • 2. Section 1 2 combining three types of learning methods (noise removed)

      1:34
    • 3. Section 1 3 installing software (noise removed)

      2:46
    • 4. Section 2 2 basic structure of a program(noise removed)

      3:35
    • 5. Section 2 3 Starting a script (noise removed)

      1:43
    • 6. Section 2 4 Declaration of Variables Comments (noise removed)

      5:38
    • 7. Section 2 5 Main Body of the Script (noise removed)

      10:11
    • 8. Section 2 6 Compile our script,debugging, using the Script (noise removed)

      8:38
    • 9. Section 3 1 introduction (noise removed)

      0:43
    • 10. Section 3 2 Pivot point support and resistance (noise removed)

      1:32
    • 11. Section 3 3 Declaration of Variables (part 1)(noise removed)

      4:54
    • 12. Section 3 3 Declaration of Variables (part 2)(noise removed)

      4:28
    • 13. Section 3 5 Custom Functions (part 1)(noise removed)

      8:32
    • 14. Section 3 6 Custom Functions (part 2)(noise removed)

      5:51
    • 15. Section 3 7 Main Body (noise removed)

      6:55
    • 16. Section 3 8 Compiling and using our Indicator (noise removed)

      5:04
    • 17. Section 4 1 introduction (noise removed)

      1:06
    • 18. Section 4 2 Moving averages and trade signals (noise removed)

      1:56
    • 19. Section 4 3 Pseudocode our ideas for our EA algorithm (noise removed)

      2:25
    • 20. Section 4 4 how to start an EA declaration of variables (noise removed)

      5:13
    • 21. Section 4 5 custom function (part 1) (noise removed)

      4:26
    • 22. Section 4 6 custom function (part 2) (noise removed)

      6:16
    • 23. Section 4 7 main body (part 1) (noise removed)

      7:32
    • 24. Section 4 8 Backtesting (Part 1) (noise removed)

      6:20
    • 25. Section 4 9 Main Body (part 2) (noise removed)

      8:55
    • 26. Section 4 10 backtesting (part 2) (noise removed)

      5:02
    • 27. Section 5 1 course complete what is next (noise removed)

      2:24
    • 28. Section 5 2 risk management (noise removed)

      6:57
    • 29. Section 5 4 turning losing EAs into gold (noise removed)

      9:09

About This Class

This is a practical course for Forex or Commodity traders who want to learn MQL4 and program their own Forex Robots (a.k.a Expert Advisor for the MetaTrader 4 trading platform). The student is assumed to have basic trading knowledge and knows how to use the MetaTrader 4 platform. This course also assumes the student is a total beginner in programming and is structured in a way to have a gentle learning curve.

Transcripts

1. Promo video for EA course (noise removed): welcome to learn and kill for from scratch and do your own for actual bots. This course is designed as a practical cause for traders to learn and cure for which is the programming language to be treating robots on the meta trader for platform. My name is Charlie. I've been trading US stocks, forex and stock options for more than 10 years. After letting em cure for and developing my own for actual bots, I left my full time job to be a full time trader and investment educator when I decided to learn ways to computerize my for expect testing. The journey took me treat months off self learning through the complex jargon off and cure for websites. I designed this course to make it easier and faster for traders to pick up the programming skills to make their own robots. At the end of this course, you will be able to build back tests and customize your own indicators and for actual bots , because the structure for someone we've got programming knowledge to pick up it walks you true programming step by step, teaching you the basics by developing a script, followed by a slightly harder custom indicator and finally, a more complex for extra bob program. The idea student for this course is the trader that wants to computerize and that test their own strategies. Yet they are worried that it might be too difficult to learn the programming skills. A prerequisite for this course will be that you should have traded for X before, where the rial or demo accounts, and you should understand the basic forex trading terms. You're free to look at a cost description, and I look forward to seeing you in sight. 2. Section 1 2 combining three types of learning methods (noise removed): Some of the viewers are probably aware there are tree common types, off learning methods visual, which means using site auditory, using our sense of hearing and finally, kinesthetic refuse us our sense of touch movements or feet. True, my past experience. When it comes to letting programming a few, it is best to combine or tree learning methods. When I learned programming as a teenager in classes, my teacher would make sure the students typed up the courts. India Mutis a few. This is a really smart way of combining or tree learning methods in the class as we use visual learning when we look at the court on the screen, auditory learning where we listen to his lecture and finally kinesthetic learning when we attacked the courts into our computers is why I would recommend you the viewer, to technicals into your own net editor as you go through the lectures. When I came out of the idea of creating this course, it was to make the learning curve easier. I spend quite a lot of time thinking off. How did I could do this? My solution was to introduce the programming concepts in a gradual way. 23 main sections defend objective. Behind each section, I will introduce the basics way in building our script, followed by more intermediate stuff. We review our indicator and finally, the advanced conception. When we finally built on Expert Advisor, which is also known as a forex all treating robot in the foreign lecture, I will get you on how to install and start up the meta trader for imitated of also where which are free software provided by the Meta Quits software company. 3. Section 1 3 installing software (noise removed): Okay, so then this part of video do a simple guide on how to download and install metal trader for for your PC or laptop? I don't know that this instructions for windows. So if you're using a Mac because you check out the metaphor meta trader for website, they will probably have instructions on how to install for Macintosh So you can go to Google. Just have been met the trader about this way m e t a t r a t e r A. Usually without spaces, they will be, ah, variety off results. So you just go to something that says meta trader for dot com or meta trader five dot com So which is quick on military before they come and you will bring you to this website with the meditator for banner so they are motivated for emitter trade of five. So in this case, we are just using meditated for click on this metric before and quick down for free and you will get you this part of the website. So we know that this whistling is a Clickbait. They are trying to get users to download and use their meditative five instead of four was forced diversion. But in this video, we're just using the metaphor, therefore, so just get this screwed down and you can see this. So it seems you're Donald Mental Trillion four for PC and create them Well, can you click on it? And in my case, you don't know Is that you? XY phone So is empty for set up the dxy. You have something like this, which is the standard installer. So once you click next, it by automatically installs metal trader on your default. Dr. Wishes are probably your c drive for being those users and you have to specify which traffic goes to. So just before while Okay, so once he has finished down installation, so just quickly finish okay. And you have successfully installed meta trader and by default, you will open up a demo come for you and this high looks like So for this part of the video , I'll just have ah brief walk True on how you're going to run your my 32 software after you have been stopped met the treated for So if you're followed a previous instructions, you should have already installed head too afraid of four onto your PC or your desktop. So the run meditative voice. Very simple. You can create a like a shot cut to your desktop. Thank ironic from there. Just go to windows. Just type up Metter. Yeah. So it's basically hiding here, which is press enter and method it'll run like this. 4. Section 2 2 basic structure of a program(noise removed): The basic structure of programming lies in tree general sections. We have the decoration section, custom functions and the main body off courts. The aggression section is where we declare Neymar variables along with the Associated Data type and detailed values. Variables are sports mais off memory in our computer, which we can assign a name to it. We used a space restore specific date, our numbers values or what's whenever we need this particular detail, we can call this variable name, and we can get access to the data. In study, custom functions are basic casts off the computers. It can perform a singer instruction or group off instructions from the user. Custom functions are commonly used when we might repeat a certain set of courts, rather than just copy and pasting a whole chunk of courts 100 times. It is more efficient to assign a custom function name to those courts and called a custom function name whenever we need to perform this set of courts. Last but not least, we have our main body off our program courts, where all our program courts will be listed down from top to bottom to be performed or run in that top to bottom order. Our previously declared variables and custom functions will be used in this main body of coats, along with other custom functions and coats, which are specific to the metadata program Only generally, we use metadata to create these tree types off programs, a script and indicator and the expert advisor, which is also commonly referred to as forex robots. Scripts run the courts once and has limited users such as installing programs. Indicators run continuously in a loop as long as the child is active. Indicators are commonly used. Perform calculations using the chart data from which it transforms and displaced a detail in a visual display such this place are usually overly on top off existing charts. Homan examples off indicators are rs i, m, e. C. D. And moving averages. Total program would be expert advisers, or E ace, which is what our meta trader community commonly referred to. Their mess E. A s run continuous es well, as long as the child is active and as long as two user does not decent evil. The expert advisor yes, are mainly used to do automated trading as they can open modify and close traits revolt. Any human interaction, Yes, are also very useful way it comes to back, testing asked. The treater can back Tess's trading strategy over several years of data that is done by running his E A on the strategy test Ahmadu, which is part off the meta trader for platform. As we move into the later lectures, I'll be referring to all our for extra bots s years, so I hope you will get used to this time. 5. Section 2 3 Starting a script (noise removed): I will now introduce to you help to start a new script in Mad editor. After matter, details running. Go to foul quickly. I knew and you will see em care for visit here. Thank you. For was it will give you a few options. What it's like Sure less select scrip. Click on next on this pitch, you just need to type in the name off the scrip. The rest of the boxers. You can beat the bank. I will need my script s my script blank and click on finish. The new temp will pop up in meta data showing you the blank new script it has dysfunction boy on start, which is a custom function that indicates where the main body of the courts will be. I've already finished programming my script, which I will show you at his step here as mentioned, you know, a lecture programme consists off three main parts. He begins with the decoration of variables followed by custom functions which I do not have here and finally ends with the main body of our courts. We shall all below the function on stuff. So this is how you start a new script and, you know, next lecture you will go through the variables and commends off my script 6. Section 2 4 Declaration of Variables Comments (noise removed): Yes, I'm going through the courts in our lectures. I hope that you were type and copy my cuts into your own net editor. I found that this is one off the more efficient ways to then programming as you learn visually by watching the video auditory learning by listening to me and can ecstatically by typing in the courts, moving forward to our lecture. I will start by talking about comments comenta ordinary tax in the program that becomes a set off reference notes, forward programmer or any other programmer days looking at your work. Such notes are not necessary for the program to work. However. It is a really good practice to include these notes. If you're new to programming, I'm sure you agree that it's not the easiest thing in the world to recognise program courts and what they do. Sometimes even professional programmers have to spend quite a fiber of time in order to understand what the courts are doing. So it is a good practice to include comments that explains the purpose of the courts at that particular part of the program to create comments. All we need to do is to include the double backspace key at the start of the common. The double spec space looks like this. Once you have typed in double backspace and he takes to the right will be great out, which means they're now a line of comments. If you are typing on lunch paragraph of comments, you can also start the paragraph with the Beck Species star, which looks like this, and you end the paragraph with a star and backspace like this. Next time I will introduce the variables. Variables are one of the most basic things we learned in programming, as mentioned in the early lecture. The our sport spaces off memory in our computer, which were used to store data to create these variables, we have to declare them, which is why we call it a section off the program. The decoration off variables. To start the decoration, we have to give our variable data type. Let's look at this line here which states I anti space kept the X semi colon i antes in blue, which means it is a date attack. I anti specifically means interject, which is whole Numbers X is in black, and on this line, X is the name off our bearable and because I antes in front off X means X is a variable off data type integer the semi colon at the end of the line is a signal that the line is compete. Semi colons are just like the full stop in the English sentence method. It'll needs this semi colon to understand that the line is complete. The falling two lines have us declaring variables. Why and Zach as interjected attacks as well, just right below them, I have another line of code, this England. I declares the tree variables X y and Zach as into Judita types. What this line shows is that we can declare multiple variables in a single line as long as they are off the same data types. We separate each variable by a comma and as usual, when we're done, we place the same equal in to show that the line has ended. It is also possible to assign values to the variables. When we're doing the decoration, the foreign lines below a short it we declare X y and Zach s in digital type, and we said they are values to the number zero. This is done by placing the equal sign on the right off the variable name and have it to be equal to any whole number. Just like in the early example, we can find a more efficient way of assigning values. Instead of having this tree lines of court, we care for a single line. This line here actually means in digital data. Type X Y and Zack are all equal to the value zero. Please remember to any of the semi colon again other than indigent, we can also create very both with other data types which we declare our text to be off the detect string and our value to be off type double string is the data type used to store lines of text, while double is that the type used to song numbers with decimal places. Just as we have finished our decoration of variables, I will end this electrica moving on into the next lecture or talk about void on start, which is the segment where our main body of program courts will begin 7. Section 2 5 Main Body of the Script (noise removed): In the previous lecture, we talked about comments, decoration of variables, data types and how we can give the variables values. In this lecture, we were discussed a cooked step force under the mean body of our program, a gentle reminder to you the viewer to copy the courts into your own matter. Editor. If you're free to post a video if you that I'm going too fast, let's start by talking about this function here. Voice on start. Just like variables, functions have data types to, as indicated by the blue lettering of the voice. In this case, Voight means no specific data type, as this particular function does not need to store or transfer any detail. We will start our main body with an open curly bracket, which looks like this for all functions. We need to place our courts within open and close curly brackets. Office line, of course, is to change the value off our X bearable, which is done by typing X equals 22 semi colon. This line changes our X from 0 to 2. Any time we assign a new value to a variable, it overwrites the previous value signal when doing programming we need a variable to be on the left side off the equal sign, even though we understand it. If it's written, S two equals two eggs. The computer does not, and you were given area where we are compiling it the next I is. Why equals to fall? Which changes? Why? From 0 to 4, This is followed by Zach equals two X plus wine, which means that will be equal to two plus four, which is equal to six Now introduced another basic operator in programming, which is the if else, operator. If operators tell the computer to do something, if a condition is true, otherwise the computer would do the thing under the else operator. So how do we used if operator type if and the worst was short in blue, then use an open bracket sign like this and please her condition within the brackets. Please remember the key in the close bracket. Sign after your conditions complete like this. Let's take a look at our condition within the brackets, which is meth. More method is one of the custom functions which are butte into metadata. In order to know, why does we need to use to helpful. We can use almost hold left, click and highlight the work math more after their go to help click on em. Cure for reference. The NPR for reference Help file pops up, and it explains here that meth want is the function returns the rial remainder off division off two numbers. His perimeters are value and Danny, too. Perimeters are input values, which in layman English it means we need to put in value and value to into this function. For it to work. We can see that this part here that value is the diffident and value to it's the divisor. So meth want takes value and device it by value to and returns to remainder. This ravine there will be off data type, double issue can tell via the blue. What's double on the left off? Met what year? Not every on the sand math. More. Let's go back to our script. Our if condition is math more and within the open and close brackets are sick and to similar to how we use brackets for our ive condition. We use brackets for custom functions as well, even if the custom function has no need for input values who still need to place a set off open and close brackets after the functioning. We want this break its metadata, can't recognize it as a custom function and returns errors. As the helpful has explained earlier. Meth Want here will take Zack and divided by two, after which he returns the remainder off this division. Now we see this double equal sign and it is double equal to zero. Since there's something new, let's check out how far again. For some reason, it doesn't automatically pop up when a highlight it and choose m care for reference. But we can always take double equal sign into such index and press enter. Doing this brings up the operations off relation. We can see quite a few operations of relation, but let's focus on our example with the double equal sign, which states here a W course be semi colon is true if a is equals to be going back to our meta deter and putting all the stuff we learned in the past few minutes. This if condition means we take the set divided by two, and if the remainder equals 20 this whole condition will be true, there's quite a lot to digest. So now what happens if this method condition is true? The computer would do the instructions that comes below the condition. We use open and close curly brackets here in order to have more than one line of courts. When the condition is true, the company will perform all the instructions in this set off open and close curly brackets . Since the first to line our comments, the only line there'll be performed is this print The value off that is Kama kept as a comma which is even as the function name suggests, print is a function that prince the sentence. The sentence will appear in one of the sections in our meta trader for platform as print is a custom function just like math more, we have to use open and close brackets, replace the sentence we want within these brackets. And we didn't open and close inverted commas like this To print the variables, we need to use a comma place. A very bunny and another committee separate it from further attacks. Any takes after the variable has to be an open and closing, but that commerce again after this explanation. How this particular if operator works is this. If there is an even number when divided by two, you will give remainder equals 20 Hence the computer will print the statement. The value off Zach is so and so, which is, even if that is not an even number. The remainder would not be equals zero, and the else statement will be printed in state. Okay, so we have finished going throughout codes, you know, to make this my script, something that we can run, all execute. You will need to compound it More program cuts from the matter. Deter will need to be compound before it can be used. Any Arizona Syntex of the courts will also show up during compile elation. If you find the lessons useful, please feel free to leave a favorable people. In the review, you can indicate what you liked this light or what I could do better. Any feedback is much appreciated 8. Section 2 6 Compile our script,debugging, using the Script (noise removed): we'll come back to in a lecture. In the previous lecture, we discussed about the main body of our program. My script. We talked in detail about how the use. If operators functions like meth more Prince Andy helpful. Now we will have to compound our my script, and we will also develop any arrest that we meet during compilation to compound. You need to go to the top and click on this compound button or F 70 s a shocker. Any errors during compulsion will appear at the bottom under the aerostat. It shows which lines are those of errors. If you double click on it, we will get directed to align with a writ sign that looks like traditional stops night at traffic crossing the era sees X variable already defined. To understand this error, you first need to understand that for programming, we can only declare our variables once. If you declare the variables more than once, they do not overwrite the previous decorations. In this case, the computer gets confused and returns that era. We can see here that we have declared X, Y and Z twice as indigent, so we can choose one of those decorations to keep. In my case, I would choose to grow out the first tree individual decorations as comments. With this done, we can click the compound button again and a similar self Harris appear. If we double click on the first era, he gets us to the line. Integer X equals 20 semicolon. This one is also a decoration off the X variable. Just that it does the editors of giving the variable of value since we company declare variables ones I would choose to keep the last line here integer X comma Why Comma Zet equals 20 semicolon. Let's grow the rest by placing double back space in front of the airlines. With this done, let's try compiling again when you see the falling messages. My script dot mp four zero errors zero warnings. He means the compilation is successful to use the script. We can't use it here in the metadata. We have to go to top left, click on foul open data folder, double click on em Cure for folder. Look for my script dot ux for or excusable fouls for meta Trader for have to have the dot t x four extension to use the script. We got to move this fall to the scripts folder. I will select the phone, copy it, go into the scripts for order and piece of copy off my script dot t x for their fooling that if you meant to treat a four is currently running. You got to shut it down every started. Once the military before is running, look for the Navigator window on the left. If you can't see your Navigator window, you can goto top left, click on View and select Navigator among the Navigator Window Golden scripts. Look for our my script. Double click on it to run. To see that script has been run. We have to go to the bottom tepes among journal and experts because I have expert advisers and charts running. My script was activated on one of my charts, and the messages appeared in the expert step. It says here my script loaded successfully and the value of Zach is six, which is even after which there was an UN end and it was removed. Going back to Armitage Eater, we can see that the calculation of that was correct s X sequester to and why was full. We can change X and Y values and test it again. Let's change X 2 43 And why to 144. We will have to re compound my script again in order for the variables to reflect the new values. Let's click compound. And with zero errors, it shows that the compilation is successful. If you go to our meditator four straight away and double click on my script again, it's two shows that is six. This because we have to go to the NPR for folder and replace the whole found with the newly We Compartment script. For To do that, we have to go to foul open data folder. Go to thank you all for food it in the first day we look for my script dot yes. For copy, go into scripts folder Peace and replace that assisting my script form to make sure that Metro trader for reached the correct fall a recommend you to shut down and restart met the treated for after restarting less double click on my script again in the expert step. This time it states ZIC is 187 which is what showing that the updated variables book with this Will You end a lecturer and section here for scripts. Starting next section, I will talk about indicators, the People Point Support and Resistance System and how we create a new custom indicator to calculate and show those support and resistance lines. If you like the lectures and find them useful so far, please leave a review to indicate what you liked or this light so that I can improve the videos from your feedback. Thank you very much. 9. Section 3 1 introduction (noise removed): congratulations on completing the previous section. You should not be able to program, compound and run a simple script on the meta trader for platform. In this section, we will start increasing the difficulty and program our own custom indicator. Our indicator will be based on the Pivot Point Support and Resistance System, which is not included in Meta Trader four by four. In this section are introduced excellent variables which are variables that the users can change in the military before platform. We were also abusing quite a few custom indicators in our programming, showing how to use custom functions to calculate our people point values to draw, delete our support and business insights. 10. Section 3 2 Pivot point support and resistance (noise removed): welcome to another lesson on creating our own custom indicator. So, as mentioned in the in the introduction, that will be creating an indicator known as people value or pivot points apart resistance system. So basically, for this system is still calculating support and resistance lines based on a certain self populations. And ah, these calculations are caught. The pivot points and the people points are calculated using an average off Senate comprises from the previous session. So the values will be using are the high, the low and the clothes off the previous session. We'll show here the falling calculations that were used to calculate our people point. So pivot point is, many calculate that using the close, the high and the low off the previous session. So you talk about this tree values and you divide it by treat getting an average value so this average value is known, asked up even value and the rest off the resistances and the support our color are calculated based on this people point value. So the values for resistance level one, as with reasons left to our own, are toe are shown there. So a support level one and support level toe are shown as well. So for most people want there'll be the level tree support and level three reasons as well . But for this lesson, to keep things simple, who just focus on level one and level two. 11. Section 3 3 Declaration of Variables (part 1)(noise removed): So let's start coding for this one Will just call this new indicated up, even as are indicated. I mean, sir pivots apart Resistance indicator. So you can actually start a news indicated scrip And I just as you do show you guys here. So in the top left hand corner, just click on new They will be the end cure for visit So in this case, you choose a custom indicator. Thanks. So we can justly for this blank You just need the name of the educator. So maybe you'll just put ive It s, uh, indicator link. So it's up to you. You can put whatever name you like They just click on next. So you would need to include this on calculate So later explained with its own conflict to you. Click on next, Justly for this plank and quick finish. Yeah, So you have ah, blank indicator template here with just the function on inter and on calculate. So I have a complete at once here and you can see that she would just put the name on top. This is such Justin within the comments so the Kampala will not compound his name. And so OK, so let's move on to explaining our our first custom indicator. So anything about the indicator you think about a pivot point indicator? How are we going to display all these values on our chart? So first and foremost is that we already have our formulas for the people points. You can actually find this online. Just go go for people Point Support and Resistance System and the the mine Arctic Ocean show you a series off calculations. So we have the car. So really have our calculations here, whereby the people value is the tota off the clothes, the high and the law taking all these values together divided by treat. And then you have your our to our one us one as to following the formula step. So since we really know the formless for this Ah, what we need to do is to chocolate or this individual values, store them in a variable and then display this particular value on the chart via a straight line. So we we need to draw the lines as well as a little kid names to the lights so that we were no wish line, Mr Pivot Point there, which line is the level one support and which line is a level to support. So so it's creating the variables to store The values are quite simple well used a variable double. So you see here in our decorations sections here so we can use double and then we are locate using you can name the variables whichever you like, but for me are just used to evening shows off each, like see for close hitch for high L for law P for people point are one for resistance one ir two for reasons to and so on. So for me I named it in a very intuitive way that is very easy for anyone to recognize. So why the value double? Because all these values, they were going to be there small points, especially on chart says Well, so for each of the values there'll be decimal points in particular For my USD Japanese in charge, I have up to three decimal places, so definitely we have to use the value double in order to store this information going back to our new path. So how you gonna generally ideas? You can just open up that note, pet you can just right click on your desktop and start not pet and start writing down toe ideas. So there, in the process of making your algorithm making or indicator or your expert advisor or forex robot, you can just refer to, you know, pet to see what the general floor that you decided. So, first of all, most already wrote down the formulas for to calculate our respective values, so I actually will need. So I need to create Darabos to store these values. Okay, then we need to grow lines off these values, give them names and color. 12. Section 3 3 Declaration of Variables (part 2)(noise removed): so creating this very both I mentioned is pretty simple. Just set that in their question section just set double, then named the respective section. So because I do not need to allocate number values to them right now, I do not need to set them to zero. So I just So I just declare them and leave them. It's blank. Then, within the decoration section that I were introduced, our first extend bearable. So here we have this particular decoration extent e x tr n then indeed Europe, even on this score timeframe. So my variable name is caught PVA on this core timeframe. So the extent variables are very useful for adjusting certain values out off the meta data . Because for my people value chart, I don't want it to be just a chart where can use it. Let's say on a weekly system, I want it to be adjustable so that I can use it on a weekly chart. I can use it on the daily chart for our teacher and so on. So, in order to do this only a variable that can be adjusted when I'm outside off the method utopian in nature itself. So just showing you how the variable works. So this is my USD Japanese yen shot where I really have the my people point indicator working here to display this certain verbose. So in your meta trader platform, you can go to indicate this list selected. So this is my indicator select. I did. And you will see here the very book people timeframe so I can double click your and I cash a justice value. So by adjusting the value, you actually display a different time frame. So let's see if I want to. Dealey. He's so in the num timeframes. If you go to method eaters mq r for helpful and you look under the num timeframes, you assure the various ended your values to switch to to display a different time frame. So, for example, the 43,200 it's actually forward a monthly timeframe. That means I'm using the previous month's values in order to complete the support and resistance for this particular month. So if I want to use the previous week's value to complete support and reasons what this week, I just need to change it to 10,080 So just show you here. So this one is actually displaying using the previous month so you can right click on the chart. Go the indicator lists. Select indicator. Tow it when the value Here, let's change it to 10,080 and you'll change it to display the previous week. So the is that previous using the previous week's value. So there's a support resistance for this particular week, so you are under used to daily values. Instead, that means it's 1440 same thing that's adjusted here. Okay, so this is based on yesterday's value to complete the support and resistance for today as well. So you can see this a lot more narrow and smaller. So he says she using yesterday's value to operate the squad residents for to the is practical today. Okay, so these where extent variables are very useful because extend means you becomes an external variable that you can change in order to suit your needs so that you don't have to come into meta detach changes values. And every time how you did declare Exxon variable is just the same way as you declare a normal variable. So let's say if we were to clip Evert time frame. We just put I anti space PVA on the score. Timeframe equals to a certain value, but I just put the extent e x tr and before they ended your type well before the tight tight in general and you will become extinct bearable. 13. Section 3 5 Custom Functions (part 1)(noise removed): so moving on right now, we're told by our custom functions. So let's refer to our earlier layout in our note pet. So after we've created the variables, store the values for the people values, that's where support and resistance values. I will need to draw the lines off these values. So in order to draw the lines, I'll start by introducing you to our custom functions. So basically, as mentioned in the earlier chapters of custom function, is basically a function that we create ourselves is contained a certain amount of court. And whenever we need to call for that particular set, of course, we just call it a particular function name. So in here we have a few custom functions we have avoided. Delete lions void, calculate people. Voigt draw lines indigent on end as void the into an indigent on couple. So all these are custom function, names said. We'll go through a few of them, so 1st 1 is our avoid delete lines. So the ley lines it's actually a custom function that I created in order to delete the lines. Once we have quit the indicator or removed the indicator. So what does the void here means so for functions actually very similar to variables. You were half a data type for that particular function. So just like variable can be off type, double or type in digital for the functions UK also be variable type double or tightening the jury as well. So if you have a certain data type for particular function, it means that the function conduce a certain amount of processing and then it can export. Ah, certainty. Time off that the attack. So let's say if we were to put in didja delete lines, that means delete lines can do a certain amount of calculation and it can actually export certain data value days off attack, indigent. But in this case, for us, the D Lions function is only used to delete lines. We are not going to export any data values out of it. So in this case, since we do not need to have any data type to be exported, we can just leave it. As for your I d. That means there's no the type for this particular custom function. So if you take a look at what is this function objectively? Ah, you know that the Norway's objectively. You can also use the help file. So there's a particular convenient permission off the M cure for helpful. You simply double click on objectively name. That means you highlight the Arctic lower function name you go to help Goto thank you all for reference and you will see here on the right side they will have selected for you object elite. So the exponential and everything is ready here. So there's saves you the time of typing objectively in the search for in the search box. So repeat the process again. So I just need to highlight the particle. What? That you want to such helpful with the help Quicker M cure for reference and is done The Walla it pops up here. So it explains here that objectively is a function that removes the object There specified name at specified Chuck. So they had to variance and so on. So explains that objectively is off the type bullion and then you can input. Ah, long type. Just the name of the church. I d a string type with his name off the object. So this side, they are to input variables steak you can put into objectively. So these very in one or you can actually have a second variant. That means it can just input the object name usually of type string into objectively and it's Danny removed. That means you don't need to put in the Chidi. So these out of two parents. So in this case, I'm actually using the second er in here. You will see that I just put object delete and I put the object name their meetings in this the first line Amum object. I'm deleting the object caught people lying second line of deleting object caught s one lie Then that I am deleting object as to lie and so on and so forth okay and then referring to I will not pet again. So we will also need to do certain them off calculations in order to calculate what is the pivot value the support resistance values it's on. So I created an unaccustomed function caught void Couple it people You know that a couple of all of this. So for the close value home, how are we going to get the clothes? The high in the low? You can use all these functions. So let's say I don't know why I close. Just highlight. I close goto the ankle for reference and help our show you So I close will return the clothes price value for the bar with the specified symbol with timeframe and shift. It's a pretty complicated explanation. In simple terms, I close simply returns to you the clothes value off which ever bar you want. So how are you going to stay at the BIS? You're gonna express it using shift. So later Problem. I can probably ah explain to you by a simple chart showing the shift numbers. So it is easier for you to understand. How are you going to refer to the previous close values? So I close is off. So the export type for I closest double that means you will export that certain value with the taboo data type. Then why the things you need to input into it? The 1st 1 is the symbol. You need to input that time frame and need to input the shift number. So in this case for the symbol, we can actually put the wood Now it means the current shot there were there were using right now. So so in this case, you don't need to put in the specific symbol like us detected the seven. So just put now will do so for the time frame is the similar. Just already explained that you numb timeframes. So in this case, really have a variable to start our time frame. So we just put pivot on this score timeframe our variability for our extent variable. So this will actually specify the time frame that we want to use. And the top one will be the shift number. So shift number one. It means toe Previous bar zero always means the current bar where one would mean the previous bar and two will mean the previous two boxes on. So for I high and I law, it works very similarly toe I close for example, if you were the highlight, I Hying good with you. See, a very simple explanation just gives the high value off the previous about previous boss and I Lewis. Well, we'll give you the low value. So how we gonna calculate the close? That means we use this I closed for and they express in this way. So we're getting the close value for the previous bar. Then Hitch is a good toe. I hired so and so for forget the highest value of the previous bar. Ellie goes toe ill will get the lowest value off the previous part and so on. So really explained our formulas earlier. So P you can just use p equals two C plus hitch blast l then everything within a certain set of brackets divided by tree. You get a rich people value and our to our one and so on. So for completing language, you have to use the sparse symbol in order to express multiplying and plus and minus are the same symbols s for usually a couple. 14. Section 3 6 Custom Functions (part 2)(noise removed): Okay, so now we're continue explaining our custom functions. So going back to our earlier plan, Leo. So I need to need to draw the lines off the well. So now really calculated. Ah, falling pivot values expressed support, resistance values. And we have stopped them, meaning the variables. So we still need to create eat the lines That means draw the lines and give them color and set names to them as well. So in this case, I have actually created a custom functional draw lines. And I put it to the attack voice as well, because I don't need to export any particle a data from this function and we are used ah, custom function object create an object set in order to create the falling lights. So wise object create. So as usual, just I like they're falling would go to help select mq oh, for reference and help, I will pop up. So it explains object. Create year basically creates an object of the special fight name. And so it took off. So you see the object created softie that type bowline, which means it's only either true or false, where they create subject successfully or not, And you see a long list off the types here. That means you do have to specify quite a few things into object. Treat the 1st 1 being the Chidi, then the 2nd 1 being the object. Name yourself type string object. Type the sub window if there is. Was that the end time of the object if you need it. So the price reasons a type double because you need to stay which price or creating the object. And then there's more the time and more price if you are creating the object using most of them. It's not just one price value but multiple price values. But in this case, we're creating a straight line, so we do not need to input so many data types in there. So if you actually refer Teoh, this one, we're just simply creating using. So we're not gonna have the Chidi, so we'll just leave it blank and instantly will go to the object name. So in the case, the first subject al crea, is my private line. That means I do object, create, and then I put so as per usual. If is if you're using string the attack you have to put the spring in open and close inverted commas. So this is the pivot lying people. Lying is actually the name of the object. Then to set it to the next data type would just put a comma. So it just helped far. Always here. Okay, so the object type is listed here at o B G underscore hitch like it means object. Horizontal line. Okay, so after object horizontal lying, you have to set the coordinates with online. So the coordinates in this case we have 00 p. So the court is for the lions set here under 00 p where P is the people value. And then once we have created object cut people lying, we need to set a color to it. So we used to function objects set in order to create our color. So Jake said basically changes the value of the specified object. So you have to object name, and you have the property index and the value. So in this case, we're going to select objects set and within this will select our objective and copy, but like, and things that were going to change his object property and the school color. That means we're changing the color off the globe object. And we're changing this particular color caught like, see green so you can play around with the colors. They are actually a whole host of colors there that you can actually use insight, meta trader or meta data for your different objects. So this will create our first people line, and then I have to create our s one my as to lie as well as R one and R two lines. So following the same example as a both our name mine s one line so object horizontal line and then said as 00 and value s one. So for my s one, like I said it to color it then as two lines the same the cordis as yours. Us too. And there are said to Riesco and for our one line was said it too hard on July at 00 R. One said it to Dodger blue, and our 02 said it to torture. Blue s well, so if you free the change play, you can play around with the different colors. You can set it to be sharper colors that you like. So, for example, you would like to change the color you can select select Dodger Blue, and I go to and cure for reference. So it's Tony pops up with a whole host of colors. This are what we call the Web colors so you can set it to any of the colors here. Yep. So the name of the colors are listed here. You can say to color it or just put it. That's right. So the see, you can actually skip the word CEO Ira, for example. You want peach puff so you can set the color to change this Dodger blue. The peach perfect want to or you would like turquoise instead. Total coins. They can just copy pale turquoise and replace it, Replace it with thought replaced a Dodger blue. What? 15. Section 3 7 Main Body (noise removed): So are they explained the first tree. Custom functions. Delete lines calculate people as we're strong lines. So another explain on int so on into is a shot form for on initialized. Initialized means that when you start the program or the values are reset or in computing terms of quite initialized, just just a complex name for saying that, yes, starter and reset. So there's off type that indigent. That means, ah, on starting the program will do the following things inside. And so, as explained, the earliest great will need to use our open and close brackets. So in the other functions you will see the open and close brackets as well. So using the open close brackets the 1st 1 when we start, he's output of function. Defeat lines, many because this I need to reset and clean out whichever lines I have previously on the chart. So when I start, I clear out the track. First, I use delete lines and then I'll call for my calculate pivot to complete all my people values and then our print the fooling words that means our pre moister clothes for the previous month, the high or in this case. I put the name previous Munn because my default value is choose the institution of monthly value. But of course, once you change the in, um, timeframes, it doesn't just display the previous month he can display the previous week's value or the previous day's value, and people values. It's so it's so cough. So calling functions is pretty simple. All we need to do issue just talk about the name off that particular function and Carly not there. You need to put open and close brackets here as well. So open and close brackets, if you don't have any value insight this bracket, it means that there's nothing that you need to input into that. There's no data type that input into the particular function. So please note that for calling functions, you will always need the open and close brackets here at the end off the functioning. Okay, so at enough on in there will always be return in succeeded so you can just leave this line . But this particular line here, this will actually return a particular value to our program that says the initialization, they succeeded, But you just can just leave it here because there's not something that we need to concern yourself with. They will have another function called void the int. So if you actually select the in tray and you goto our thank you are for helpful, you'll notice that it cannot find anything like try searching for the end. It says No topics fall because D. Inter is actually not specific to the matter. Editor language. The intense actually from an ad, a programming language caught swift S W I. F T and the Meta data Comm Paolo is actually Butte from eso caught a combination off various languages such as C language as well as truth, programming language as well. So the end is not unique. It's not unique to the method. Is the language show there's no help file for it. If you go online and you search for the U explained that deviant is basically function that will execute everything when you quit the program or when you terminate the program so it's got. In other words, it's a shot form for what the initialize. So you have the only initialized s that and the D initialized for the end of the program. So we need is the in here because we need to delete whatever lines that we have created in our earlier indicator. That means when I removed the indicator that the into a call for delete lines, we should delete away all the previous lines to after on or when I quit the program, my clothes off the screen close off the window as well that the intellectual will call delete lines who should actually remove away orderlies as well. So you're make our chat nice and clean, so falling out the into we move on to our main poke, our main function off the indicator, which is caught on calculate. So if you select one Khalkhali and you go to the helpful, so there's a very lengthy explanations here. What a custom indicator that it's necessary to copulate in care values by a couple of events or himself off. So in layman terms, what on calculate does is that it does a certain set off calculations on every tick one tick, meaning every second where our for acceptable will pass price information toe our meta trader for platform. So on calculate will do a calculation on every tick and on every tick you were actually run . Our indicate that you calculate the values for indicator and you you will do accordingly. So basically, for E A s, we will be using a different type we will be using on tick your school in the helpful here . So four expert advisers are for actual but later will be using on tick That means on every tick. Of course, there are certain functions like on time on tester on even, but for the scope of this lesson will not be touching on this. So on calculate are generally used for indicators. That means on every indicator you used uncouple even in order to do all your calculations and to display your stuff so on on chocolate. So we open and close colleague brackets and then we will have our draw lines time. It's on every tick. How actually be copulating on everything actually be drawing my lines. So whenever the lines value change, right? So let's say we change our time frame from a monthly to a weekly. So you were detected on the next tick. There are calculations are variables have changed and you draw a different set off lines. The same will happen as well. If let's say is on the day d time frame and you're just going into the next day, the values for variables would change and you will redraw the lines on the next. Then there's also returned for reuse. Toto. So this one, the return value, you have to leave it here as well, so this is necessary for the function to work properly. 16. Section 3 8 Compiling and using our Indicator (noise removed): Okay, so I hope that you have off as I followed the lesson you have tucked in all the variables and every function name as a clear line for line of the same syntax into your own compound as well. So now we'll do the compelling. That means we will compound this so also kicked pump All So he says people, as our indicator has been composed successfully. Zero errors. You're a warning. And let's look this compiler into our method trader for platform and see how it works. So in order to load it up, you can go to found opened a tough order. So now for the here you have to select mq r four section. So look for the name off our particle indicator. So I take it that is caught. People s are indicator dot Exe for I would you Ah, copy. Don't go to the indicator photo and I would do a piece replace my orders. You follow their So in order to test our indicator will use a blank trap. So let's use this Euros fish f shot. And how you gonna find your indicators? It's once I've loaded into the folder on the left hand side, you can open up your navigator, which you can open on view and select the Navigator or Quattro end. So once you have this navigator window open under the indicators, expand it scroll down. You should see somewhere here the people aside indicator. So is categorized Alfa numerically, so just click on it. You can drag or you can double click, and you have this. Pop up your custom indicator before indicator name, So on the common just tick. Check the chicken second box on the input you can change. Used to be scheper in, um, time frame that you that you want. Whether is it a monthly, weekly, daily or even hourly and the colors are just leave it as a default colors because it's not really important. And the visualization just leave these two boxes checked the enough time frame that we select that is for the monthly value. So is using the previous month's close, high and low to calculate the pivot supporting the says values for this month. So you do see that uh, yeah, it seems to have a certain bounce, so maybe we can kind of consuming photo, so you do see their days. Ah, bounce off. That business is one value for this particular month so far. And then I say I want to change it for the previous week. So just by changing the child, I can see the week and I need to select my indicator here, right Click said. I indicate this lists, so let's go back to the numb timeframes, selecting the time dreams so on to the previous week, the value of machines to 10080 Let's quantify this to 1000 and that's elected to select close. So now the values who have changed. So this will be the support reasons, values calculated using the previous week's value. And you can see that for this party, Chloe Sims style. The price has bounced off our r 02 or this week as well. That means our resistance level two. So what if I want to check it for the previous day and let's selected TV time frame? Yeah, and that's modify it. Get this said it. And earlier, you know, timeframe. For one day we will use 1440 less changes value to 1440 select. Okay, So close And the values have changed again. So this prevents apply resistance is copy using the previous day's value. Okay. And it shows that for this but ago trading session, it hasn't really touched any off. The support are one or twice as one. Maybe he was close to touching the Arab one, but you didn't really hear it and I went back down. Okay, so now we're really completed our custom indicator. And thats particle indicator is caught The pivot values, support and resistance system not usually it is not usually available. Incitement a trader. So this just goes to show that hurricane we can program our own custom indicators in maturity test. 17. Section 4 1 introduction (noise removed): from regulations are completing the previous section on custom indicators. You should now be more familiar with custom functions, extent, variables and be able to program people Point support Resistance Custom indicator in this section will finally stop running out for extra body or as the community calls it, expect adviser. Or he's well shot will be using a simple moving average cross four minutes of trading system where we entered treatments that faster moving average process is over. In terms of algorithms, I'll show you yet again can use a simple to like no pet or brainstorming and to start our according design process, how we use custom functions for by itself it's and how we use variables to control health frequently, our explained by several tree and end of the section, we will bet Tessa Expert Advisor show you have to change the settings and extend variables so we can test on a variety of time frames and different Regency House 18. Section 4 2 Moving averages and trade signals (noise removed): in this section, let's talk about the moving average trading system. A moving average line is simply and lying from from linking the averages off a state at number off pass, oh, soon as spirits, the spirits can be hourly daily, 30 minutes for hourly and so on. Each data point is an average off a state of number off periods, for example, you can be average of the previous 20 periods as a sign is moving the line ginger slightly . If every new completed period because we have every new period, your rich coalition will change slightly. There many variations of calculating, moving averages. We can base the average off the closing price, highest price, lowest price or even the median price values. And they also a few ways of calculating averages as well, such as we can use the simple method exponential or the wheat. That moving average calculation system. The keeping simple moving average crossovers are where a faster moving average lying crosses a slower moving average life by faster, we mean an average line. Using less spirits by slower means a lying create it using more average periods. For example, a line off 20 periods is a faster line then compared to a line off 50 periods and so on. Hence, moving average crossovers are usually used to determine if there might be changes in a price trend or if a new trend might be starting up. So treating signal will simply be a cell or short order if the faster line crosses below. The slower moving line and a bio are long order if the faster lying crosses above this local line. 19. Section 4 3 Pseudocode our ideas for our EA algorithm (noise removed): From now on, I'll refer to our for extra, but also known as expert advisor Bias in shows e a. Captain Ian Captain A. It is commonly referred to in the M careful community. So how do we stop programming our e? What courts are functions to be used? In order to start our brainstorming process, we can use our trusty window snowpack ticket. This process can be referred to as pseudo cording, where programmers first thing about the according ideas in fit coats, which do not to follow the syntax rules and are more easily understood by people first. Resting of what external adjustable variables we might need in our year, we would prefer to have our moving average periods to be adjustable. Hence we need the extent very both forward, faster moving average and another ex unbearable for a slower moving average. We will probably also prefer to be able to adjust our motor calculating our moving average , whether we want to use simple moving average exponential or we took moving average. Let's create another variable for these as well. Trading wise, I guess most traders would probably also prefer to set their own, take profit and stop loss values. So let's great two variables for these. Okay, we have set up most of the important variables. Let's think about our trading conditions again in the very video. Actually talked about the moving average crossover where we buy where the the faster movie average crosses upwards off the slower line and we sell when the faster moving average lying crosses below the slower life. Let's use simple if operators to express this. If faster moving average crosses above to slower moving average by if faster moving average crosses below the slower moving average cell. With this Mpasu. Because we have the general idea for our E, let's proceed to cook this indoor metadata in our next lecture. 20. Section 4 4 how to start an EA declaration of variables (noise removed): Let's start a whole new expert advisor in matter Editor If you go to the top left quickly and fall, click on new and you have to Mq Oh, is it? Follow here. So select expert advisor Next delete can really alter and link. It's not important and you can even anything you want. But let's name our expert advisor m a cross e blank and since separated before I was just talking directly farming. You have a choice on time on child and leave this to blank click. Next on Tester Leavitt Blancas Well, and click finish. So we have our playing template. Yeah, yeah, with the functions on end, the end and on tick are not terrible to my complete expert advice. And true why the variables that use if you free the change of arable names to anything you like? Personally, I prefer to have my very Bo's name very literally so that it can easily remind me what they are just by reading their names for sun will be magic number Very well that we used to identify the traits that our expert advisor has. Meat is useful when you won your expert advisor to modify treats Later, as we can say I expert advisor, to look for this particular magic number to find the particular order or the particular tree. Sometimes we might be running multiple E ASR motorbikes, but advises on our meta trader, which are creating multiple treat orders or we males McKeon. Some manual treats ourselves when it comes to modifying treats. It can be a disaster if e. A's modified traits that are not their own. Imagine having a manual treat there was working out well and could have a new a few $1000. Instead, your E a modified your manual tree early due to a lot of this identifying magic number, and your trip took profit at $100. Instead, that's instant loss of thousands of dollars. Next up we have our variables fast mea on the scope here it and slow Amy on the scope here it which are self explanatory just based on their names, the help us to set the period numbers. So I said the fast Pierrette to 20 and this little peer it to 50 dessert default values. Since this is extent variables, you can change them later. Want to have your expert advisor Compound Variable Emmy And the school method is my very best for selecting which averaging not to use, whether we're gonna use simple exponential or wheat. That calculation method for moving averages You are questioning why I usedto indigent? It attacked for me and s committed. I'll explain this later When we go to the function I am me Variable stick profit peeps in stop loss pits are self explanatory. Yes, well being the number off peeps for take profit and stop loss respectively. So for default, I'll set them to fire it pips for now as the exit variables, you can change this any time. Variable order size will be the very before us to select a lot size for each street For this video actually will ignore the timing related variables such as minutes portrait free to treat total minutes minute different show our differences and ordered it for now. I will explain why we use them in a later video lecture. I've met four variables for all moving averages. Fasten slaw, Emmy. Ah, self explanatory. Then it's wise for faster ways for slower. Why would have variables for the current Emil I end at a set for the previous Emmy lines for this one are you send that picture to illustrate to you. How do we determine if a line has crossed over? One way I can think of his detect if the current faster line is below the slower line and then do another check if the faster line was previously above this lower life in order to do this only itself. Variables for the current Emmy values and another set off variables to store the previous Emmy values. 21. Section 4 5 custom function (part 1) (noise removed): now we should be moving on to our custom functions, be prevent for a few lengthier video electricity and still be quite a few courts and subtle things Our explain I created to custom functions for our buy and sell orders. There might be situations where we might use our buy and sell orders multiple times, you know, mean body coats. This is a make it convenient to repeat the buy and sell orders in our main body codes. It also makes it easy to copy these functions to your other E is in the future. So you do not have to re type all reading the courts for by and so on this for our bio long order. I named it literally s place by order. And of course, you need to include the brackets as well. We've data type his voice as we do not need to process and transfer any data off dysfunction. The custom function order send will handle order processing for placing our tree orders. Hence, we do not need to transfer any process data out from this custom function First week need to set our take profit and stop loss values as traders. I'm sure you're aware that any treat orders will have a bit aspirin from your forex broker as this. How do you make money? So for by orders, we're placing our orders at the ask price. Wherefore sell orders? We're placing our orders at the big price for my place By order. Custom function. I will set my take profit price as US plastic profit underscore Pips multiply by point Stop loss Our said it as us minus stopped lost on this score peeps and multiplied by point where take profit on this carpet and stop loss underscore pips are set in our extent. Variables. Let me take you a bit to explain the custom function Court point. If you have, like the work point and go to m cure for reference helpful, it states the point size off the current symbol in the court currency. I will do a more detailed explanation state if you go for the explanation off point in trading terms, it refers to one New America increase left off the decimal place for grip it in Japanese yen. A drop off 141.62 140.6 would be a drop of one point in meta data Point function is the value off one divided by one point for that particular for its symbol. As traders, we understand that one pitch is the smallest number movement off currency pair, Let's say for group within power Japanese Year, you meditate before one P, divided by one point, goes to fourth decimal place, which is 0.1 So the point function used on gripping hunch apparition would give Use your 0.0.1 which I'll show you. Here. You can see that it goes evolved decimal place for repeating pound champion skin. More complex explanations of sight stating your stop loss and take profit in number off pips, then multiplying it by. The point function in metadata gives you the exact price value that you want to adjust your symbol by. For example, I bought group within part technician at 141.600 I want to stop loss to be firing Pips. So using 500 multiplied by the point function, which is 0.1 would give me 141.600 minus 0.500 and my stop loss would be at 141.100 exactly 22. Section 4 6 custom function (part 2) (noise removed): moving back to our workplace by order. Custom function. Hope you understood my explanation for the point. Custom function. The variables take profit. Stop loss and their values are calculator in the decoration section off this custom function. Next we will declare the variable ticket. We have the data type integer asked the following order Sand wave of love technical give bridge in the brackets. To understand this, we will need our trusty helpful again Hi orders and go to help and select a cure for friends. Addison is the mean function used to open market or place a pending order. It is off data type, indigent. First perimeter Within this bracket is the forex symbol we are treating. For this, we just quote symbol open and close brackets. This returns the current for X symbol off the chart. The is on next perimeter is the operation type. Click on tree operation in the help file and you will see on this table. What for? Extra officers we can use for now, we're just using Opie on this score by as we're entering by treat here, you can also quote their respective in the your values as from the table in the helpful next Very. But we have our order, size or number off lots. If you remember in the early lecture, we have our number a lot in the extra invariable orders size in the beginning off the decoration of variables mix up is order price as explaining the only video lecture due to the B aspirin, We are placing our by or the at the ask price for your information. If you type us capital A with small it us sk in metadata. It is a custom function that returns the ask price off the forex pair at that woman. Experimenter is slippage, which is how Maney Peeps were allowed the order to place when it has slipped away from our actual ass price. We were set this to three peeps for now. If he said it to law to zero, for example, the order might not be sent if there's actually pitch from your broker due to Internet like or serve elect next to perimeters are stopped lost price and take profit price which we have calculator in the beginning of this custom function. So let's use it to very botia. Next is a comment on our trip, which I said to my order. You can name your order, whichever you like falling. This is our order magic number, which we explain a little bit. A lecture on our decoration off extend parables. This is the identifying number that we will use to know which treats are placed by this particular e A. We've said our magic number in decoration variables at the top off our E. We'll just used the variable here. The next is expiration time. We will set this 20 since it's only applies to four pending orders. Last perimeter is by arrow color. I said this to greenness my personal preference. Feel free to set this color to any color you like. Let's check out the return value off this function or their sin in the help our it says Retton's number off to get a sign to the order by the treat server or minus one. If it feels personally traders flying it useful. The uses return value to check ways to error if a tree it feels to be set up by the forex robot is why I used the following If operator, If ticket is negative, represented by ticket less than zero. Print the following message order. Send fit with air attache. Get last era. We've opened in close brackets where the function get last error will return the error number and you can use this error number by referring to the help file to find as that reason for the failure. If the ticket is not negative being that is positive, it means the order is successfully sent to the broker and the system. Prince the message order send place successfully. We show you know, the falling courts free to trade. It goes to falls and order they because time covering For now, I'll explain them in a later video lecture for the other custom function, place sell order It is pretty much the same as placed by order just that we reversed a tick profit and stopped lost competitions. We will be using big price to place our so order as we used to us Price ful by Otis in the others and function will use OPI underscore cell in stay off Opie and this go by for the seller Aero color. I preferred it said it to writ, but few feed. They said it to any color that you like. The F operator is basically a copy and peace from the previous function, and it works in the same way. 23. Section 4 7 main body (part 1) (noise removed): in this video actually show start going through the main body off R E A and the courts under the function on tick on to end and on the in has been explained in the previous section when we were creating our custom indicator for this particular year. I'm not using these two functions, so I'm leaving them blank. You can choose to delete both off them. You feel like us. They will not affect the operation off your year. The function on take is very similar to a NCAA clip from our previous section on making our own custom indicator. It executes the coats in the function on every tick shtick is usually one second when your frank's broker updates and sense the latest price data to your meta trader for platform we see here that I'm assigning values toe are four moving average variables using the function I m e This refer to our trusty helpful again to explain what I am. Eat us how late. Do what I m e go to help and cure for reference. Okay, and you will see to help follow here in the Hellfire, he says calculates the moving average indicator and returns its value and uses the data type double for his return value going through the perimeters. The 1st 1 is the forex symbol. We can use the term now here to reflect it. Refer to the current Sinbo off the charter. E. A's on timeframe refers to whether the charges using five minute bars, one hour for our bus and so one we will set this 20 to let it used a current period off the charts. Emmy and a scope here it is the averaging period for calculation in our extend, a crucial variables. We have set our fast m appear to 20 and the slow em a period to 50 situs extend variable. You can change these values to any other periods that you like. We will use all variables fast Emmy and the scope Here it and slow Emmy on the scope Here it for the perimeter Emmy period. EMI Schiff is similar to church. If over this number shifts the entire moving average lane right instead, Emissions zero is the current Emily, with a mission of one moving the Emmy lying one period to the right EMI shift to is moving the Emmy lie to periods to the right and so on. For our expert advisor, we will use a mission. Zero for all our Emmy calculations, let me underscore. Metta is to let the trader choose the method off calculating Emmy click on the INA meme emitted, and you can see the interview value for each more going back to extend variable decoration for M A on the score. Mt. This is why I said the variable to data type integer and I said the number 20 For simple moving average, you can choose any number from zero to tree to choose which moving average met that you would like to use. A play on disk or price refers to the price value you like. The area should be calculated by click on enema plaque price, and you can see that we can use a whole range from closing price Open high. Orloff The period two median Typical weighted price. The calculation for each price type is explained in the description box for now, abusing price on this score median for the final perimeter shift. It is similar to spirit shift in bass that we learned in the previous section in our custom indicator. We've zero being the current purity, one being the previous period to be in the previous two periods and so on. I will set the current fast Amy and current Slow Amy to shift number zero and set the previous fast Emmy and previous slow EMI to shift number one Lexi know the courts, for many underscore different to tota on this commune. It's on this card difference for now. I'll explain them in a later video lecture, referring to our sudoku. You know, not pickin. I will mean trading conditions listed under the two ive operate this to check if the lines have crossed recently. You know, other. If you do a lecture one way, we can check if the line has cross ears. If current on this score fast, Amy is a birth current underscore slow any we will check if the previous on this score far semi is below the previous on this course law Emmy. If both conditions are true, it means the fast moving average line has crossed the slow moving average line from below to above it. This would give us the by condition. To do that, we use please by order refill paying close brackets for our cell condition. We simply reverse the conditions if current fast moving average is less than current slow moving average read in check. If the previous fast moving average is higher than the previous slow moving average. This means that the fast moving average line was a birth. The slow moving average line and crossed beneath it. Demon s a cell condition. We will use place sell order with full paying close brackets. 24. Section 4 8 Backtesting (Part 1) (noise removed): before Mean body cause done. Let's compound year and back. Test it to see how it works. Our compound version of our e A with all the timing related coats Great up, meaning I put them behind two backs race parts to commend them so that the Kampala does not compound him. I will screw this version off M a crossover e A and time, which you will see I have commented or great out or the sections related to timing treats. If you have any syntax errors while trying to compound, make sure you go back to this part and post the video to see which small parts you might have missed up. Let's compare it here for back testing. The process is similar to running off script or custom editor. First, let's go to foul open data folder. Go to kill for Florida. If your eggs or flour is located here, copy them and paste them into the experts for order. After this is done, if your meta trader for is currently running, you need to quit the program and restart meta trader I once met. A trader is restarted for back testing. We will use the strategy tester Goto view click on Strategy Tester Oh, you can use his keyboard shortcut by holding control and then pressing our on the strategy tester. First, make sure the expert advisor is selected in the box here. This box is for selecting the year that you want to test. For now. We're select Emmy Crossover year and timed UX four. Choose to symbol. Choose to model. We have a choice off open prices, control points and everything as the name open prices only uses the opening price for off each period, so is not precise enough for testing some E is. But it is the fast assessing matter if your E a only uses the opening price off the period . Control points is slightly slower than open prizes as it uses the important prices off the lower timeframe. But it is too much faster than everything. Everything ISS most precise but slower says it basically goes through every second off the price data for our year back testing. Using control points should be good enough. Take the box, use it and selected it. Really Sure you want to test check the box vision more if you want to see the treats as the price bass develop. The slider controls the speed off the test. So our invasion, what we have left being slow us and right being fasters. Next, we can click on expert properties where we can change the initial deposit amount for testing and in the import tab is where we can change our extent. Variables. Periods where you can select five minutes, one hour daily chance for our charts. Etcetera spread is the bit are spread from your broker. Personally, I said it to 20 peeps, as I like to underestimate by profits, and I know that some brokers have adjustable spreads in some off. Therefore, express this on a means that things are usually adjust. You can try out the other functions as well. After we are satisfied before some things, we just need to click stuck to run our tests. - A PSA test is running. You can see an obvious issue where there are multiple traits when each trading conditions for few this because that each control point, once a trading condition, is true, the EU will enter the treat. If we had chosen every take, he will enter treat every second, meaning 60 possible treats. If our trading condition was true for one minute and in real life years treat on every tick . So this presents a problem for us. Let's stop. Are back testing for now. Once you click stop, the Emmy allies will appear on the chat, and we can go through the taps off results graph report in Journal for additional info on our testing results in the next video electrically or try to solve this issue off non stop trading by our year. 25. Section 4 9 Main Body (part 2) (noise removed): Let's go to our no pet again to pseudo cook to try to solve our problem. Our question is, how can we control our year to treat only ones every 60 minutes or once every four hours, etcetera. Possible solutions that I can think office. We can introduce a variable that allows or denies that year to treat. We can also have another variable that records the time from the last treat. So once enough time has passed from the last street update the variable to allow our E to treat again. We will also need one variable to store how much time you will allow our E eight wit until its next trip. If treat done, no recut current time using variable of the variable that does not allow that year to treat . You've 60 minutes or four hours etcetera has passed from the current time update. The very begin to allow trading to be done with the solutions. In my we will go back to our Emmy crossover E A. To look at our trip. Timing related variables and courts again in the extent decoration of arable section we need a very body lets the trader choose how are fun dust This year Trip I created and interject data type variable minutes underscore per on the score treat or minutes portrait for shot. I need this very literally s records A number off minutes from one tree to the Knicks, usually another variable to control when there is a lot retreat. So I created this Boolean data variable free to treat. Bullen is a data type that just toss either true or false. I said the default value to true so that when the day is just started up, the variable is set to true to allow it to enter treats usually variables to store in complete the differences from the trading date and time to the current time. Hence I created tree interjected that I've terrible's torture minutes dif minutes day if I was deaf. Finally, we need a variable to record. When the last rate was meat, I used a time data type Variable order underscored it. They turned to the type of store both the exact collender the end as that time off treats since we need to update our free to treat and order that variables on the moment our traits are done. Let's put these variables in the section when a treaty successfully meet going to our custom functions, pleased by order and play sell order, we will update these variables under the section under the else condition. When the ticket number is positive and truly successful, we set free to treat equals to force to make that year stock trading and order the egos to time current with open and close brackets where time current gives the current date and time and we record this under the variable ordered. In order to know how much time has passed from our last sexual trip, we have to calculate the time difference. Let's put this court's under on tick so that the time updates every second. Let's calculate the difference in number off minutes where minutes underscored thief equals two time minute time current minus time, minute order the If you have that time in it and good our trusty helpful. We see that it returns the minute count off the time ranging from 0 to 59 it's a interjected attack. So minutes def will be the minute. Count off the current time, minus the minute. Count off the order, please. Time However, this presents a problem. What if the trip was placed at 8 59 PM and the covering time is 91 PM within the reserve. Off minutes, def. Be negative. Hence an event. It minutes. Dief is negative. We simply use minutes def Blast 60 to give the correct difference in minutes another minutes. We also need to record difference in hours. Our formula here is ours. Def equals two time our time current, minus time. Our oddity. If you have that time, our and check, I'll help bargain similar to time in it. But it returns to our accountancy. They note that our count works in 24 hour count. So 10 PM is 2200 while 10 a.m. is 10 Georgia, we're also near if operator to check in case I was defense negative. We use ours diff equals two hours This blast 24 to go over it to the correct difference in hours to get our daughter number off Minutes passed since the last trade we used to formula . Total minutes diff equals two hours, def multiplied by 60 last minute stiff referring to a lawsuit a cook from Are not pet before. If enough time has passed since the last treat, we need toe update our variable toe. Allow our year to treat again to measure the difference in time. Let's use and if operator to check if torture minutes def is larger than minutes. Portrait minutes Portrait had been set in our extra decoration of parables. If this condition is true, we were set free to treat it close to truth. In order to let this variable free to treat control our trading condition, we need to add it to our if operate this. How, if operator becomes, if current fast m a larger than current slow em e double and sign free to treat where double in size, the end operator. And with this end operator current Fast M, a larger than current slow EMI has to be true and free to treat has to be true as well. In order for the whole if operator to be true, the and operator is a convenient operator to use. If you want something toe happen only if multiple conditions line up to be true, some viewers might be asking, Why don't we set the condition to be if free to treat double equal science. The question true? Yes, we can do this. The court will look exactly the same since before exactly the same. It is more efficient to use option with less coats. Less coast means faster processing time, less complexity and easier to d. But in case of problems before these courts done, I was goto our quotes from top to bottom so that you can post a video and copy them into your own metadata. We will compound that year again and back. Tess it again in our next video lecture. 26. Section 4 10 backtesting (part 2) (noise removed): Let's compound our Emmy cross over a year to back Tess it we will repeat the same process as in the earlier video lecture. Could have foul opened a tough order and cure for folder Copy Emmy crossover e a dot ux for going to experts folder Peace and replace any existing seem far that you may have. If you're middle treated for is currently running, you need to close the program and restart it or else that year was to be on the old version in meditative four Go to View strategy tester beside the Expert Advisor box. Make sure you select the correct E. In my case, I named it m a crossover dot Yes. For the rest of the settings, you can tinker with them as you like. I will still be using control points for our model of testing and use the same time periods I did last time. 1st October 2018 to 27 January 2019. Click on Start when you want to run the tests. This so you will notice that year only does one treat at a time and not unlimited traits like you know, previous version. We've all order timing related goods. I will makes out the speed and end the test by moving the vision. What Speed slider to the max. At 32 the ambulance will appear after the test ends. We can now go into the other tests to check out data. The result Step show when the street is done and the profit and loss graph simply shows the performance of our account over the testing Deeds report is so useful. Summary off our E. A's performance, such as total net profit. Maximum drawdown percentage off profit treats, percentage of law streets, average profit tree average in Law Street You can red click anywhere on the report Tap and Safety State as a HTML fall, which can study in further detail later. Journal is like a Diary of Art year sections. Yesterday Progresses s a trader that wants to make sure that might years profitable. Most of my time is spent here in the strategy tester. We can test on other currency pass and time frame to see if our strategy can be more profitable in other situations, trick our stop loss and take profit prices. Take the chart pivots such as trying it out on four hour periods or 30 minute periods. Instant. The big advantage off computer respect testing compared with manual bet testing is that you can now test your strategy much more quickly over many different scenarios and variables. I believe you are new to computerize back testing. You might discourage very quickly because you might realize how hard and how rare it is for you to actually have a profitable strategy that can be profitable over a long time period. Social spending, several years and health and strategies and your trading sizes can wipe out entire accounts during the test. However, all is not lost in the next section or tried to discuss other factors, such as Greece management and why even losing strategies can be very valuable to you. 27. Section 5 1 course complete what is next (noise removed): we have basically completed all the required sections in order to program your own forex robot. The pulling sections are optional lectures we shot about Reese management and other frequently asked questions. With the new and care for programming skills, you should now be able to translate your own trading strategy into Expert advisor and run your own forex robot. You will be able to back trace it to CVS, profitable over Southern Currency Pass and whether it's viable over the long term, such as over a few years as mentioned in section Force concluding article. There's no shot cut to experience in this area where it comes to forming trading strategies into ease. The good thing about Uncle for is that they have redeem it functions to get the data from most of the common indicators that come along with Metta treated for. And there's quite a lot. For example, the common indicators, such as moving every Jersey R S I m. A c, the Bollinger bands, etcetera. You can use common functions such as I am a I r s. I I m a city and I bends to get the data from this indicators. If you're running your own custom indicator. You can even use the function. I custom to get the data from your own custom indicator. If you wish. Need more advice. You can always email me and I'll try and best to help you if it's really the scope of my knowledge. Otherwise, NPR for dedicated websites such as book dot co dot for our good for additional learning as Cyprus Aylan my Ankle Four skills from this website Expo, the website has lost programming and Syntex related jargon, which you should be able to handle once you get used to order program in terms that the community commonly uses. Whether your experience trader or new to trading investing, I highly recommend you at least check out the falling section on Reese management as most top traders and investors will agree. Good risk management skills are key to treating investing. What about the common one to treat percent Re screw for every trade, however, also talk about how to manage the grease from running multiple e A's or forex robots, as is something only traders who are doing systematic trading, such as running multiple forex robots where encounter also talk about a commonly race issue off E. A s. They are continuously losing money how we might be able to turn them around to make money in state, or how we can actually develop them into hedging ease. 28. Section 5 2 risk management (noise removed): risk management could be the single most important topic for traders and investors. So much so their immediate, the mean hit like topic for this section. If you read widely among investing books, especially those that interview the top traders and investors, your fire common team off them, quoting risk management to be one of the keys to success, these are quoted from the interviews off top investors and traders from the falling books, which I've read. I hope you get my point that it's a big due to minimize risks. Most of the top traders interview in such books typically Reese less than 5% of the cone in one position. Most of them were, is even lower personally for each trait that my year places, if my stop losses hit, I'll be risking 1 to 2% of my account. I were just my trading size to suit this risk profile. If you're risking 2% of your count on each trip, it would take 50 consecutive losses to wipe out your account. If the race is only 1% it takes 100 consecutive losses, which is the lost less likely to happen on the flip side, If you're risking as much as 5% of your account on the street, then you when it accepted 20 consecutive Flosses to wipe out the whole account, even if it's only 10 consecutive losses is to 50% of the count gone to make up for that 50% loss, where you need to make 200% profit from the remaining money in order together account back to break even and in a part of risk management. What he is is that we might be tempted to run too many years. Diversification is good, however, you have to be careful to study how much each years risking if a stop loss is hit on that year, for example, we might be running 10 E. A's on 10 different currency pass At the same time, they stopped lost for each E A with 5% of all con value in the event all 10 e a set stop loss on the same day. That's 50% off our count wiped out just on one single tea. Such events actually happen more often that you might think, because most of the currency pairs are co related and global financial news events might string off them in the reverse direction at the same time. If you're running multiple years, I would suggest you calculate your account or treat sizes this week. Let's say one E A's Mex losses $200 which is 2% off a $10,000 we decided safe enough as it is, quite unlikely for our E A to loose 50 times consecutively. So if you're running 10 years and the Mex loss for each is to her a dollar each, then to be safe, we actually need to set aside $10,000 times 10 which is 100,000 in our account. This will make it safe enough as each of the 10 years will need to lose 50 times consecutively toe wipe out the whole count if you doing. If it's much Ares 100 key and we want to run 10 years in other ways to lower the treat sized by 10 times to properly manage Aries from running multiple years, we should first look at the percentage account loss from one year, then reduce our treat sized by the number off E s that we want to run together. Here's example let's say, for one e A. We usually treat at drop by five lots portrait and each stopped lost. We are using to our dollars our common sizes. 10,000. So that's a 2% next loss that we mentioned earlier. If I'm running 10 e. A's with the same a common size of 10,000 I would divide by trading size by 10. So each E A is only trading at 0.5 lot poetry instead, to some, rice kept each loss at 1% 2 maximum 3% off your account value in the even. You're running multiple E. A's. Make sure to reduce your trading size to be small enough so that your account size does not take a huge beating in the event or the E a stop loss. At the same time for running multiple years, I have a simple guideline for Reese management. Work out the treating size so they're lost for one year is 2% loss from the camp. Then simply divide the trading size by the number of these days running 29. Section 5 4 turning losing EAs into gold (noise removed): some traders who are new to programming years by us help. All my strategies turn into losing yays. Should I give up trading? The beauty of programming years is that we can see order data and act on it. So have you ever thought if all my strategies are losing one's? What if I just reversed them? If you have never thought so, you should post a video and think about it for a few minutes to let the idea sink in if you're trading manually. Orders. While such an idea may be hard to accept for some people, drinks all hurts the price off Some traders. You mean submitting to themselves that they are strategies are bet everything that they are wrong. This took me a Walter except to heart that end of the day. I talk about why I went to Detroit. I wanted to treat to make money, not to prove that I'm smarter than the market. Not to boost my ego by seeing my ideas proven wrecked. I am meted it. Even if my ideas were totally bad, that's unless I can make money off it. I am happy with it. If you're okay with trading of reverse version off your strategy this time you might ask. So how do I do this in my year? Reversing trades in Israel? Simpler than you might imagine. And this is another big reason why one other buy and sell treats to be handed by custom functions. Here in my Method Eater, I have two versions off my M A crossover yea, side by side. The only things we need to change our the functions that e a cause when he has a buy signal or cell signal. When our original year has a bicycle, change it to call a cell. Custom function instead. When the origin eight year has a cell signal, change it to call a bike. A simple changed it. The rest of the year has exactly the same courts. I'm mortified mine. They named it M a crossover e a. Reverse the mixture. I don't mix them up. Let's compel our Emmy crossover year reverse and proceed to beg. Test it. We're running on our strategy tester, or USD CED from 1st January 2018 to 27 January 2019. First, let's spec test origin a EMI crossover, and I will use non vision Want to get the results immediately. We can see in a report here that it is minus 2757 So these air losing A for this particular currency pay mass Spec tester Emmy crossover reverse on exactly the same conditions. Let's look at the result is actually negative 1102 Instead, you might say, Wait up, wait up. Isn't the reverse ea doing everything exactly opposite with the tick, profit and stop losses or flipped? Exactly why is it not positive profit? Instead, some of the more experienced readers watching this might have noticed this more detail, which affects our profit. This more number on the right here, no one that spread is what's eating into our profits and affecting our back testing results . I left the spread at 20 peeps as there's around what my broker is charging me, and this Brett actually affects the tick, profit and stop loss values. Disparate mix. The EA take profit 20 peeps later and stopped lost 20 peeps earlier to illustrate the difference. Let's change your spread to two pips instead and run our test again. First, we will run any crossover looking at the result this time it is only negative it to it instead off negative 2757 earlier a big difference of almost $2000 and affects our profit factor by a big 0.1%. Let's run our Emmy crossover reverse and spread of two peeps. This time, the result is positive. It 06 instead off the negative 1102 earlier again, the big difference of almost $2000 almost affecting our profit factor by 0.1. For viewers who do not really understand profit factor, a difference off 0.1 is similar to a difference off 10% returns per annum and ye that returns 40% per annum becomes one that only returns 30% per annum profit. And this is big. If your capital investor is a large amount, let's stay away from all talk and spread and back to our Emmy crossover reverse E. Comparing the results when the spread is minimal at two peeps, the original years result off negative it to it and the reverse years result off positive. 06 are quite close and it is how you have expected the reverse year toe work. I hope this video also showed you the viewer. Why exploit traders? One that's a little spread as possible. And why brokers one as much spread as possible as they affects their profits significantly . And so it is important to negotiate a broker for us minimal fix bread as possible for the currency pair that you're going to treat. Some brokers actually have a fluctuating spread for their products. If it's not possible to reduce spread, take the sprinter account when back testing and estimating your years. Profit and loss is containing onto the topic off reverse traits on our year. Another way to uses is as a hedging to some. Traders might have a strategy that has, ah, wider tick profit target. Maybe aiming for a few 1000 peeps and a stop loss of phony a few 100 peeps. These strategies might be profitable in the long run, but you might have a very low angry. Hence, one way to minimize the losses off is running. Such strategies is to run another E A that hedges it, using the earlier mentions, stopping off buy and sell orders from our origin i e. A. We can set the hedging year stick profit to be the stop loss value off the original E. And to close or stop lost the hedging treat when our origin ITRI is doing very well, some viewers might be thinking that hedging trades have been in some countries and their brokers do not allow it. You might be more troublesome by the trader can actually run his hedging ear on another forex account with a separate broken state, which could be a look around for such situations.