Mql5 EA build
-
Currently trying to build a bot to trade based off an SMA 60
Here is how my strategy works.
Once there are 2 candles above or below the SMA I either short or long based on which side it is above or below.
I want my EA to trigger a stop loss if it breaks the SMA 60 and I want to test multiple take profit levels to see which level works best for whatever currency pair.
This is what I got so far but it isn't exactly working on what I have seen so far from testing it.
-
I can't test the .ex5 right now, got an optimization running..
Please use the windows snipping tool to put a picture, or share a copy of the project:

-
-
@spicynote
This will need some fixing. Remember that the ea algorithm runs on every new tick (as we are "on Tick").
Now it checks every tick if the candle is above MA 60, and if that is TRUE, then it buys.
It will not open new buys (even if price is above MA) before we wait 2 bars, that's what the "every n bars" does.
You shouldn't put any closing conditions after the opening condition - that means that you want to close the trade on the same second you open it.I'll make a working example in a minute
-
@spicynote
Here: https://fxdreema.com/shared/Y3lUXgVrb
Moving backwards in time is best done with the candle ID.
ID 0 = current, updating candle
ID 1 = latest completed candle
ID 2 = 2nd completed candle
etc.Connecting blocks vertically means "AND".
I connected 2 blocks with condition: "candle close is above 60 MA", with different candle IDs, so the combination reads as "latest candle is above 60 MA, AND the one before it is also above 60 MA" -
When I test it out is there any way to see all the visual ques on the meta trader 5 chart of where it bought and sold?
Thanks m8 ,
-
Also I am not very familiar with Mt5's strategy tester. Is there a place after you use strategy tester to see the whole rundown of how your bot performed?
Thank you,
Spicy
-
Nvm found it. For some reason it wont let me delete the previous comment.
-
I will attempt to build it with the id's included this time. When running the example I realized that it still is buying and selling multiple times on one candle for whatever reason. I think once I rebuild it according to the id's I should understand it more intimately.
-
@spicynote The reason here is probably our closing condition: it checks candle close and MA with ID 0 (the current candle), and the price can naturally cross the moving average multiple times in one bar time. Use ID 1 in the closing condition to fix,
or put "once per bar" in the project -
It shouldn't purchase until 2 candles have been established above or below it. The system should make a purchase on the opening of the 3rd candle. @roar
-
@spicynote
The EA doesnt currently care about the current candle for the trade opening, it only looks the ID 1 and 2. To trade only on candle open, use "once per bar" at the very top of your project -
Where is the option to do that? @roar
-
@spicynote
Like dis:

-
@roar I am confused on how these sequence of blocks would execute according to my strategy/ Wouldn't it still continue to long/short according to this after another bar pops up?
You got a discord it will be easier to communicate through that
All the best,
Spicy
-
@spicynote
The code inside "once per bar" -block will execute on every tick. However, the block will continue the execution flow to blocks 8 and 9 only at the first tick of the bar. When new bar appears, it will once again execute only on first tick.
Go ahead and compile the .ex5 and backtest it (in visual mode), that is the best and quickest way to learn. When I do something new, I compile and test 10 new versions of my EA in 10 minutes, its all about the repeating process. You can copy some block groups, turn some blocks off, experiment and find out which does what.I'd like to keep the process in this forum, for (1) building a knowledge base for everyone and (2) separating my free time, I only come here when I want to escape my busy life, I should be studying right now lol
-
-
So i tried re building it from scratch i noticed that i couldnt find a way for it to tell the program to wait until the blocks past above the MA 3 time before buying on the opening of the 3rd candle.
Also another problem i keep running into is to get it to stop purchasing above the 3rd candle
This is built through the mt5 builder so if anybody could help me it would be much appreciated
Thank you,
Spicy
-
@spicynote
I tested the project I shared earlier: https://fxdreema.com/shared/Y3lUXgVrb
Found a little bug - close sell condition was "below" instead of "above".
Now the EA works as designed.
It surely does make some stupid trades, but lets not blame the poor algorithm. It just does what we tell it to do

-
@roar It to zoomed out to see very clearly.
But, I notice there are two shorts right next to each other without breaking supports.
Perhaps i didnt explain it clear enough.