Skip to content
Archive
← r/algotrading
2
100%
u/Shot_Loan_354 1 day ago Other/Meta

Any tips on how to migrate an EA from mql4 to mql5?

Since less and less prop firms are offering MetaTrader4 and switched over to MT5, I'm planning to rewrite my MT4 EA in mql5, and i thought to ask if anyone here has any tips on how to make this procedure quicker / smoother. I'm currently taking an mql5 programing course to see what they did differently to the syntax compared to mql4, and I'm planning to migrate the code in pieces, function by function, and use ai to get it done faster, and i thought to ask here, maybe one of you had to do something similar at a certain time, so I could learn a thing or two from your experience. thanks in advance.
8 comments held Reddit says 5 on reddit ↗
  1. u/CommandantZ 3 1 day ago
    Professional bot developer here, No specific advice, what you're doing is fine. Maybe one actually, don't hesitate to look at the "C" libraries. As in "CTrade", "CPosition" and so on. They remove much of the verbosity of native features. (Typically, instead of using OrderSend(), you will use your CTrade instance and just call trade.Buy or trade.Sell without needing to go through using an MqlTradeRequest structure). https://www.mql5.com/en/docs/standardlibr… More specifically: https://www.mql5.com/en/docs/standardlibr…
  2. u/UnnecessarilyTested 1 1 day ago
    The CTrade classes are a godsend when moving from 4 to 5, cut my migration time by maybe 40% once I stopped trying to roll my own order management. The one thing that tripped me up was the event handling model, in MT4 you just had start() and that was it, but MT5 uses OnTick, OnTimer, OnTrade etc and if you're not careful you end up with logic firing in places you didn't expect. Good call doing it function by function, trying to do a wholesale port in one shot is a great way to end up with 600 compiler errors and a headache.
  3. u/ShaznayNordgauer74 1 1 day ago
    yeah the standard library classes make a huge difference, way less boilerplate to deal with
  4. u/SysZeron 3 1 day ago
    Artificial Intelligence will rewrite it for you in one go. Have it do regression testing (i.e. generate sample data, test against 4, rewrite, test against 5 using the same sample data, compare the two results to ensure they’re the same). Then do manual tests of both versions yourself to compare, backtest and demo.
  5. u/QuanTradin 0 1 day ago
    port it function by function, but keep the MT4 version running on the same data and diff the two trade lists. order handling is where they differ most, MT5 positions and deals don't map one to one onto MT4 orders, so that's where the AI will quietly get it wrong.
  6. u/Aggressive_Listen849 1 1 day ago
    the thing that bit me: in mql5 OrdersTotal() only counts pending orders. open trades are positions, so every OrderSelect loop from mql4 becomes PositionsTotal() + PositionGetTicket(). also check if the account is hedging or netting, closes behave differently.
  7. u/[deleted] 1 1 day ago

    [removed] — already gone when the archive first saw it

  8. u/artemiusgreat 1 1 day ago
    This person follows all changes in MQL5, writes article about different EAs and libraries, and posted library that allows to run MQL4 in MT5. https://www.mql5.com/en/code/16006