How to share information between two MetaTrader terminals

Is it possible to share data between MT4 terminals on the same VPS?

Is there a location that both terminals could access?

For example, I have Terminal 1 using Broker A, and Terminal 2 using Broker B. Broker B has a market that is not available with Broker A. So I want to send the price data for this market from Terminal 2 to Terminal 1 every time a bar closes to use in an EA. Only solution I can think of is to save the prices in a csv file and have an EA in Terminal 1 read from the csv file. But where can I save this csv file for both terminals to see? Is there a shared location? It must be possible because otherwise how do trade copier EA’s work?

Thanks in advance!

It is only possible if you are using 3rd Party VPS, but not if using MetaQuotes Virtual Hosting Services .

If using 3rd Party VPS, you can do it via Sockets communications or via a data file in the Common Folder or via Sockets.

A brief summary of files in the Common folder versus something like socket communication:
Files in the Common folder
Advantages: * Relatively simple * Uses only native MQL functions; does not require “Allow DLL imports” to be turned on
Disadvantages: * Higher message latency * Higher processor usage. Receiving EA must not only repeatedly poll the file, but also inspect it for changes * Relatively hard to extend from a single repeated status update to a variety of different message types from the clients (e.g. differential notification of a new open trade) * Can’t scale beyond a single computer
Sockets, or similar
Advantages: * Lower message latency * Lower processor usage. Receiving EA can sit idle until a new update arrives, rather than repeatedly polling in OnTimer(). No disk I/O. * Inherently message-based, and easier to expand from a single repeated status update to a variety of different message types from clients to receiver * Can potentially work across multiple computers
Disadvantages: * Relatively complex * Requires “Allow DLL imports” to be turned on

Thanks to the author for the library!

Wrote the functions to transfer any data. Below the script shows their work on the example of ticks

#include <MemMapLib.mqh>
#include <TypeToBytes.mqh>

// Selects the specified length memory for data
template <typename T>
bool GetFileMemory( CMemMapFile* &FileMemory, const int Amount, const string FileName = "Local\\test" )
  FileMemory = new CMemMapFile;
  return(FileMemory.Open(FileName, sizeof(T) * Amount + sizeof(int) + HEAD_MEM, modeCreate) == 0);

// Writes data to memory
template <typename T>
void DataSave( CMemMapFile* FileMemory, const T &Data[], const bool FromBegin = true  )
  const int Size = ArraySize(Data) * sizeof(T);
  uchar Bytes[];
  _ArrayCopy(Bytes, _R(Size).Bytes);              // Copied quantity
  _ArrayCopy(Bytes, _R(Data).Bytes, sizeof(int)); // Copied data

  if (FromBegin)
    FileMemory.Seek(0, SEEK_SET);

  FileMemory.Write(Bytes, ArraySize(Bytes)); // Have dumped all in memory

// Reads data from memory
template <typename T>
int DataLoad( CMemMapFile* FileMemory, T &Data[], const bool FromBegin = true )
  if (FromBegin)
    FileMemory.Seek(0, SEEK_SET);

  uchar Bytes[];
  FileMemory.Read(Bytes, sizeof(int));  // Read from memory the amount of data 
  FileMemory.Read(Bytes, _R(Bytes)[0]); // Received the data itself

  _ArrayCopy(Data, Bytes);              // Reset the data in an array

#define AMOUNT 1000

#define TOSTRING(A) #A + " = " + (string)(A) + " "

// Example of forwarding ticks
void OnStart()
  CMemMapFile* FileMemory;
  if (GetFileMemory<MqlTick>(FileMemory, AMOUNT))
    MqlTick Ticks4Save[];    
    CopyTicks(_Symbol, Ticks4Save, COPY_TICKS_INFO, 0, AMOUNT);
    DataSave(FileMemory, Ticks4Save);
    MqlTick Ticks4Load[];    
    if (DataLoad(FileMemory, Ticks4Load) > 0)    
      Print(TOSTRING((_R(Ticks4Save) == Ticks4Load)) +
            TOSTRING(ArraySize(Ticks4Save)) +
  delete FileMemory;


(_R(Ticks4Save)==Ticks4Load) = true ArraySize(Ticks4Save) = 1000 ArraySize(Ticks4Load) = 1000

The easiest way for terminal to terminal communication is always QuickChannel, as already posted here many times. Just do a Google search for “ quickchannel”. It will not work on MetaQuotes VPS (missing “P” and “S”).

Thanks everyone!

I am using a 3rd Party VPS so all of these methods should work. I will give them a try. I have just been reading about QuickChannel and it does seem fairly straightforward. I’ll look into all of them and report back if I run into any issues.

Much appreciated!