GRat Order Exchange
Info
The GRat Order Exchange is a Library for MetaTrader 5 that the attached. mqh files are designed to export orders and trades from one EA and import them into another one (copying trades), which can be run both in the same terminal and in another terminal on the same computer.
Usage
This tool is typically used for enhancing chart analysis and decision making.
Platform
This Library works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Libraries folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use GRat Order Exchange
1. Storage: Place library files in the MQL/Libraries directory to ensure they are accessible to your projects.
2. Implementation: Include the library in your code using the #import directive, ensuring you match the exact function names and parameters.
3. Compilation: Ensure the library is present in the directory before you compile your main EA or script, as the compiler links them during this phase.
4. Management: Keep libraries organized in sub-folders if you manage many custom functions to maintain a clean project structure.
Frequently Asked Questions
Q: What is a library file used for? A: Libraries store reusable code modules, allowing you to centralize common logic used by multiple EAs or indicators.
Q: Is a library executable? A: No, libraries are non-executable files containing functions; they must be imported into an EA, indicator, or script to function.
Q: Can I update a library while the platform is running? A: You should compile your EA or script after updating a library to ensure the latest code changes are integrated.
What this tool does
The attached.
Typical Use Case
This Library excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Library works on MetaTrader 5. Place the file in the MQL5/Libraries folder and restart the terminal.
Description & Settings
Related: Simplified Order Management Class for MT4/MT5 - another powerful library for MetaTrader 5 traders.
The attached .mqh files are designed to export orders and trades from one EA and import them into another one (copying trades), which can be run both in the same terminal and in another terminal on the same computer. It is also possible to exchange trades between different symbols, for example, copy trades of an instrument of spot market on the corresponding futures or any other instrument that correlates with it.
Also recommended: AS Q Order Executor - similar library with strong performance on MetaTrader 5.
ExportYou need to include the
GRat_OrderExport.mqh
file to your exporting EA with the following command:
This must be done in the input parameters area exactly in the place where the export parameters should be:
Common
-
true
- export to another terminal on the same computer;
false
- export to the same terminal.
KeepSeconds
- how many seconds of exported trades are available for import.
0
- unlimited.
Then, in the EA code, wherever orders are executed by the
OrderSend()
function (or methods of the
CTrade
class), you need to add a call to the
ExportOrder()
function, for example:
The
MqlTradeRequest
structure can be used the same as for the
OrderSend()
function, but you should fill additional
MqlTradeRequest
fields for actions
TRADE_ACTION_DEAL (for closing positions), TRADE_ACTION_SLTP
,
TRADE_ACTION_REMOVE
and
TRADE_ACTION_MODIFY
:
type
(to modify positions it should be
ORDER_TYPE_BUY
- for a long position and
ORDER_TYPE_SELL
- for a short one)
volume
price
(only for pending orders)
stoplimit
(only for Stop Limit orders)
sl
tp
position
(positive value, only for closing positions)
An example implementation of an exporting EA is .
Import
You need to include the
GRat_OrderImport.mqh
file to your importing EA with the following command:
You need to do this in the input parameters area exactly in the place where the import parameters should be:
Common
-
true
- import from another terminal on the same computer;
false
- import from the same terminal.
VolumeFactor
- multiplier for the volume. It can be used to change the risk of trading, or in the case when the lots of instruments differ, for example, when copying trades from spot to futures and vice versa.
PriceFactor
- multiplier for the price. It can be used when the prices of correlated instruments differ, for example, when copying trades from spot to futures and vice versa.
DeleteAfter
-
true
- delete all trades from the exchange file immediately after import. For the case when trades are imported into only one EA. For several EAs set to
false
.
Then, to import trades, you need to call the
ImportOrder()
function. Call example:
As a result, the
aReq
array contains all the latest unprocessed trades with the
Magic
number and the symbol of the current chart. In the last parameter, specify a different symbol if it differs in imported trades.
Next, in the cycle, you need to execute imporded trades on the desired symbol, adjusting the order parameters if necessary:
Attached EA is an example of the implementation of an importing EA that opens the imported trades on the symbol of EA's chart.
You may also like: n Close Orders - excellent alternative for library users on MetaTrader 5.
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.