Share Data between 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!
 
James Parker:
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.

Forum on trading, automated trading systems and testing trading strategies

GlobalVariables, MT4 and VPN

JC, 2017.09.29 10:11

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

Forum on trading, automated trading systems and testing trading strategies

GlobalVariables, MT4 and VPN

Fernando Carreiro, 2017.09.28 20:59

Following a similar (but different) reasoning as presented by @Jack Thomas,  here is a recent Blog post by @JC for a Socket library (with source code) which can be used for communications between EAs.

Forum on trading, automated trading systems and testing trading strategies

GlobalVariables, MT4 and VPN

Fernando Carreiro, 2017.09.28 23:14

True! I forgot about that one!

EDIT: Does it also work in Portable mode?

EDIT2: Just tested it and yes, it does work in Portable Mode and both MT4 and MT5 share the same common folder, so it is a possible cross-platform solution.

 

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Библиотеки: File Mapping без DLL

fxsaber, 2017.04.03 16:07

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
  
  return;
}

// 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
  
  return(ArraySize(Data));
}

#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)) +
            TOSTRING(ArraySize(Ticks4Load)));
     
    FileMemory.Close();   
  }
  
  delete FileMemory;
}


Result

(_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 "site:mql5.com 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!

 

Link.

 
Fernando Carreiro #:

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.



Is creating symlinks/hardlinks possible for MT5?

I am trying to access the same historical data with two different terminals for backtestings my strategy. it works fine with MT4.

I created symlink for the 'Bases' folder to share and use the same historical data with the second terminal, but I can't access the data at the same time. terminal returns "History  'XAUUSD_MB' file opening or reading error [32]". 

I tried to change  .hcc files permission to Read-only and this time got error "History  'XAUUSD_MB' file opening or reading error [5]". 


how can I share historical data for a different MT5 terminal?

 
wekall #:



Is creating symlinks/hardlinks possible for MT5?

I am trying to access the same historical data with two different terminals for backtestings my strategy. it works fine with MT4.

I created symlink for the 'Bases' folder to share and use the same historical data with the second terminal, but I can't access the data at the same time. terminal returns "History  'XAUUSD_MB' file opening or reading error [32]". 

I tried to change  .hcc files permission to Read-only and this time got error "History  'XAUUSD_MB' file opening or reading error [5]". 


how can I share historical data for a different MT5 terminal?

Why do you need to do that?

Your backtesting and optimizations computational resources are limited to your hardware. What is the sense of running backtests of the same EA from multiple platforms into the same time?

 
Fabio Cavalloni #:

Why do you need to do that?

Your backtesting and optimizations computational resources are limited to your hardware. What is the sense of running backtests of the same EA from multiple platforms into the same time?


Thank you for the quick response.

sorry I forgot to mention it. the purpose is to backtest two different EA, using two different terminals with the same historical data

 
wekall #:


Thank you for the quick response.

sorry I forgot to mention it. the purpose is to backtest two different EA, using two different terminals with the same historical data

Makes sense, is that a custom symbol with ticks history that take a lot of hard drive space?

Why not simply download the XAUUSD_MB history on the other terminal?
 
Fabio Cavalloni #:
Makes sense, is that a custom symbol with ticks history that take a lot of hard drive space?

Why not simply download the XAUUSD_MB history on the other terminal?


Exactly, I have few custom symbols, which occupies large amount of my drive in case I import data to the both terminals.