MT5 Drawdown Safety Expert Advisor Programming Tutorial

Поділитися
Вставка
  • Опубліковано 19 лис 2024

КОМЕНТАРІ • 91

  • @kidafrica7621
    @kidafrica7621 2 роки тому +11

    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 роки тому +4

    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 2 роки тому

      @ 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 ?

    •  2 роки тому

      @@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 роки тому +3

    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 роки тому +1

      I am sorry but I focus on mql5 right now :/

  • @andresgiraldo2723
    @andresgiraldo2723 Рік тому +1

    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 10 місяців тому

      Thank you for resharing this. O can use this code alone, or i have to put it under Rene’s code?
      Thank you

  • @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!

  • @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!!!!👍👍

  • @sectionone1111
    @sectionone1111 3 місяці тому

    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

  • @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

  • @arashm.1556
    @arashm.1556 5 місяців тому

    Thanks Rene, Much appreciated. very educational and very useful. cheers

  • @antonhassan
    @antonhassan Рік тому

    This is a very valuable lesson. Thanks, Rene. 🙏🏻

  • @shane1474
    @shane1474 2 роки тому

    Your vids got me into ea I made my first one and I passed my mff account in one day

  • @WeslleyBorgesWBGames
    @WeslleyBorgesWBGames 6 місяців тому +1

    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?

  • @americanlife360
    @americanlife360 2 місяці тому

    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?

  • @pengshiqi7335
    @pengshiqi7335 2 роки тому +1

    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 11 місяців тому

      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.

  • @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 роки тому +1

      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 :)

  • @AbdoAbdo-tw4mn
    @AbdoAbdo-tw4mn 2 роки тому

    Nice job , I hope you will talk about HFT in the next video.

  • @KingjakesFx
    @KingjakesFx Рік тому +1

    how can i modify this code to reset the drawdown reached limit at midnight server time. Please Help

  • @samirrayes616
    @samirrayes616 22 дні тому

    Hey, not sure what i'm doing wrong, but the safetyTool won't close my trades when my drawdown switches to true. Is there something I might be missing? Thanks.

  • @peterezeh196
    @peterezeh196 5 місяців тому

    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.

  • @ramiali6269
    @ramiali6269 2 роки тому +1

    please upload it to MQL and add this GV_DRAWDOWN Checker in your scalping project ea

  • @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.

  • @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?

  • @shakuganoshanayoutube4112
    @shakuganoshanayoutube4112 2 роки тому +1

    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 ?

    •  2 роки тому

      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 2 роки тому

      @ thank you a lot !

  • @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?

  • @gymlol
    @gymlol Рік тому +1

    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!

  • @alirezafaramarzi6396
    @alirezafaramarzi6396 2 роки тому

    Hi Rene. Please talk about the server and its features in automated trading...

    •  2 роки тому +1

      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.👌

  • @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?

  • @Fxmoneyman98
    @Fxmoneyman98 Рік тому

    How can I get this i really need it

  • @marvine.6155
    @marvine.6155 2 роки тому

    Great work

  • @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.

  • @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 роки тому +1

      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 ;)

  • @TMGdeals
    @TMGdeals 6 місяців тому

    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?

  • @mahanharirpoush9190
    @mahanharirpoush9190 2 роки тому

    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)

    •  2 роки тому +1

      Hm could be true. You can solve this if you only update the equity max variable if the day changes.

  • @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.

  • @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/

  • @mitrecyclers
    @mitrecyclers Рік тому

    How can we close lets say 50% of trade if that particular trade is over 1% of account limit?

    •  Рік тому +1

      The CTrade class has a PositionClosePartial function: www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade

  • @Kubtrading
    @Kubtrading Рік тому

    Where can I have this EA?

  • @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 роки тому +1

      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 роки тому +1

      @ 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 ;)

  • @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.

  • @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.

  • @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 роки тому +1

      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

  • @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 ;)

  • @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

  • @elkarourkhalid5857
    @elkarourkhalid5857 Рік тому

    Share Source Code plz

  • @AbdoAbdo-tw4mn
    @AbdoAbdo-tw4mn 2 роки тому

    Do you do freelance jobs ?
    I have an Idea to be coded?

    •  2 роки тому +1

      Hey, no I am sorry but I do not offer any programming services.

  • @koi4feur990
    @koi4feur990 2 роки тому

    Hey man how can contact you for a partnership?

    •  2 роки тому +1

      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.

  • @WasimZayed
    @WasimZayed 2 роки тому

    Hi, be careful some scammers are using your name to scam your followers with fake account

    •  2 роки тому +1

      Yeah I know :( I think these are mainly bots and there is nothing I can do about it.. Hope UA-cam finds a way to solve this issue someday.

  • @Kandy_Ltd
    @Kandy_Ltd 2 роки тому

    First to comment 😁

    •  2 роки тому

      :)