| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| MQL5 to MQL4 functions https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=6440 |
Page 1 of 1 |
| Author: | Thunderbolt4x [ Tue Aug 19, 2025 10:16 am ] |
| Post subject: | MQL5 to MQL4 functions |
Hi, I started to post this subject on another forum but there wasn’t any interest in it so I thought I might try here. The majority of the code on the Internet that I have seen allowing people to write programs for both MQL4 and MQL5 is written from an MQL5 point of view, which means that coders still need to know how to code for the MT5 platform. I think that there are still a lot of NON object oriented coders out there who would like to make their existing programs run on MQL5 as well as MQL4 without learning OO and with the minimum of fuss. What I plan to do is convert MQL4 functions and use the same parameters as the existing functions in MQL4 but make them also work in MQL5. The function name will be the same as that in MQL4 except that it will have an underscore appended to the name. This way it will be displayed in the MQL4 MetaEditor IntelliSense screen beneath the standard one. The function will also return the same value as the standard MQL4 one. Functions that work the same on both platforms will generally be left alone, it is the ones that are used in MQL4 but not MQL5 or ones that return different values that will be the initial focus of this project. E.g. in MQL5 the OrdersTotal() function is used differently to how it is in MQL4 and returns the number of pending orders placed. So I use the function below. Code: Select all If coders here think there is a need for this project then I will proceed. I say this because I really appreciate comments and suggestions from other coders as I believe there is always a better way to do something. Thanks, TB |
|
| Author: | dydynamic [ Thu Aug 21, 2025 10:08 pm ] |
| Post subject: | Re: MQL5 to MQL4 functions |
I'm not a coder but i would love to see you pursue your desire of making a better mql4 for the sake of all retail traders that are interested in coding but are finding it hard to code. thanks for coming here. i really appreciate your kind gesture. |
|
| Author: | Thunderbolt4x [ Fri Aug 22, 2025 2:45 am ] |
| Post subject: | Re: MQL5 to MQL4 functions |
OK, I'll start posting the functions but it is important to know that you will still need to know how to code MQL4 programs. All I am doing is making the MQL4 functions compile on both platforms. With each function I will create scripts to enable the code to run on both platforms as an example. I will also include an explanation of what has been done. |
|
| Author: | Thunderbolt4x [ Fri Aug 22, 2025 8:39 am ] |
| Post subject: | Re: MQL5 to MQL4 functions |
Before we dive into the different functions I will explain how we get the same code to work on both the Empty4 and MT5 platforms without doing a lot of copy and pasting. The code for this example is called TestScript and is attached to this post. We create 3 files. A file to compile the code file for Empty4, a file to compile the code file for MT5 and the code file itself which contains all the working code. All 3 files are put in the Scripts folder. The Empty4 compile file is called TestScript.mq4. The MT5 compile file is called TestScript.mq5. The code file is called TestScript.mqh. The code for TestScript.mq4 Code: Select all Code: Select all The code for TestScript.mqh Code: Select all |
|
| Author: | Thunderbolt4x [ Mon Aug 25, 2025 12:59 am ] |
| Post subject: | OrderSend_() |
Hi, I thought that we would start with a function with a bit of meat in it, so this is the OrderSend_() function which replaces the built in Empty4 OrderSend() function. There are a couple of ways to create orders in MT5 but I think that this is the most transparent way. Another way is to use pre-defined MT5 classes which I think adds another element of complexity to this project and I am trying to keep it as MT4ish as possible. The example script that calls the function creates two sell orders, one is a market order and the second is a pending order. MT5 isn’t as straight forward as Empty4 when it comes to placing orders as as they are divided onto separate pools of Orders and Positions. When they go to the broker they become a deal. My goal is to create functions where the Empty4 coder doesn’t need to worry about these different types. Below is the code for the OrderSend_() function. I have added quite a few comments for those that are interested to read them but it isn't necessary to do that, or to understand the function code at all for that matter. The purpose of this project is to make your Empty4 code work on MT5 without needing to know a lot of the ins and outs of the language differences. Code: Select all I think that the main changes to standard Empty4 code will be the missing predefined variables in MT5. E.G. the following variables are not in MT5 Bid, Ask, Digits and Point. The code change to get these values is the same in Empty4 and MT5 and is as follows. Code: Select all OP_BUY, OP_SELL, OP_BUYLIMIT, OP_BUYSTOP, OP_SELLLIMIT and OP_SELLSTOP are not in MT5 and need to be replaced with ORDER_TYPE_BUY, ORDER_TYPE_SELL, ORDER_TYPE_BUY_LIMIT, ORDER_TYPE_SELL_LIMIT,ORDER_TYPE_BUY_STOP and ORDER_TYPE_SELL_STOP and are of type ENUM_ORDER_TYPE. ***** Installation Instructions ***** * Copy all three files to the Empty4 and MT5 Scripts folder. * For Empty4 compile theOrderSend.MQ4 file * For MT5 compile theOrderSend.MQ5 file ***************************************************** If you have any questions or suggestions please let me know. |
|
| Author: | Thunderbolt4x [ Mon Aug 25, 2025 3:00 am ] |
| Post subject: | WindowExpertName_() |
Hi, This is a very simple one. This is the WindowExpertName_() function which replaces the built in Empty4 WindowExpertName() function. In MT5 there is no WindowExpertName() function so we will call MQLInfoString() which is available on both platforms. Below is the code. Code: Select all ***** Installation Instructions ***** * Copy all three files to the Empty4 and MT5 Scripts folder. * For Empty4 compile file with the MQ4 extension. * For MT5 compile file with the MQ5 extension. ***************************************************** If you have any questions or suggestions please let me know. |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|