if you have a computer internet connection and 1 hour of time then by the end of this video you will have a scalloping robot which has more than 90% win rate with a very tighty stop loss of 20 Pips even if you know nothing about coding mql language or metatrader as a trading platform we'll go step by step we'll cover these topics and I'm putting the time Mark so if you're already comfortable with certain sections then you can easily skip forward sections that you don't need to see so we'll look at a strategy back test
and result then we'll look at the strategy itself then we're going to download metatrader and open up the coding environment then we'll write all the codes and then we'll execute the EA and then we're going to set up all the inputs that we need to provide to the EA and we will apply it to charts to show you the strategy results up front in a back test I've already written the code and executed the file so I've loaded it into metat Trader we're going to use it on USD JPY on a 5- minute chart from
2023 beginning until today and I'm starting with a balance of €1,000 and let's start the test so here we are in the testing environment and as you can see the EA has started to perform the trading operations it has a very tight stop loss and it performs the scalloping operations so you can see a lot of Trades opening and closing very very quickly on a 5minute chart now I'm going to speed up the test because I don't want to take too much of your time so the test has finished and if if we look through
the testing details what we see is a lot of Trades opening and at the end we are finishing with around € 26,000 of profit if we go back to metat Trader and go to the back test Tab and what we can see is we started with an initial deposit of €1,000 and we're finishing with a net profit of close 26,000 Euros a running draw down of close to 22% but that's also dependent on the risk settings that we will go in deep details what we have is 91% short trades that we won and close to
91% long trades that we won if you look at the graph of equity you basically see no running draw downs and that is because of the tightest stop- loss that the strategy employs the overall performance is up and up there are periods of stagnation there are also periods of draw down but overall the strategy keeps making money and we're ending with around 26 27,000 of profit strategy works best on USD JPY gpp USD and Euro USD it can work on any pair as long as the spreads are low so let's very quickly run it on
Euro USD as well and I'll remove the visual mode because we have already seen the visual mode with usdjpy and I'll speed up the test so once again what we see is no running draw Downs because of tius stop losses the performance is up and up there are periods of decline as well here for example and here as well but we're ending up with something like 4,000 500 in the end overall the back test result 14% draw down 91% short trade one 95% long trade one and a total profit of 3568 if we run it
also on [Music] gbpusd and again I'll speed up the the test once again no running draw Downs because of the tightest stop loss some periods of stagnation between July and January but overall performance is up and up if we look at the back test results we've got 21% of draw down we've got 92% of short trades one and 92% of long trades one we started with a balance of 1,000 we're ending up with a net profit of 3,600 and now the strategy itself strategy in itself is very very simple what we're betting on is that
if the price is moving in a certain direction that it will continue to move in the same direction for at least one more pip now you can use various entry methods like EMA crossovers RSI crossing a certain threshold ichimoku clouds whatever your criteria is as long as the market is moving in a certain direction and you take the trade in the same direction as well the criteria we're using in this example or in this EA is the last High and the last low so we place a buy order at the last high and we place
uh a sell order at the last low and we put a 20 pip take profit and a 20 pip stop loss that's where the tight stop loss comes into the picture now if the price comes down and hits that level again it is moving in that direction then and if it is moving in the downward direction that what we basically saying is that if the price comes down to that level that we're betting that it will go at least one more pip so at this point the cell order will convert into a sell and then
as soon as the price moves more than one one and a half two Pips defined in the criteria we will start to Trail the stop loss extremely aggressively until the price comes back and either hits the stop loss or it continues in the direction that it is continuing or it is coming and hits our take profit so that is the entire strategy for those of you who are hearing the word metat Trader for the first time it's a trading platform and you will learn about it as we go but you can head to Google just
type meta Crea a download and click on the first link and you can download it for Windows and you can download it for uh MacBooks as well once you have downloaded it and youve installed it and you open it you will basically see a screen similar to this you need to head to the accounts by the way if it is not visible it's basically the market watch and the Navigator which are turned on currently in the view this is the Navigator and in the accounts you can open up an account or if you already have
a trading account then you can log into it you can select the servers basically uh depending on who your broker is and then provide the login and password and hit okay and you will connect to that server here in the market watch you basically have all the pairs if you're not missing any pairs then you can click on the plus button to add those pairs right clicking let's use gpp USD right clicking on it you can go show the chart window and there you have this charting software which is deploying the prices in The View
Bar as well again you can go to strategy tester and that is the one that we were using to test the strategies here you will have all the robots that you have written now in order to code an EA and apply it to the charts you need to head to the development environment by clicking the button IDE when you click this button The Meta Trader is going to open up the meta editor and you're going to end up with an screen like this so this is about the meta Trader and meta editor so once you
have downloaded metat Trader and you have opened up the meta editor now we can start writing the codes so let's start coding I'm going to create a folder in the exper folder by creating a new folder and let's call it the scalloping robot by selecting this and clicking new then you're going to be creating the expert advisor in that folder let's give it a name and let's call it escallop robot and when you hit next next and then finish you get this template now in meta editor all of the CES which are written after these
two lines meta editor treats them as Commons so it doesn't read them it just goes and reads all of the codes which are without these two dashes I'm going to remove these commment dashes lines to make it clean and after the clean up we end up with a template like this now there are three functions that come automatic Ally when you create a new template the on init the on D init and onti on init is basically on initialization so when we will attach the EA to a chart that's the initialization of the EA and
every code that we write here is going to be run when the is applied to the Chart then the initialization as you can imagine is on De initialization so when you remove the E from the chart the chodes written here are going to be run and that leaves us with ontick function now on tick function if I go back to metat Trader every time the price data changes that is a tick in mql terminology so whenever there's a new data about the price comes in that's what metatrader treats as tick and then on tick is
basically whenever a new tick arrives all of the codes which are going to be written between these two curly brackets are going to be run now we will create some functions of our own as well below here because these three functions available to us are not going to be enough to write the entire code but we'll go step by step and I'll I'll explain every step in details but for now let's first go back to metatrader because we're going to see the input tabs the input tab is where all of the variables for the EA
are defined so when you will be applying the EA to a chart or when you're doing a back test you will be able to come here and Define all of these input variables now let's go one by one because I'll explain them and then we will we use them to start our coding so the first one is how much risk as a percentage on each trade that I'm willing to take so if you have ,000 in balance a 2% risk will mean that in case the trade comes back and hits your stop- loss you lose
2% of 1,000 which is €20 then the next ones are about the trailing stop as we already saw in the strategy description that we will be trailing the stop loss very very aggressively so there are two points to it the first one is how how much do we want the stop loss to be away from the price so if the price is moving in our Direction how aggressively do we want to trail that stop loss now 10 points equals one pip so if I say 10 that basically means that we want to Trail the stop-
loss behind the price by one pip then the next one is points in profit before the trailing stop is activated is basically if we have taken the the trade on a certain price level how much do we want the trade to go in profit before we start trailing the stop stop loss and I'm defining here as 15 points which is 1 and 1/2 pip so once the price has moved in our favor by 1 and 1/2 pip that's when we start trailing the stop- loss by one pip then the time frame to run on that
basically is which time frame do you want to run it on 5 minutes chart 10 minutes chart 15 minutes chart 30 minutes chart 1 hour chart I normally use 5 minutes chart and we will Define it here so that the EA in the background knows what time frame to all always run the code on even if you change on the chart itself because what you can do is here on the chart currently it's at 1 hour but what I can do is I just want to quickly see how the price looks on 15minute chart but
if I change it and the EA was defined as current then the EA will start treating 15 minutes to be the chart that it's running on and not the 1 hour or the 5 minute but if we Define it as 5 minutes here in the EA itself as an input variable then even when you're changing the chart on the metat trader the EA in the background knows that it still needs to continue running the EA on 5 minutes irrespective of what the time frame on the chart is then the EA identification number and that is
basically for the EA to identify the trades that it places by itself so for example if you had an account and let's say if you had three or four different charts let's open up another chart let's say on Euro New Zealand you had another EA cordos another RSI EA which is running here and on gpp USD you had our scalloping robot running then the year is going to get confused which traits it has played itself and which trades are coming from the other EA and this is why we need to define a unique identification code
for the EA so the EA always knows which trades are its own trades and which trades are not its own trade you can put any random number you like but at least now the EA knows that if the trade has this number then this is a trade that the EA has placed itself so any changes to that trade it will make it is making changes only to its own trade then I also like to have the start hour and the end hour defined because during the midnight portion the spreads go so Bonkers that I do
not want the EA to be trading in that time so what we want to be able to Define is let's say I want to say my ear only starts trading at 800 hours in the morning and it stops at 2100 hours so it does not trade between the hours of 2100 and 800 hours the next morning then there are some variables that I have defined for the background chart and color but these are only my preferences these have nothing to do with the e but if you want to code them what they basically do is
if you go back once you apply the chart I like to have no grades a black background yellow as my bull candles and red as my bear candles and this is what I'm defining here that I want chart to be in Candlestick but you can also have it as a bar chart or a line chart I want the background to be black I don't want to show the grid lines I want the bull candles to be yellow but you can change it to God knows whatever you like and then also my bare candles are going
to be this color this is just my own preferences of wanting to see the chart like this and not like this it just looks ugly that way to my eyes so now in order to be able to write these into the coding that we will do we will need to ask the user for risk percentage and the trailing stops parameter which chart to run on and the hours of trading and the unique EA code just remember this because we're going to be using it in the coding now back to meta editor the top portion here
before these functions is the portion where you define all of the variables so this is where we're going to be asking the user for input and then we're going to also Define some variables where we're going to use those variables in the coding but we're not going to ask any input from the user so let's start with creating a section and by section I means here you see that these all variables are under trading input and all of these variables are under chart background so back in meta editor if we write the code input group
then basically the the metat trader is going to create a header section if you write input group and then within apostrophes whatever you write so if you write D D Dash trading input it's going to create a section called trading input now let's start asking our user for the inputs and the first input we need from the user is the risk percentage so we write input and if we write if we start the code in the line as input then the EA or the metat trader is going to or when we writing the code and
executing it EA is going to identified is this is something which the user needs to input and we Define a variable and we call it risk percent for example and we give it a value of three so basically three and we're going to be using it later on as 3% now what does this double mean meta editor works with different kinds of variable so if you are going to store in a variable uh an integer say 1 2 3 4 then you basically say in and meta editor is going to know that whatever variable you're
going to Define next is going to be storing an integer value now if you want to store something which will have decimal then you have to start with or defining the variable as double what we have done in this case so when we say double then we can store decimal values you can store 3.5 3.6 and because risk percentage depending on the user whether they want to Define it as 2 2.1 2.2 if they get really fancy with it I'm going to create the variable as double now remember this part which is you start with
input if you say input then meta editor is going to know that it is going to be asking the user for an input double is defining what kind of variable it is going to be followed by the name that we are defining the variable and then if you want to store a value you can leave it blank as well like this but then the variable on creation is going to be empty if you say three equals to three then meta editor is going to start with a value of three on the onset of the EA
so even if the user does not define anything or forgets to Define it there is a default value now let's convert this small code that we have written so far into an EA by clicking the button compile and we have zero errors zero warnings which basically means that this EA has been created or updated so now if I go back to metatrader what I will see here is that in the experts in our folder that we created as scalping robot our new robot is now available if I select it and then go back to input
stab what you can see here is that that the section trading input has been created and the part risk percent has been created with a value of two if I go back to default yeah it's three and this is the three that we had defined here now if you put a double hash here and say let's say risk as percentage of trading capital and compile it again now if we go back to metat Trader what we will see is that the variable is not called risk percent it's actually called risk as a percentage of trading
Capital risk as a percentage of trading Capital so this is a way of because we Define the variables as very like unique words and the user might not be able to to understand them so if you put double hashes and then say what you want to say here the actual name of the variable is going to change in metat Trader now the next variable that we wanted to collect input on from the user was take profit points how much is the take profit and I will ask the user to provide an input so I'll start
with input integer because we're going to we're not going to store decimal values in this and I'm defining the variable as TP points 200 and we say it's the take profit and 10 points equals 10 one pip then if I go again again and say and this should be in a small so now if I say input again integer and now we say stop-loss points and we can again Define it as 200 points and say this are the stop loss points and 10 points equals one p just to prompt the user that when they're defining
it in points they're defining it in points they don't confuse it with Pip now if I compile it again and now if we go back to metat Trader we will see that these variables are also now created coming back to meta editor the next variables that we need input on are on trailing stops and the first one was when do we start stop loss to be triggered so I'm going to create a variable again integer because we're not going to store decimal values in it and I'm calling it trailing stoploss TSL trigger points so when
to start triggering when to start moving moving the stop loss and I'm giving it a name or or defining it a giving it a description that points in profit before the trailing loss is activated once again if I compile it and then I go back I will see here that now the user can also Define when the trailing stop is activated back again to meta editor the next variable we're going to ask for is to Define as an input the TSL points which is how much the stop loss need to Trail the price buy so
once it is triggered let's say the price has gone in our favor by 1 and 1/2 pip now we need to start trailing the stop loss how far do we want the trailing stop loss to be from the price and that's what we're defining here as one pip or 10 points and then we ask the user for their input on the time frame so I'll say input but now time frame is not a double it's not an integer and in mql it is defined as enum meaning enumerated enum time frames so that's the type of
the variable and once you have defined the type then we need to give it a name and let's call it time frame and once I hit enter now this once you start writing period it will open up the drop- down button and from there you can select what the default value is going to be one day chart 1 hour chart 12 hour chart 2our chart I'll set the default as perian C which basically means that whatever chart you're applying it to whatever is the time frame on that chart at that point in time that's what
the year is going to use I hit enter and then every code in meta editor finishes with a colon that's basically where of telling mql that the code has finished or the instruction has finished and it needs to move on to the next instruction let's give it a description and let's call it time frame to run now if I compile it and go back to metat Trader then we basically have the variables defined here as well they can select it from a drop down or they can Define the value directly another input that I need
from the user is the magic number which is the unique code for identification of the EA and then the last input that I'm going to ask the user to provide is a comment and again this here I'm saying input as a string and a string basically mean text so integer was 1 2 3 4 5 double with decimal time frames are enumerated time frames as a variable type and then input is strings basically mean the variable is going to store text because I also want to put a trade comment and let's call it es scalping
robot for now so now if I compile it and go back here are all the variables that we we are giving the users the possibility to Define for themselves so these are all the variables where we're asking the user to provide an input but we're also going to need some variables where we don't want the user to provide any input we're going to hard code them now guys I've tried my best to within a week write the entire coding and record it and edit it but it's just a bit too much I mean it takes
forever to to capture the entire thing and then editing is a pain in the back side already in this video we have looked at the E and everything we have looked at the user inputs we' have coded the user inputs in the next video we will go through writing the CES for finding the high High finding the lower lows and then also creating the trading conditions so that the trades can be placed and then we can start trailing the stop losses but I also appreciate your patience with it I'll see you next week stay safe
trade safe [Music]