MT5 Drawdown Safety Expert Advisor Programming Tutorial

  Рет қаралды 12,450

René Balke

René Balke

Күн бұрын

Пікірлер: 90
@kidafrica7621
@kidafrica7621 2 жыл бұрын
Rene wanted to say that I appreciate you giving all this trading robot knowledge to the public for free , because I recently started learning how to code my own personal EA and all of your videos have been extremely helpful in shedding light towards automating my trading. God Bless you and I pray that you get everything that you want in life.
@jaspersteven1964
@jaspersteven1964 2 жыл бұрын
Programmed a similar ea some weeks ago. Its very interesting to watch another Person solving the Problem in another way. Like your Videos very much 👍
2 жыл бұрын
Thanks :)
@shakuganoshanayoutube4112
@shakuganoshanayoutube4112 Жыл бұрын
@ Hello @René, useful info as usual. Quick question : 1. Why use OnTimer instead of Ontick ? 2. What's the purpose of using a static int instead of a regular int ?
Жыл бұрын
@@shakuganoshanayoutube4112 You can use OnTimer or OnTick. Do I use OnTimer in the video? static int will not be deleted if the function terminates: www.mql5.com/en/docs/basis/variables/static
@stefd5886
@stefd5886 2 жыл бұрын
Thank you for sharing all of this with us, I would love to have all the things you are sharing in mt4 too. Thanks
2 жыл бұрын
I am sorry but I focus on mql5 right now :/
@sooriya2156
@sooriya2156 2 жыл бұрын
Thank you rene for answering my query. I did not expect you to deliver. You are a great youtuber thanks so much!
@sectionone1111
@sectionone1111 2 ай бұрын
Would be interesting to see a tutorial for auto-reducing risk percentage given the allowed daily drawdown and SL distance. So that even if it reaches SL, it will not violate the rules. Instead of closing positions mid-way
@andresgiraldo2723
@andresgiraldo2723 Жыл бұрын
Hi René, another great video, thanks! Regarding the max daily DD rule for the MyForexFunds it says: "A trader must not loose more then 5% of daily starting equity. Drawdown % = [1 - (lowest equity for the day) / (starting equity for the day) ] X 100. A trader will have more drawdown if the account is in positive and less if it is in negative" Based on the previous formula, I created the following code: int barsD1; double equityLow, equityStart, equityCurrent, ddPercent; bool ddAlert; bool CheckDrawdown(double maxDailyDrawdownPercent) { int bars = iBars(_Symbol, PERIOD_D1); if(barsD1 != bars) { Print(__FUNCTION__, StringFormat(" > NEW DAY! Resetting daily drawdown ... max daily DD was %.2f%%", ddPercent)); barsD1 = bars; equityStart = AccountInfoDouble(ACCOUNT_EQUITY); equityLow = equityStart; ddPercent = 0; ddAlert = false; } equityCurrent = AccountInfoDouble(ACCOUNT_EQUITY); if(equityCurrent < equityLow) { equityLow = equityCurrent; ddPercent = (1 - (equityLow / equityStart))*100; ddAlert = (ddPercent - maxDailyDrawdownPercent >= 0); if(ddAlert) { Print(__FUNCTION__, StringFormat(" > DD: %.2f%% !!! ALERT !!!", ddPercent)); } } return ddAlert; } ... and inside the OnTick function, something like: if(CheckDrawdown(4)) { //TODO: Close losing positions and prevent new position until tomorrow. } In the Close losing positions implementation, I'll close only the positions relevant to this EA and that are losing money. I don't want to close the wining deals. For other challenges like the FTMO or TheFundedTrader I think this code has to be changed in order to comply with the DD rule. Just my two cents. Thanks man!
@petr5178
@petr5178 9 ай бұрын
Thank you for resharing this. O can use this code alone, or i have to put it under Rene’s code? Thank you
@KaliteyClips
@KaliteyClips 2 жыл бұрын
OMG René, you just coded Gold imho!! I was always looking for small drawdown EA's, but with this program, you can run any EA without breaching the max permited drawdown...🙏 When I see you coding, I just want to learn that also...it seems to be so much fun to create whatever you come up with...please keep it up René, all thumps up!!!!👍👍
@NoTime1407
@NoTime1407 Жыл бұрын
thanks Alot. very helpful. glad you started doing videos in English
@Foryou-Relax
@Foryou-Relax Жыл бұрын
thank René Balke, you are a nice teacher
@pengshiqi7335
@pengshiqi7335 2 жыл бұрын
Hi Rene, I guess there will be a bit of an issue for resetting your drawdown every time the day changes. I think you should update your static variable's value inside your if (GlobalVariableCheck(GV_DRAWDOWN)). Because if you update its value outside that if function, bars and barsTotal will always differ. The static variable is always updated at the end and it will hold its value until the next execution. In the next execution, the bars variable will be changed, but the barsTotal variable will still be at the previous value. I'm just wondering, if I'm not mistaken. Please correct me if I'm wrong. Hehe :) I'm also still learning. Thank you anw for sharing such great content with us.
@sooriya2156
@sooriya2156 2 жыл бұрын
Hi, I was having an issue with this while backtesting as well. Futhermore, I noticed while backtesting the drawdown indicator was displaying 0.00 any ideas why as well?
@DestoTrading
@DestoTrading 10 ай бұрын
Of course there is an issue, most of his videos are showing concept ideas that are not finished or polished. He just writes them on the spot (with lots of mistakes) and therefore the ideas are basically useless if you can't finish them by yourself.
@arashm.1556
@arashm.1556 5 ай бұрын
Thanks Rene, Much appreciated. very educational and very useful. cheers
@americanlife360
@americanlife360 Ай бұрын
Hi, Rene. thanks for sharing MT5 EA for equity drawdown. can you please share the completed MQL5 EA code you did in this video? I write almost the same code in MQL5 but its showing 30 errors and 3 warnings?
@antonhassan
@antonhassan Жыл бұрын
This is a very valuable lesson. Thanks, Rene. 🙏🏻
@shakuganoshanayoutube4112
@shakuganoshanayoutube4112 Жыл бұрын
Hello @René, useful info as usual. Quick question : 1. Why use OnTimer instead of Ontick ? 2. What's the purpose of using a static int instead of a regular int ?
Жыл бұрын
Hey :) Did I use OnTimer? You can use both I think. OnTimer can make sense because different EAs are communicating here and the ticks can be different. This might result into a delayed order cancellation in other charts if there are no ticks at the time when the drawdown is reached. Static variables are not deleted if the function terminates. You can read about it here: www.mql5.com/en/docs/basis/variables/static
@shakuganoshanayoutube4112
@shakuganoshanayoutube4112 Жыл бұрын
@ thank you a lot !
@peterezeh196
@peterezeh196 4 ай бұрын
Hi Rene. Great video. I have a question. I tried this on the strategy, and when it's get to the equityMax it doesn't close all the positions. Can you help me out.
@FighterFred
@FighterFred 2 жыл бұрын
Good work, but this exist already with the equity protector from Earnforex. That EA has a lot of functions. What would be very helpful is a MT5 indicator that prints the current and max drawdown in percent and also produces a time line in a separate window. In that way we can backtest and see exactly when a DD occurs, which can be very helpful if the prop firm claims that we broke the DD rule. Just my thoughts.
2 жыл бұрын
Hey, thanks for the comment. I think a lot of functions/programs already exist. But this channel is all about learning how to code your own EAs and a lot of people requested this :)
@WeslleyBorgesWBGames
@WeslleyBorgesWBGames 5 ай бұрын
very cool video! thank you very much! Friend, could you help me create a robot for shopping for mobile media? It's probably not very difficult, but I really don't know how to do it, I know that averages don't work that well, but for my operating style, I would like to test some ideas that I've been having since I started following the chart however, it would be for use with RENKO chart Could you tell me if this would be possible?
@NazoStudios
@NazoStudios Жыл бұрын
Hi Rene! I have followed all your instructions but I have the problem that when a new day arrives, equity max and equity becomes the same and drawdown % stays at 0. So everyday I have to delete the EA and add it again. I mean, the EA works perfectly on the first day but then it stop working. I believe is because of the equityMax = equity after PERIOD_D1. How can I fix this?
@KingjakesFx
@KingjakesFx Жыл бұрын
how can i modify this code to reset the drawdown reached limit at midnight server time. Please Help
@AbdoAbdo-tw4mn
@AbdoAbdo-tw4mn 2 жыл бұрын
Nice job , I hope you will talk about HFT in the next video.
@addICTed_to_USD
@addICTed_to_USD Жыл бұрын
What's the difference between this and a stoploss? Don't they both pretty much operate the same or produces the same results?
@shane1474
@shane1474 2 жыл бұрын
Your vids got me into ea I made my first one and I passed my mff account in one day
@rashadj1832
@rashadj1832 2 жыл бұрын
Hi Rene! Great video as always!! I had a quick question that you may know the answer to or even make a video on - when you optimize or model your EAs, do you use Every Tick data OR Every Tick Based on Real Ticks? Surprisingly, they produce very different results (recently tested with your scalping EA) - wondering what the difference is and if one is more appropriate to use than the other based on the EA I guess
2 жыл бұрын
Hey, thanks for the kind comment. I think 'based on real ticks' should produce the most accurate results.
@rashadj1832
@rashadj1832 2 жыл бұрын
@ Ok so I did some further digging because whenever I used “based on real ticks”, the results would be pretty bad to say the least (for the scalping EA). As the data for these “based on real ticks” is related to the individual broker, I opened a demo raw spread account with IC Market to compare the results with my previous broker. I found that IC Market data is missing a lot of “real ticks” indicted in the Journal tab within the strategy tester at the start of the tests compared to my previous broker. Further, I noticed that the spread is always practically 0 throughout the test (unrealistic) which is the main reason IC Market testing produced better results. I am curious if you also noticed 0 spread throughout your testing as it could explain why the scalping EA is too good to be true 🤕 - just thought I would share my findings thanks again!
2 жыл бұрын
@@rashadj1832 Thanks for sharing your experiences. In my tests I see the spread. But with the raw spread account it is usually really small anyway. I am running it in a live account so I will be able to compare the tester results to the live results soon ;)
@NoTime1407
@NoTime1407 Жыл бұрын
Hello Rene, wanted to ask, how come after the risk/drawdown target has been activated/reached, the code isnt allowing any more positions to open. keeps saying on the experts tab, "CTRADE:: OrderSend: cancel #number [invalid request]" ? any help on that . i think its refusing to reset.
@louisfourie3081
@louisfourie3081 2 жыл бұрын
Hi Rene. Your videos are extremely helpful😊 thanks for all the hard work. I was wondering if it is at all possible to have an EA that reads the code from an external source such as a website? I wish to create an EA that can be changed by updating the external source.
2 жыл бұрын
Thanks :) yeah this is possible. You can do nearly everything with mql5 programming.
@taztheworld5922
@taztheworld5922 2 жыл бұрын
Hi, great video, but the variable "Expirationhours" and "orderdistpoints" are deleted ? or the data are put directly in the code ?
2 жыл бұрын
I changed the algorithm a bit. The EA in this video works different than the one from the programming tutorial.
@tailorgd
@tailorgd 2 жыл бұрын
Hey Rene, thanks so much for such an informational series, please keep them coming. One question, could this block of code just be included included in our trading EA instead of having it as a separate program? Also, in the example of your prop firm rules where it is 5% drawdown per day and 10% total let's say you won a few trades taking your equity up 5% but then lost a few triggering the EA's set limit of 4% (keeping a buffer of 1%) to prevent account termination. You would still acutally have 6% drawdown to go for the day using this logic. I could be wrong but I don't think this example would account for this. Could you show us a way to code a solution that would account for this scenario as well? Thanks again!
2 жыл бұрын
Hey, I am glad you like it :) you can also put this code into your EA. It does not have to be a separate program. You can also change and modify the code as you like. I do not think I will make another video about this soon. I am sorry.
@tailorgd
@tailorgd 2 жыл бұрын
@ Np, thanks for the reply! I think I can figure it out, just wanted to see your solution. Thanks again!
@Capital247
@Capital247 Жыл бұрын
@ pls i have a question, i'M atrader for about 2years now, but i want to learn how to program trading tools, so do i need to start leaning how to program ea or i should first start with learning custom indicators, before learning ea. pls i need your advise.
Жыл бұрын
@@Capital247 Hey, I always felt that EA programming is even easier than indicator programming. You can just start with EAs ;)
@ramiali6269
@ramiali6269 2 жыл бұрын
please upload it to MQL and add this GV_DRAWDOWN Checker in your scalping project ea
@anthonokayster6326
@anthonokayster6326 Жыл бұрын
Hi. Is it possible to add buy or sell limits to my EA with specific instructions for each limit (example, the next limit should increase in lot size and decrease in the amount of pips), something like that?
@gamingfreak2141
@gamingfreak2141 Жыл бұрын
Can't we code like 5% DD on Martingale EA than open a opposite trade and modify tp at no loss no profit zone also disable auto trades, is this possible?
@marvine.6155
@marvine.6155 2 жыл бұрын
Great work
@TMGdeals
@TMGdeals 5 ай бұрын
great video, I learned a lot. What if you did not want the drawdown for percentage, but instead a specific amount? Example if I wanted all trades to close at $2,000 drawdown?
@gymlol
@gymlol Жыл бұрын
Hey René, I used the expert adivsor on my VPS but then the global variable does not show up in the global variable tab. However if I use it on my local PC it does show up in my global variables. How can this happen?
Жыл бұрын
Yeah I do not recommend using the mql5 'trading' VPS. With a normal VPS you can see the variables as on your local PC.
@gymlol
@gymlol Жыл бұрын
@ Just to make sure, does the variable only show up after the (INPUT) drawdown% is hit, or does it show up once you put it on your chart?
Жыл бұрын
@@gymlol only when the drawdown it hit
@gymlol
@gymlol Жыл бұрын
@ Ok, thank you very much!
@mahanharirpoush9190
@mahanharirpoush9190 Жыл бұрын
Hi Rene, if I understood this correctly, even if you are in profit, the system recognizes this as a drawdown because there is no minus. In case you are 4 percent in profit, it will also close all positions. Is this correct? if yes, how can we redefine the drawdown calculation so that it also includes minus values ( when you are in profit)
Жыл бұрын
Hm could be true. You can solve this if you only update the equity max variable if the day changes.
@alirezafaramarzi6396
@alirezafaramarzi6396 2 жыл бұрын
Hi Rene. Please talk about the server and its features in automated trading...
2 жыл бұрын
Hey, do you mean the VPS I run my EAs on? I plan to do this ;)
@alirezafaramarzi6396
@alirezafaramarzi6396 2 жыл бұрын
@ This is exactly what I mean.👌
@d3.finance
@d3.finance 2 жыл бұрын
Hello Rene. First I want to say I enjoy all your content and thank you for putting this great knowledge out into the world. I was thinking about signing up for your course but I wanted to ask if we are able to message you direct questions that we have as a part of the course? Thank you
2 жыл бұрын
Hey, thanks for the kind comment :) I would love to see you in the course. I cannot provide individual support though. But this should not be necessary in the first place. In the course you learn everything you need to know about EA coding. Also you can always come back and watch the lectures again if you have any questions.
@KaliteyClips
@KaliteyClips 2 жыл бұрын
@ is there also some guidance to find your way in MT4/MT5 in the course regarding the usage of EA's and coding, etc? I've only used MT4 for live trading and I find myself getting lost sometimes in the EA sections and features...
2 жыл бұрын
@@KaliteyClips hey, I don't really understand. Do you mean my programming course? In the course you will learn how to write expert advisor code. You can have a look at my website for more information about it: en.bmtrading.de/mt5-masterclass/
@Fxmoneyman98
@Fxmoneyman98 Жыл бұрын
How can I get this i really need it
@mitrecyclers
@mitrecyclers Жыл бұрын
How can we close lets say 50% of trade if that particular trade is over 1% of account limit?
Жыл бұрын
The CTrade class has a PositionClosePartial function: www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade
@Kubtrading
@Kubtrading Жыл бұрын
Where can I have this EA?
@sadiqabdulazeez6530
@sadiqabdulazeez6530 2 жыл бұрын
After placing my trade Does my mt4 need to be constantly connected to the Internet for it to close the trade??
2 жыл бұрын
It depends. If you place a SL or TP it will be executed even if the mt4 is closed. But if you want to close the trade using an expert advisor you have to be connected to the internet.
@limzicheng1412
@limzicheng1412 2 жыл бұрын
Hi, can I use 2 EA at the same time? I mean my currect EA + drawdown EA
2 жыл бұрын
Yes you can use as many EAs as you want. Just open a new chart for each EA ;)
@AbdoAbdo-tw4mn
@AbdoAbdo-tw4mn 2 жыл бұрын
Do you do freelance jobs ? I have an Idea to be coded?
2 жыл бұрын
Hey, no I am sorry but I do not offer any programming services.
@Cimolnyoy
@Cimolnyoy 2 жыл бұрын
Rene please advice how to change constan
2 жыл бұрын
You cannot change a constant. That is why it is called 'constant' ;)
@Cimolnyoy
@Cimolnyoy 2 жыл бұрын
@ i mean i have a mq4 file i want change constans
@adamjuniorfx
@adamjuniorfx 2 жыл бұрын
That's good am trying to put the code in my EA but when I try to text it it show zero divided from my EA but I think I try to generate #include file, is that right ?
2 жыл бұрын
You can do both I think. A zero division always produces a critical error. You should check all you divisions in the code again and make sure that you never divide by 0.
@adamjuniorfx
@adamjuniorfx 2 жыл бұрын
@ ok thank you sir
@elkarourkhalid5857
@elkarourkhalid5857 Жыл бұрын
Share Source Code plz
@koi4feur990
@koi4feur990 2 жыл бұрын
Hey man how can contact you for a partnership?
2 жыл бұрын
Easiest way is on mql5. But I am not really looking for partnerships and I am usually not interested. You can still write me and if I like it we can have a look at it together.
@teresasean3117
@teresasean3117 2 жыл бұрын
If there is one thing I have learned in recent months it is to remain calm, especially when it comes to investments in cryptocurrencies. Learn not to sell in a panic when everything goes down and not to buy in euphoria when everything goes up. I advise y'all to forget predictions and start making a good profit now because future valuations are all speculations and guesses. The market is very unstable and you can not tell if it's going bearish or bullish. While myself and others are tradimg without fear of making a loss others are being patient for the price to skyrocket. It all depends on the pattern you follow.
@WasimZayed
@WasimZayed 2 жыл бұрын
Hi, be careful some scammers are using your name to scam your followers with fake account
2 жыл бұрын
Yeah I know :( I think these are mainly bots and there is nothing I can do about it.. Hope KZbin finds a way to solve this issue someday.
@Kandy_Ltd
@Kandy_Ltd 2 жыл бұрын
First to comment 😁
2 жыл бұрын
:)
Crypto Pours Millions Into 2024 Elections | Bloomberg Crypto 10/23/2024
44:49
小丑家的感情危机!#小丑#天使#家庭
00:15
家庭搞笑日记
Рет қаралды 35 МЛН
Fake watermelon by Secret Vlog
00:16
Secret Vlog
Рет қаралды 29 МЛН
НИКИТА ПОДСТАВИЛ ДЖОНИ 😡
01:00
HOOOTDOGS
Рет қаралды 2,8 МЛН
Sigma baby, you've conquered soap! 😲😮‍💨 LeoNata family #shorts
00:37
Find High and Low Peaks with MQL Code
17:33
Orchard Forex
Рет қаралды 38 М.
Easy Scalping Strategy For EURUSD | Free MT5 Expert Advisor Coding
53:33
MT5 News (Calendar) Expert Advisor Programming Tutorial
27:39
René Balke
Рет қаралды 10 М.
The Easiest Way to License your MetaTrader Expert Advisor
15:48
René Balke
Рет қаралды 17 М.
小丑家的感情危机!#小丑#天使#家庭
00:15
家庭搞笑日记
Рет қаралды 35 МЛН