Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

GRat Order Exchange - MetaTrader 5 Library - MT4/MT5 Resources

author EAcpu | 5 reads | 0 comments |

The attached .mqh file is designed to export orders and trades from one EA and import them into another EA (copy trades), this file can be run in the same terminal and in another terminal on the same computer. It is also possible to exchange trades between different symbols, for example, to copy trades of a certain instrument  point market the corresponding futures or any other instrument related thereto.

You need to include GRat_OrderExport.mqh Save the file to your exported EA using the following command:

 #include

This must be done in the input parameters area exactly where the export parameters should be:

Then, in the EA code, wherever the order is executed OrderSend() function (or method) trade network class), you need to add a call exportorder() function, for example:

 Mql trade request request={}; // Market sell request. Action= TRADE_ACTION_DEAL ;
request.symbol = symbol() ;
Request volume = 0. 2 ;
Request Type = Order Type_Sell ;
RequestPrice = SymbolInfoDouble ( symbol( ), SYMBOL_BID );
request.magic = 2 0000 ;
OrderExport(request);

    this Mql transaction request The structure can be used with OrderSend() function, but you should fill in the additional Mql transaction request operation fields

    TRADE_ACTION_DEAL (for closing positions), TRADE_ACTION_SLTP , TRADE_ACTION_REMOVE and TRADE_ACTION_MODIFY :

    An example implementation of exporting an EA is GRat_OrderExport .

    you need to include GRat_OrderImport.mqh document Use the following command to your imported EA:

     #include

    You need to do this in the input parameters area exactly where the imported parameters are:

    Then, to import transactions you need to call importorder() Function. Call example:

     Mql transaction request request[];
    OrderImport(aReq, Magic, Symbol ());

      result, Require Array containing all latest unprocessed transactions magic Numbers and symbols for the current chart. In the last parameter, specify a different symbol if it is different in the imported transaction.

      Next, during the cycle, you need to execute an import trade on the desired symbol and adjust the order parameters if necessary:

       for ( integer i = 0 ; i < array_size (aRequest); i++)
      {
              aReq[i].symbol = _symbol ;
              aReq[i].price = normalized double (aReq[i].price, _number );
              aReq[i].stoplimit = normalized double (aReq[i].stoplimit, _number );
              aReq[i].sl = normalized double (aReq[i].sl, _number );
              aReq[i].tp = normalized double (aReq[i].tp, _number );
      if (aReq[i].action == TRADE_ACTION_DEAL )
              {
                      ...
              }
              ...
      }

      Attached EA is an example of the implementation of an importing EA that opens the imported trades on the symbol of EA's chart.


      Attachment download

      📎 grat_orderexport.mqh (4.27 KB)

      📎 grat_orderimport.mqh (4.34 KB)

      📎grat_orderimport.mq5 (6.09 KB)

      📎grat_orderexport.mqh

      Source: MQL5 #41580

      Verification code Refresh