with a 90% win rate a very tight stop loss this is an amazing scalloping robot if you have a computer and internet connection and 2 hours of time then by the end of this video you will practically own this trading robot even if you know nothing about coding matter Trader or mql as a coding language so without any further nonsense let's start we will go step by step and I will explain every code in detail so you can very easily follow it and code it for yourself but before we do the coding let's take a
look at the back test and buckle up because it's going to be crazy I have written the code already and executed the file so this is the one and we're going to run it on 5 minutes chart beginning of 2023 until today I'll run it in the visual mode first so we can see how the operations work so let's start so here we are in the visual testing environment and what we can see is that the EA is performing all of the tra trading operations automatically without any manual intervention it's opening up the trades it's
setting up the TPS and stop losses it's trailing the stop losses exactly how we wanted it to if I look at the results so far the ear is performing all of these operations and we're already in € 273 of profit I'll speed up the test so the test has finished and what we can see it's an scaling robot so there are a lot of Trades that opened up we started with a balance of ,000 and here is the crazy part where ending up with a profit of $33,000 if we go back and look at the
graph what you will see is that there are no running draw Downs because there is a very tight stop loss in place so either the trade hits the takeprofit Mark or the stop- loss mark it doesn't go into draw Downs you might have a few consecutive losses here and there but the overall performance is just up and up there are periods of stagnation for example here where the the EA did not do very well but overall if you leave it alone for a very long period of time it continues to just gain more and more
momentum and continues to go up I'll speed up the test and the test has finished if you look at the back test results what you will see is we started with a balance of ,000 we're ending up with a profit of $633,000 that is crazy what's more crazy is the relative draw down on the balance is only 9% we have short trades one around 90% And we have long trades one around 90% as as well now let's take a look at the strategy itself strategy in itself is very very simple what we betting on is
that if the price is moving in a certain direction that it will continue to move in that direction by at least a small margin now you can use different methodologies you can use RSI so if the RSI increases from 50 to 60 that means the price is moving upwards or you can use moving average cross overs so if the the fast moving average crosses the slow moving average upwards that that can be your trigger point but the point is if the price is moving in a certain direction then we bet that it will continue to
move in that direction what we using in this e is the last High and the last low so when there is a last High we place a a buy order and when there is a low we place a sell order and as soon as the price touches that point it opens up the trade and if the price moves further in favorable Direction then we Trail the stop loss very very aggressively and until either the price comes back and takes our stop- loss which is trailing or it hits our take profit point so the strategy is
extremely simple if you have been following this channel then you have already seen the last two videos where we coded this es scalloping robot but more related to Forex currency payers operations so we looked at it specifically at USD JPY Euro USD and gpp usdy now when it comes to bitcoin we cannot apply the same code reason being that the takeprofit point the stop- loss point and the trailing stop- loss points that we Define for the Forex currency pairs are not applicable to bitcoin because of the price structure difference normally Euro USD hovers around 1
1.1 GBP USD somewhere between 1.2 and 1.5 and USD JPY between 130 and 150 when it comes to bitcoin the prices are 50, 60,000 sometimes 15,000 so there are two issues number one the price structures are very very different so we need to modify our TP points our stop loss points our Trail stop-loss point and then secondly and more importantly Bitcoin prices can jump from 15,000 to 60,000 so you cannot have a static takeprofit stop loss ratio we need to make it Dynamic somehow that it is related to where the price is in the market
that particular day and we do that by applying takeprofit points and stop- loss points as a percentage of the price in the market so if you already have these codes from the last two videos we can continue if you don't have these codes I will urge you to go back code this from the last two videos and then we can start to make the modifications let's start so this is our trading robot from the last two videos and in the input tab we had all of these inputs from the user under the trading input header
so the first thing we're going to do is create a header here and create system profiles so we go back to meta editor and we create another input group and we call it trading profiles within this what we are going to do is create two different profiles for the user to select from so like in the last video we will create an enum which is going to give us the drop- down button so we're going to have two different profiles in it one is the Forex and we assign it a value of zero and the
other one the new one that we're creating is the Bitcoin and we assign it the value one then we create an input variable and we assign the new enum that we have created system type which has Forex and Bitcoin has two drop- down values and we assign that variable to that variable type and the default value is zero thereby Forex after the two slashes we say trading system applied so that will become the text that the user is going to see and then we create an integer variable calling it system choice where we're going to
store whatever value the user selects whether it's zero for Forex or one for Bitcoin we're going to store it in this variable now if I compile it and go back to meta Trader what I will see here is that there is a trading profile created SO trading system applied Forex or crypto and the user can now select whether Forex or Bitcoin profile to apply back in meta editor we go down to the bottom and here we will collect some more input from the user and so let's create another input group and we call it cry
CTO related inputs and these are only effective under the Bitcoin profile and here we're going to ask the user to provide us with first the TP as a percentage of price because that's what we're going to use here so if the price is 60,000 where should the TP be as a percentage of that price or how big the TP should be we're calling it an input variable so that the user can Define it and we're creating it as double because this will store decimal values then the same goes for a stop- loss so we'll ask
the user to provide us a stop- loss again as a percentage of price so where should the stop loss be if the price is 60,000 and then exactly the same way we're going to ask our user to provide us input on trailing stop loss but not as a percentage of price but as a percentage of the TP so if the TP is 100 points what percentage of that should be the trailing stop 5% will mean 5 five Pips out of 100 and then the same goes for the trigger of the stop- loss as the point
of how much the price should be in profit before the trailing stop loss is triggered and then coming back up here where we're defining the variables but we're not asking the user to provide an input I'm going to create four variables on the double which are TP points SL points TSL trigger point and TSL points and these we create because if you have followed in the previous video these were the points on which we were basing the entire EA in terms of TP points SL points trigger points and TSL points but because we were collecting
them as user input we cannot change them so if if these variables are defined here then these becomes hardcoded and our code will always look at this regardless of whether it's Forex profile or Bitcoin profile so when we will ask the user to provide the input we will store it in a different variable and and then depending on which profile is used whether Forex or Bitcoin then we will assign the values to TP points SL SL points trigger point and TSL point the value based on those profiles selected so we go back up here and
then the input variables that we had asked the users to provide I'm going to change them by simply adding input in front of it so all four input input and then input so now the values are going to be stored in these which we are not using in the EA anywhere we are going to be using these points in the EA and therefore now we have the the Liberty the freedom to actually take the value either from here or assign the values that we calculate here to these four points so now let's compile and go
back to metatrader to see whether these changes are now visible and we can see that not only do we we have the profiles available now we also have the crypto related inputs which are effective only in the Bitcoin profile also here the user can provide the value here here and here so now we have all the variables that we need so we go down to the initialization function and add the very initialization of the EA we assign the values that we have collected from the user into the TP points SL Point TSL trigger points and
TSL points which is basically the Forex profile numbers from here we are assigning them back to these variables that we have created and the reason creating them separately was again so that we can assign either these values or assign these values depending on which one do we want based on the profile selected then I'll go down here and these two variables that we had assigned values in the onti function I will move them up into the initialization as well which is the start our choice and the end our choice because we collect the input from
the users here and on the initialization of the EA we can already assign these values to these variables that we created up here we don't need to do it on every tick or every opening of the candle once the year has started these values are assigned and they don't change anymore and now as the last step the way aable that we defined where we're going to store this choice of the trading profile we created it here we created the system type with Forex and Bitcoin as selectable values and then we created a variable S type
system type where we're going to store which of the profile has been selected and we called it S type so now I'm saying if system type equals zero and if you put two hashes then it's a condition so if system type equals to zero meaning Forex then system Choice equals zero as well and if system type selected in the input variable is one then store the value of one in system choice and there we're done with the initialization function so let's move on to onti function now on the ontake function this is the new bar
section so every code under this code is going to be run only on new candle and everything above it is going to be run on every tick the last video explained it fully and after we have looked and checked that we are in the trading time period defined by the user here in terms of start hour and end hour after that we go ahead and we create one more function and say if system choice is one meaning if it is Bitcoin because that's what we said here Bitcoin equals 1 so if the system choice is
one then get the value of the price from the market as it is now by using the symol info double function sending the the chart symbol which is Bitcoin and asking for the ask price now between the ask price and the bit price the difference is going to be very minimal on bitcoin I mean the Bitcoin prices are 60,000 50,000 so a couple of points here and there do not matter so we're only going to work with ask price and not the bid price and then we assign the value to TP points and SL points
based on the market price so here is the market price ask multiply by whatever the user has said as the percentage of price for the TP and then divide it by zero because it's a percentage same goes for stop-loss points so we're asking for 60 let's suppose if the user has defined the TP as percentage as one then what we're saying is if the price is 60,000 multiply it by 1% and then your TP points are going to be 600 points away from the price then exactly the way that you saw in the last video
how we coded it for Forex we wanted the this the orders to be only sent when the price is not too close to the price so for example if the price is here and if this was the high then we don't want to send the order because the price is extremely close to the point what we want is that the price is further away from that point so that we can send the stop order and this is the variable that we defined here for the Forex order distant point which was 100 points meaning 10 Pips
so only if the price is away from the order that's being sent by more than 10 Pips then send the order and it was half of the TP points for Forex so I'm keeping the same logic and going whatever is the TP points divided by two and that is the minimum distance that the price must be from either the high or the low for us to send the order and then lastly we assign the TSL point and trigger stop-loss point also based on what information we have collected from the user as a percentage of the
TP so if the user says it's 5% of the TP for let's say uh TSL and the trigger should start at 7% of the TP then we say TSL equals the TP points multiply by whatever percentage divided by 100 and the trigger point should be DP multip by whatever is the trigger point as a percentage of TP divided by 100 so now what will happen is when the year will start it will look at okay which profile is selected Forex or Bitcoin if it is Forex then it will come here and then it will assign
the input variables that we have collected from the user here under the Forex section let's call it Forex Trading inputs under the Forex section it will apply the value as default to the TP point stoploss point trigger point and the DSL point and also the expiration bars and the order distance Point are going to be the same as as the EA that we coded in the last two videos for Forex but then it will check whether the the system type is zero meaning Forex or is it one now if it is zero then it will
continue and when it will come here it will check whether it's one but it's not one it's zero it's Forex so it will escape all of this and it will continue to run the EA with the same input as provided by the user under the Forex Trading inputs but in case if it is one then the system is going to go back to the the crypto related inputs and we'll look at these four and then redefine the TP point the SL Point order distance Point TSL point and the TSL trigger point based on those variables
defined by by the user let's compile it we do not have any error one warning which is going to be a warning of the conversion type from double to integer here because the when we're dividing the TP points to two it might be ending up in a decimal number but the order distance point that we fine was an integer now you can change this to a double otherwise what the system will do is basically round it up or round it down to whatever is the closest integer I don't mind either ways you can change it
to a double and in which case you will not have any error and no warning as well now one mistake which have made which we need to correct is where we had this we don't need to divide it again by 100 and the reason being that when we get the TP points and we send the buy order if you come down here to the buy order or sell order what you will see is here we're multiplying it by points which in this case is going to be 60 so there are two decimals afterwards and because
we multi M Ling it with the point system so in a way we're dividing it by 100 anyways so we don't need to divide it by 100 again we're sending the value in points so those are going to be converted based on two decimal system under Bitcoin so it's effectively being divided by 100 in the buy order section and in the sell order section so we don't need to do it here again so this is it for all the modifications of the code and now it's ready to run so let's compile it one more time
and then if we go back to metat Trader here is our scalloping robot and now in the input tab on top of what we have already covered in the last two videos we now besides the Forex profile also have the Bitcoin profile if you are applying this EA to USD JPY gpp USD or Euro USD you select Forex in which case all of these settings are going to be used for takeprofit stop-loss trigger of the stop- loss and the trailing stop loss in itself if you use use Bitcoin then these settings are going to be
used the only things common in fact what we can do is we can go back to meta editor and create another input group and let's call it common trading inputs and there you have the risk percentage you also have the time frame magic number start hour and end hour so these are all common elements ments and then these are the elements related to Forex in fact these are also common so let's move them up here so these are all the common trading inputs these are only specific to Forex Trading these are only specific to crypto
trading so there again if I compile go back to meta Trader then what we see is we have the trading profile these are the common ones let's select five here 5 minutes chart we'll start at 300 hours and we'll end our trading at 2200 hours and then if you were applying it on Forex then these are going to be used and if you were applying it on crypto then these are going to be used depending on what profile you select so before we go away let's go back again here our robot 5 minutes from 2023
until today let's run the test one more time to see if all of our coding is correct I'll go to the graph and I'll speed up the test so the test has finished again on the back test we have 8% of relative draw down almost 90% short win almost 90% long trades one we started with a balance of ,000 we're ending up with a net profit of €40,000 now a few very important points number one this is a scalping robot so it requires very tight spreads so choose a broker that offers a very tight spread
on both Forex and also on bitcoin the second one is the ability to set it stop losses very very close to the price because we're going to be trailing them extremely aggressively so that should be allowed on your broker and thirdly no year is going to make money every day every week or even every month so when you apply the ca you also see in the back test that there are periods where there are consecutive losses there are going to be periods where there are going to be maybe weeks or even months of less profit
no profit or stagnation it is about the overall direction of the EA so for example here now we are in a period of stagnation even slightly losing money for a very long period of time from June all the the way until the end of July now when you run the back test it sort of looks like because it is done in 4 minutes 5 minutes that it looks like oh I made a lot of profit in just 5 minutes but that is not true in real trading so here between June and all the way here
until the end of September there is no profit and even whatever profit was made here is already given back to the market so you cannot expect every month to be profitable remember these three points apply the EA with care demo it first and then only apply it to life chge once you are comfortable with how the EA is performing and you have optimized the settings to your liking so until next time guys stay safe trade safe [Music]