Thumbnail for Create a Profitable Range Breakout EA with Gemini AI (Fast!) by René Balke - Fx Bot Trading

Create a Profitable Range Breakout EA with Gemini AI (Fast!)

René Balke - Fx Bot Trading

20m 59s3,531 words~18 min read
AI audio transcription
Transcript source

AI audio transcription

This transcript was generated from the video's audio because no usable YouTube caption track was available. The transcript below is server-rendered so it can be read, searched, cited, and shared without opening the original YouTube player.

Timestamped outline
Pull quotes
[0:00]In the previous videos I already looked at chat GPT and Claude AI for vibe coding Meta Trader 5 expert advisors.
[0:00]So it's only logical that today we will look at Gemini AI, the Google AI to create automated trading expert advisors for the Meta Trader 5.
[0:00]So the task for the AI will be the same as in the previous videos, I will ask for a simple range breakout expert advisor that will work like this here.
[0:00]So every day in the morning, every single day I want to create a range between two points in time.
Use this transcript
Related transcript hubs

[0:00]Hey listen and welcome back for another video on this channel. In the previous videos I already looked at chat GPT and Claude AI for vibe coding Meta Trader 5 expert advisors. So it's only logical that today we will look at Gemini AI, the Google AI to create automated trading expert advisors for the Meta Trader 5. So the task for the AI will be the same as in the previous videos, I will ask for a simple range breakout expert advisor that will work like this here. So every day in the morning, every single day I want to create a range between two points in time. For USD Japanese Yen, I usually use from 3:00 to 6:00 AM in the morning. And after this time, we will have a buy stop order and a sell stop order at the top and the bottom of the range. If one order is executed, the other order can be deleted and then there is a end of day trading mechanism, which means that we either hit the stop loss of the position, or we make a big, big profit if the position will be closed by the end of the day. This is actually surprisingly successful and profitable. I also traded it in my live account. So let's now try to wipe code an expert advisor like this. So switching over to Gemini EA, I already prepared a prompt and it is the same prompt that I used before for chat GPT and Claude AI. So if you still have it in mind, you can skip this, but for everyone who is new here, I will read this prompt again. So my request is, create the following expert advisor for the Meta Trader 5. Do not include any Meta Trader 4 code. The Expert Advisor should execute the range breakout strategy in Meta Trader 5. The strategy uses a time-based range and then trades breakouts every day. The time period for the range should be easily changeable in the settings of the EA. It should be possible to optimize the time settings. During this time period, the EA finds the highest and lowest price. The range should be displayed visually in the trading chart. Pending orders are placed at the high of the range and the low of the range once the range is fully created. If a pending order cannot be placed and there is a breakout then it should open a market position. If orders are not executed, they will be deleted at a specific time, which should be selectable in the inputs of the EA. If positions are open by that time, they should also be closed. Also no more trades will be opened after this time.

[2:31]I also want to be able to choose the risk for every trade as a fixed money amount in the settings. The take profit and stop loss for every trade will be based on the range size of that day. In the settings, there should be an input for the factor. I also want to be able to trade without take profit so that the trades will only be closed at the specified time. I want to be able to trade both buy and sell trades a day or only one. If I select to trade only one trade per day, then the second order should be deleted once the first order is executed. So that is my prompt, and I will use this Gemini 3 flash preview. I think it's the default, so why not use this model and I will just build here. We can also see if the code is not useful, we can use the same prompt with a different model and then see what the um, yeah, what the outcome will be. So we can see here that the AI just as any other AI is now thinking and now creating some files, doing some calculations. It's interesting that it's only thinking for 9 seconds. Maybe it's because of the model I chose, but other AIs like the chat GPT AI and the Claude AI used a lot more time to think before actually getting to work. But let's see what the outcome will be. So and here we can see it was running for around 1 minute and then created this. And this is really surprising to me because none of the other AI tools gave me this sort of overview here, which is really interesting. So we do see the strategy simulation and this is new. Uh, we do have like range start, range end, and we can play around with this actually a bit. And then we do also have um, yeah, we do also have the the the the generate code here. I think this will actually show the MT5 code. And um, yeah, it's it's it's really funny to see this visualization and I think if I switch back and forth, it will also give different like trading results, which is kind of cool. But of course, this is just playing around. It can be good to to visualize a little bit and then um, yeah, we we we can generate the actual code. Let me just copy the code and let's move on to the Meta Trader 5. I will post it in like one of my files here and just compile and want to see if it works. Okay, there are no errors, which is a good sign for now I would say. So let's move over to the Meta Trader and try to test this very program here. I used the test two file for this. I will also use USD Japanese Yen. Let's maybe go with the same settings, uh, 3:00 to 6:00. I'm I'm not really happy to be honest that this is a um, text input because I explicitly asked for inputs that can be optimized. Maybe I was not clear enough, but of course I wanted to optimize it in the Meta Trader 5 and text inputs can uh cannot be optimized. Um, so this is not really what I wanted. Then we can um, yeah, use a take profit, we have a take profit range factor, stop loss. This is what I requested. Um, yeah, I don't know. Let's just, let's just see how, how this will turn out if we trade like this. With the default settings, I will just give it a go just to see what AI gave us in the most, like, in the default version. So I can see here we do see actually uh a range that is created. It's uh created in a way that we see two lines. It's not really beautiful and and and actually we can see already that this EA is not working at all how it was intended from, or by me. It's it's opening a lot of positions. It's really, really messy. It's closing the positions immediately, so it's it's not working at all. It's it's really not usable at this point. So I don't know what the problem could be. Maybe it is because we use a take profit and the the the take profit factor is zero. So let's put it to one, but even if it would be one, then I think uh, yeah, even if uh the trades are closed in the TP, it should not open like unlimited positions. Okay, with a TP factor of one, it is working a lot better, but yeah, you just saw that the previous errors were not really uh, yeah, we are not really good. And also we can see here, it's opening like way too many positions. I mean, I could clarify, but if I just think about that I gave the same prompt to chat GPT and Claude AI, the the results were actually way better. It's it's not even a comparison, I would say. So let's, let's try if I maybe mess this up and gave the um, prompt to the wrong um, model here. Let's switch the model. Maybe we go to the pro model instead. Okay, here I put the prompt again and we used the Gemini 3 Pro now and I'm just waiting for the result. Okay, so this seems to be even worse. We got an internal error. So let's retry and run again. Actually, I'm not sure if Gemini also has a paid version. So far, I'm using the versions that I got right away after signing up. So maybe there's also a paid version that is better, but let's just, um, yeah, see what the retry will do and if we can get a better version. Okay, so this time it looks better. We did get a result. We do have something that's looking a little bit different here. The preview, I would say, um, oh, no, actually, it's it's it's fine, I think. Um, we can download the MQL5. This is the code of I don't know what. This is not MQL5 code, I think it's maybe the code that was used to create the actual, like, MQL5 code, but we do get a preview. We don't get this little visualization here. So let's just copy the code and put it into the Meta Trader. Maybe I can use test three this time. And if we compare the lines of code are kind of similar. Let's see if the result is better. So going back to Meta Trader here, now is the test three program. I will have a look at the inputs. The inputs already look a little bit different. I think we have more inputs. I really like that now we do have integer inputs for the times, which makes optimization possible. This is what I ask for, so I'm glad that with this model we get the actual result for this. We do have SLTP, like before, we do have OCO or only one. Um, we have position close at time. This is new a little bit. Visualize range true. Okay, let's just not overthink and give it a go and see if this outcome now is better. Maybe the previous model was more like for quick answers and this is a little bit more like uh, yeah, better thought through. Okay, we see here the range is displayed differently. I like this way more. We see there's a breakout. Uh this is kind of fine. Oops, no, I was speeding up a little bit too much. But the EA is working kind of fast, which is a good sign. It means that it might be efficient. And I think this time, yeah, we actually see, um, the result that I wanted to see. Is looking way better. Unfortunately, it's uh deleting the previous, or the ranges from the last days, but I'm sure I could ask chat GPT, I'm not chat GPT, Gemini AI to keep them. But yeah, this is working way better. It's not messing up so hard. Let's see what happens if we don't use ATP, then we should trade end of day. And then also we can uh trade multiple orders maybe. Let's try this and let's also, yeah, let's let's try this first. And then also we can we can of course have a look at the code that we got here from the AI. I think this time it will be way better than the previous version. So here now I trade in a way that it closes the positions end of day and we don't have a TP. I think it's working out quite fine so far. Also we don't cancel the opposite order now and it is working just fine. So we can also trade two orders on one day. So I think this is working quite fine. You can see this is a program that can already make profits, but in this video it's not about profits, but creating programs with AI. So let's check what Gemini AI gave us here. We do see the include trade.mkh file. That's pretty much MQL5 programming basics. Then we do see what I already said before, we have inputs now, integer inputs now for the times, which is good for the optimization. We do have, yeah, I mean we, we looked at the inputs before, so nothing new here. We do have the magic number, which I like. Um, then we do have a few global variables, not too many actually, which is interesting. So, um, yeah, let's see. We set the expert by the magic number, that's good. And then we use the on tick. I like that. We calculate the range start, the range end, and the close time. This is valid how it is done here. Then we do have a new day reset. If current time is smaller than range start, then we reset all of our, all the necessary, uh, global variables here, I think.

[12:38]We, yeah, delete the um, objects. Uh, optional. Yeah, that's nice that it's optional. Delete, uh, the objects. So we could also delete these lines. It's it's nice that there's a comment for it. If we delete these lines, um, the the objects will stay and not be deleted. Then we can check for the close time. We close all of the positions. This is great. We delete pending orders. This is great. Um, during range, we wait for the range to complete. Okay, so we don't build the range during the range, I think, and just at the end of the range, which is really good for, like, run time efficiency. It's not the most visual approach. So if I would use it in live account, I think I would like to um, create the range already during, uh, the the range time. But this is also completely fine. Then here again, we draw the range, we get some prices. We calculate SL distance, uh, TP distance. Actually, this is really interesting. If you have a look at the functions here, we can see the approach of Gemini is completely different than the one that, for example, the Claude AI usually chooses because the Claude AI usually created a lot of custom functions, which makes the code maybe a little bit more readable and structured. And also, I realized Gemini AI uses a lot less lines of code in general compared to, for example, Claude. Um, but yeah, we we we calculate all of the values. Um, yeah, we we use the TP if the TP is um, like activated, we calculate the lot size. We have buy and, ah, we we open a buy position if we are above the range. That's also what I, um, expected. Then we do have a buy stop here. Actually, I think there could be problems if you start this after the range was, uh, created, because then you might open a position just way above the, uh, the range high or below the range low, which is not really good. I think there should be some mechanism to prevent this. Um, but yeah, in general, this is, I think, Ah, this is not good. Yeah, it is not perfect because here it says if positions total are greater than zero, we want to delete, ah, no, no, it's fine. Okay, sorry, sorry, sorry, I was messing it up. Okay, that's fine. That's, that's totally fine. Calculate range. It's using um, copy rates, uh, start end. Ah, okay, that's interesting that we loop through the array instead we could use um, copy high, copy low, but this is just a different approach. I think it's, it's totally fine. Um, also it's really inefficient because anyways, this program only calls this once per day to create the range. Then we calculate the lot size. This is pretty basic. There are some explanations. Yeah, this is, this is really basic. I also do this often in my programs. Delete pending orders helper, close positions helper, pretty straightforward and visualize the range. Okay, this is a very simple, like, short and precise code, I would say. It's kind of straight to the point, not a lot of functions, not a lot of global variables. It's it's really easy to see what the program does even if you're not super advanced programmer. I don't know if it's the most stable or, I mean it's not bad. It's it's very straightforward. Okay, let's, let's have a look at, um, the settings again. I mean, what I liked about the, like, this is really just what I requested. But what I kind of liked about the Claude AI is that it was giving also like the possibility to, like, have like an overnight range or closed at the next day only. And this is not really included here, I would say. Um, but yeah, also I didn't request it, so I cannot really complain, I think. And besides that, it is kind of doing exactly what I asked the AI to do. We can close, uh, like use this input to not close at a time and then instead just use a take profit, I think. Let's try this, maybe as the last one. And now you will also see that the, uh, that the range is no longer deleted because I deleted these two lines or this one line from the actual code that Gemini AI gave me. So this will be the last test. But overall, I would say the, the Gemini, like the second model I tested, it was kind of doing its job. It's not adding a lot of extra code here and there. It's really just doing what I requested, which is fine, because that's what I requested, right? And I'm sure that, and it was actually fast, like faster than the other AIs. Yeah, you can see now positions are open overnight, so this is also working. I think the code that I got here is working just fine. Let's, let's, let me do one last check. Like what happens if you open, if you activate this? I think there's like one problem, um, range determined false. False. Yeah, there's one problem, I think, if you activate this program after the range is completed. I think you will just open a position right away if there was a breakout already. So this is something that I think is not really beautiful. Um, but, um, but yeah, it is what it is. But I just realized it used a lot of returns in the on tick, which makes the code very, like, runtime efficient. So we are not wasting a lot of computer resources. This is also why the back test is extremely fast here. This is, um, something that other AIs don't do by default and you have to request more efficiency sometimes. Um, but yeah, yeah, here this is, um, yeah, the problem that I was talking about. Kinda. I think if we, uh, yeah, if we activate after the the range end time, then there's a little bit of a problem because we open right away. But except for this, it's really totally fine, I would say. And also, once we have positions already and then start the program again, it will also open more positions. So it's not like crash safe, but if you activate it and let it run all the time, I think it's safe to use this program. So that's Gemini AI's approach, like in a most basic version to create this expert advisor. I think the the result especially with the second model I tested, it is, it's it's really, it's really good. Um, what I think was, was interesting here is that we saw this little preview, which is kind of cool. It also, I think this is cool, because as you can see here, if I change these, uh, default inputs, it's also updating in the code. So this will be, uh, like watch this line here. This will be the actual default settings that you will then also see in the Meta Trader, which is kind of cool. This was not included in any of the other, uh, AI tools. So this is, I think, a benefit especially if you are like very, very, um, yeah, if you don't want to code at all and you don't even want to change anything in the code, then this is a good approach to use Gemini AI.

[20:27]So yeah, this was the comparison of all of the three, probably biggest AIs that people use at this point. Let me know in the comments what you think about these AIs, which one is your favorite and what do you think about Gemini AI specifically? I hope the little overview like series about building the same expert advisor with three different AIs was interesting to you and I will be glad to read your comments. Until then, have a great time and good trades. I will see you in the next video. I'm out. Bye-bye.

Need another transcript?

Paste any YouTube URL to get a clean transcript in seconds.

Get a Transcript