MQL5 TUTORIAL – ADVANCED RANDOM ENTRY SIGNAL

video

In this video we are going to check random entry trades.
Random entries?!
Why should anybody trade random entries?
Well, there is a good reason for that.
Let’s imagine you would trade anything like Bollinger Bands, MADC or RSI.
Wouldn’t you like to know which kind of entry is the best one?
To find out what the answer to that question is it makes sense to trade random entries and use the result as a benchmark.
This is the Forex Trading Framework and this is the trading entry we are using right now. It’s called: “CheckEntry_Random”. We are going to create the entry module right now.
To do that, please click the little button here in your Metatrader or press F4 on your keyboard.
Now you should see the Metaeditor window and here you want to click on “File/ New/ Expert Advisor (template)” from template. “Continue”, I will call this module: “CheckEtry_Random” click on “Continue”, “Continue” and “Finish”.
Now you can delete everything above the “OnTick” function here and two comment lines, and we will exchange the void “OnTick” function and create a Check Entry (CheckEntry) function that will return a string.
The first thing we need to do is to create a signal that will be a variable of the type string and we don’t assign any value right now because we are going to calculate that later.
Now we need to initialize the random generator; that is done by using the function “MathSrand”.
“GetTickCount”, “MathSrand” sets the starting point for generating a series of pseudorandom integers.
“GetTickCount” returns the number of milliseconds that elapsed since the system start, so basically this value is always different. To calculate a random number we use “MathRand” this time without the “s” in the middle, that can create a pseudorandom integer within the range of 0 to 32,767, but we just want one of two numbers and that expression: “%2” will do that.
If the random number is 0 that would be a buy signal and in that case we would assign the word: “buy” to the signal variable. In the other case if the random number is 1 that would mean we have a sell signal and now we assign the word: “sell” to our signal.
The last step is to return the random entry to the main module by using the function: “return” for our signal.
Now this is just the entry, I use the Forex Trading Framework; that’s basically a collection of different functions that can handle the trade management for open positions.
Whenever our Check Entry Random (CheckEtry_Random ) module delivers the signal for a buy or a sell trade we would pass that signal to the Framework.
Now we need to save the “CheckEntry_Random.mq5” file by clicking on the little button here and recompile the Forex Trading Framework by pressing F7 or clicking on the “Compile” button. That worked without any errors. You can create your own Forex Trading Framework or main module or if you prefer download my version from: forextradingframework.com and if you could compile the code without any errors you can click the little button here or press F4 to go back to Metatrader.
In the Strategy Tester I select the Forex Trading Framework. You would need to select your own main module. I now can adjust the trading risk for my Framework to 10, select a currency pair and let’s trade from January 2018 to the 1st of March, I click on start, lets speed up the trading process here, it takes some time, we are now in the middle of January, so far this is cash-flow positive.
Now we have reached February, we made a profit and our test should be finished soon, that happened right now, this is the balance curve, here is our result, we made a total net profit of 463 Dollars.
Let’s do a few more tests.
I disable the visualization mode to speed things up and click on “Start”. Here is the graph, this time we made 415 Dollars.
Let’s do another test, and this time we only made 36 Dollars and the reason is that we have traded a random entry.
Now you know how to create an entry module to create random entry signals that you can use with the Forex Trading Framework or with your own trading library and you have coded it yourself with a few lines of MQL5 code.