Code Library / Order Management

MQL4 Trade Copier

Local trade copier using global variables.

Language: MQL4 · Category: Order Management · Tags: trade copier, MQL4, master slave, copy trading, local

Source code

// MASTER
void SendSignal(int type,double lots) {
   GlobalVariableSet("SIG",type);
   GlobalVariableSet("LOTS",lots);
   GlobalVariableSet("TIME",TimeCurrent());
}
// SLAVE
datetime lastSig=0;
void CheckSignal() {
   if(!GlobalVariableCheck("TIME")) return;
   datetime t=(datetime)GlobalVariableGet("TIME");
   if(t<=lastSig) return; lastSig=t;
   int sig=(int)GlobalVariableGet("SIG");
   double lots=GlobalVariableGet("LOTS");
   if(sig==0) OrderSend(Symbol(),OP_BUY,lots,Ask,3,0,0,"Copy");
   if(sig==1) OrderSend(Symbol(),OP_SELL,lots,Bid,3,0,0,"Copy");
}

How to use this snippet

This is a building block, not a finished trading system. Paste it into your own MQL4 project, compile it, and test it on a demo account with your broker's real spreads before relying on it. If MetaEditor reports errors, the compilation error fixer can help.

Related snippets