Home › Trading journal › Connect MT5 / MT4

Connect MT5 to your trading journal

Send every closed MetaTrader 5 trade to your free CROZAX journal automatically. About 5 minutes, once. No password, nothing to install except one small file, and the EA can only read your history.

You need: MetaTrader 5 on a Windows or Mac computer · a free CROZAX account · 5 minutes. Phone apps cannot run EAs; MT4 users see MT4 below.
1

Download the CROZAX Sync file

Open your trading journal, press 🔗 MT5 auto-sync and then ⬇ Download CROZAX-Sync.mq5. The file is small (about 7 KB) and is saved in your Downloads folder.

If this doesn’t work: The browser blocks the download, or the file is saved as .txt? Skip the file. Use the Copy code button in the code box below and follow step 3 (the “new Expert Advisor” way).
Step 1: Download the CROZAX Sync file (illustration)
2

Open MetaEditor

In MetaTrader 5 on your computer go to Tools → MetaQuotes Language Editor, or simply press F4. MetaEditor is the free code editor that comes with MT5.

If this doesn’t work: Nothing opens? MT5 may ask to download MetaEditor first: allow it. On a Mac, use the same menu inside MT5 for Mac (Fn+F4 on some keyboards).
Step 2: Open MetaEditor (illustration)
3

Add the EA to MetaEditor

Way A (file): in MT5 choose File → Open Data Folder → MQL5 → Experts and copy the downloaded file there. Then in MetaEditor's Navigator right-click Experts → Refresh and double-click CROZAX-Sync.
Way B (works always): in MetaEditor choose File → New → Expert Advisor (template), name it CROZAX-Sync, press Next until Finish. Select everything in the new file (Ctrl+A, Mac Cmd+A), delete it, and paste the code from the code box.

If this doesn’t work: The .mq5 file does not open, or you cannot find the Experts folder (common on Mac)? Use Way B. It gives exactly the same result.
Step 3: Add the EA to MetaEditor (illustration)
4

Compile it (F7)

Press Compile on the toolbar or F7. At the bottom, the log must say 0 errors. Warnings are fine.

If this doesn’t work: You see errors? Usually only part of the code was pasted. Select all again, delete, paste the whole code from the box (it ends with a closing }) and press F7 again.
Step 4: Compile it (F7) (illustration)
5

Allow CROZAX in MT5 (WebRequest)

In MT5: Tools → Options → Expert Advisors. Tick Allow algorithmic trading and Allow WebRequest for listed URL, double-click the empty line, type https://crozax.com and press OK. This only lets the EA talk to our website.

If this doesn’t work: Later the Experts tab shows Error 4014? The URL is missing or misspelled. Open this window again and check it is exactly https://crozax.com (no space, no slash at the end).
Step 5: Allow CROZAX in MT5 (WebRequest) (illustration)
6

Copy your personal sync key

On crozax.com/journal (logged in) open 🔗 MT5 auto-sync and press Copy next to your key. The key only lets the EA add trades to your journal.

If this doesn’t work: It says “Log in to see your key”? Log in with your free CROZAX account first. Shared the key by mistake? Press New key: the old key stops working at once.
Step 6: Copy your personal sync key (illustration)
7

Put CROZAX Sync on a chart

In MT5 open the Navigator (View → Navigator or Ctrl+N), expand Expert Advisors and drag CROZAX-Sync onto any open chart. Any symbol and timeframe works; it syncs the whole account.

If this doesn’t work: CROZAX-Sync is not in the list? Right-click Expert Advisors → Refresh. Still missing: close and reopen MT5, and check step 4 said 0 errors.
Step 7: Put CROZAX Sync on a chart (illustration)
If the EA is missing: right-click Expert Advisors and Refresh (illustration)
8

Paste the key and allow Algo Trading

A window opens. On the Inputs tab double-click the value next to SyncKey and paste your key (Ctrl+V, Mac Cmd+V). On the Common tab tick Allow Algo Trading. Press OK.

If this doesn’t work: Paste does not work in that box? Right-click the cell → Paste, or type it. Or put the key into the code itself: change the line input string SyncKey = ""; to input string SyncKey = "your-key";, compile again (F7) and attach the EA again.
Step 8: Paste the key and allow Algo Trading (illustration)
9

Turn on Algo Trading

The Algo Trading button on the MT5 toolbar must be green, and the EA name appears at the top-right of the chart. CROZAX Sync never places trades; MT5 just needs this switch to run any EA.

If this doesn’t work: The button is grey or red? Click it once. The EA icon shows a red mark? Recheck Common → Allow Algo Trading (step 8).
Step 9: Turn on Algo Trading (illustration)
10

Check it worked

Open the Toolbox (Ctrl+T) → Experts tab. A line like CROZAX Sync: {"ok":true,"added":12} means your trades reached the journal. Refresh your journal: the trades are there. From now on every closed trade is sent within about 2 minutes.

If this doesn’t work: Error 4014: go back to step 5. server answered 401: the key is wrong or was renewed, paste the current key (step 8). Nothing at all: wait 2–3 minutes, and make sure MT5 is open and connected.
Step 10: Check it worked (illustration)
</>

The CROZAX Sync code

This is the complete EA (the same as the download). Use Copy code for step 3, Way B. Read it if you like: it only reads closed deals and sends them to crozax.com.

Show the code
//+------------------------------------------------------------------+
//| CROZAX Sync — sends your closed MetaTrader 5 trades to your free  |
//| CROZAX trading journal (crozax.com/journal).                      |
//| It only READS your trade history. It never opens, changes or      |
//| closes trades, and your MT5 password never leaves your computer.  |
//|                                                                    |
//| Setup:                                                             |
//| 1. MT5: Tools > Options > Expert Advisors > tick "Allow WebRequest |
//|    for listed URL" and add  https://crozax.com                    |
//| 2. Copy this file to MQL5\Experts (File > Open Data Folder),       |
//|    open it in MetaEditor and press Compile (F7).                   |
//| 3. Drag "CROZAX-Sync" onto any chart and paste your sync key       |
//|    from crozax.com/journal into the SyncKey input.                 |
//+------------------------------------------------------------------+
#property copyright "CROZAX — crozax.com"
#property link      "https://crozax.com/journal"
#property version   "1.10"
#property description "Sends closed trades to your free CROZAX trading journal. Read-only: it never places or changes trades."

input string SyncKey      = "";   // Your sync key from crozax.com/journal
input int    DaysBack     = 30;   // On the first run, send trades closed in the last N days
input int    EveryMinutes = 2;    // How often to check for newly closed trades

string   URL  = "https://crozax.com/api/journal/ea";
string   GV;               // terminal global variable that remembers the last synced close time
datetime lastSent = 0;

int OnInit()
  {
   if(StringLen(SyncKey) < 24)
     {
      Alert("CROZAX Sync: paste your sync key from crozax.com/journal into the SyncKey input.");
      return(INIT_PARAMETERS_INCORRECT);
     }
   GV = "CROZAX_SYNC_" + IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN));
   if(GlobalVariableCheck(GV)) lastSent = (datetime)GlobalVariableGet(GV);
   else lastSent = TimeCurrent() - DaysBack * 86400;
   EventSetTimer(MathMax(1, EveryMinutes) * 60);
   Sync();
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason) { EventKillTimer(); }
void OnTimer() { Sync(); }

string JsonEsc(string s)
  {
   StringReplace(s, "\\", "\\\\");
   StringReplace(s, "\"", "\\\"");
   return(s);
  }

string Num(double v, int digits) { return(DoubleToString(v, digits)); }

//--- one closed position as a JSON object, built from all of its deals
string PositionJson(long pos_id, datetime &closeTime)
  {
   if(!HistorySelectByPosition(pos_id)) return("");
   string sym = "", type = "";
   double vol = 0, openPrice = 0, closePrice = 0, profit = 0, commission = 0, swap = 0, fee = 0, sl = 0, tp = 0, outVol = 0, outValue = 0;
   datetime openTime = 0; closeTime = 0;
   int digits = 5;
   for(int i = 0; i < HistoryDealsTotal(); i++)
     {
      ulong d = HistoryDealGetTicket(i);
      if(d == 0) continue;
      long entry = HistoryDealGetInteger(d, DEAL_ENTRY);
      long dtype = HistoryDealGetInteger(d, DEAL_TYPE);
      if(dtype != DEAL_TYPE_BUY && dtype != DEAL_TYPE_SELL) continue;
      sym = HistoryDealGetString(d, DEAL_SYMBOL);
      digits = (int)SymbolInfoInteger(sym, SYMBOL_DIGITS);
      profit     += HistoryDealGetDouble(d, DEAL_PROFIT);
      commission += HistoryDealGetDouble(d, DEAL_COMMISSION);
      swap       += HistoryDealGetDouble(d, DEAL_SWAP);
      fee        += HistoryDealGetDouble(d, DEAL_FEE);
      if(entry == DEAL_ENTRY_IN)
        {
         if(openTime == 0) { openTime = (datetime)HistoryDealGetInteger(d, DEAL_TIME); openPrice = HistoryDealGetDouble(d, DEAL_PRICE); type = (dtype == DEAL_TYPE_BUY ? "buy" : "sell"); }
         vol += HistoryDealGetDouble(d, DEAL_VOLUME);
        }
      else if(entry == DEAL_ENTRY_OUT || entry == DEAL_ENTRY_OUT_BY || entry == DEAL_ENTRY_INOUT)
        {
         double v = HistoryDealGetDouble(d, DEAL_VOLUME);
         outVol += v; outValue += v * HistoryDealGetDouble(d, DEAL_PRICE);
         datetime t = (datetime)HistoryDealGetInteger(d, DEAL_TIME);
         if(t > closeTime) closeTime = t;
        }
     }
   if(type == "" || closeTime == 0 || outVol < vol - 0.0000001) return("");   // still open (or partly open): send it once fully closed
   closePrice = outValue / outVol;
   for(int k = 0; k < HistoryOrdersTotal(); k++)                              // last stop-loss / take-profit set on the position's orders
     {
      ulong o = HistoryOrderGetTicket(k);
      if(o == 0) continue;
      if(HistoryOrderGetDouble(o, ORDER_SL) > 0) sl = HistoryOrderGetDouble(o, ORDER_SL);
      if(HistoryOrderGetDouble(o, ORDER_TP) > 0) tp = HistoryOrderGetDouble(o, ORDER_TP);
     }
   // v1.10: MAE / MFE — the furthest price moved against / in favour of the position while it was open (M1 bars)
   double mae = 0, mfe = 0, hi[], lo[];
   int nh = CopyHigh(sym, PERIOD_M1, openTime, closeTime, hi), nl = CopyLow(sym, PERIOD_M1, openTime, closeTime, lo);
   if(nh > 0 && nl > 0)
     {
      double H = hi[ArrayMaximum(hi)], L = lo[ArrayMinimum(lo)];
      if(type == "buy") { mae = MathMax(0, openPrice - L); mfe = MathMax(0, H - openPrice); }
      else              { mae = MathMax(0, H - openPrice); mfe = MathMax(0, openPrice - L); }
     }
   return("{\"position\":\"" + IntegerToString(pos_id) + "\",\"symbol\":\"" + JsonEsc(sym) + "\",\"type\":\"" + type + "\",\"volume\":" + Num(vol, 2) +
          ",\"openTime\":\"" + TimeToString(openTime, TIME_DATE | TIME_MINUTES) + "\",\"openPrice\":" + Num(openPrice, digits) +
          ",\"closeTime\":\"" + TimeToString(closeTime, TIME_DATE | TIME_MINUTES) + "\",\"closePrice\":" + Num(closePrice, digits) +
          ",\"sl\":" + Num(sl, digits) + ",\"tp\":" + Num(tp, digits) + ",\"commission\":" + Num(commission, 2) + ",\"fee\":" + Num(fee, 2) +
          ",\"swap\":" + Num(swap, 2) + ",\"profit\":" + Num(profit, 2) + ",\"mae\":" + Num(mae, digits) + ",\"mfe\":" + Num(mfe, digits) + "}");
  }

void Sync()
  {
   if(!HistorySelect(lastSent - 3600, TimeCurrent() + 86400)) return;
   long ids[]; int n = 0;
   for(int i = 0; i < HistoryDealsTotal(); i++)                               // positions that had a closing deal since the last sync
     {
      ulong d = HistoryDealGetTicket(i);
      if(d == 0) continue;
      long entry = HistoryDealGetInteger(d, DEAL_ENTRY);
      if(entry != DEAL_ENTRY_OUT && entry != DEAL_ENTRY_OUT_BY && entry != DEAL_ENTRY_INOUT) continue;
      long pid = HistoryDealGetInteger(d, DEAL_POSITION_ID);
      bool seen = false;
      for(int j = 0; j < n; j++) if(ids[j] == pid) { seen = true; break; }
      if(!seen) { ArrayResize(ids, n + 1); ids[n++] = pid; }
     }
   if(n == 0) return;
   string items = ""; int count = 0; datetime newest = lastSent;
   for(int j = 0; j < n; j++)
     {
      datetime ct = 0;
      string js = PositionJson(ids[j], ct);
      if(js == "") continue;
      items += (count > 0 ? "," : "") + js; count++;
      if(ct > newest) newest = ct;
      if(count == 100) { if(!Send(items)) return; items = ""; count = 0; }
     }
   if(count > 0 && !Send(items)) return;
   lastSent = newest;
   GlobalVariableSet(GV, (double)lastSent);
  }

bool Send(string items)
  {
   string body = "{\"account\":\"" + IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN)) + "\",\"trades\":[" + items + "]}";
   char data[], result[]; string headers;
   StringToCharArray(body, data, 0, WHOLE_ARRAY, CP_UTF8);
   ArrayResize(data, ArraySize(data) - 1);                                     // drop the trailing zero
   ResetLastError();
   int code = WebRequest("POST", URL + "?key=" + SyncKey, "Content-Type: application/json\r\n", 15000, data, result, headers);
   if(code == -1)
     {
      Print("CROZAX Sync: add https://crozax.com in Tools > Options > Expert Advisors > Allow WebRequest. Error ", GetLastError());
      return(false);
     }
   if(code != 200) { Print("CROZAX Sync: server answered ", code, " ", CharArrayToString(result)); return(false); }
   Print("CROZAX Sync: ", CharArrayToString(result));
   return(true);
  }
//+------------------------------------------------------------------+

⬇ Download CROZAX-Sync.mq5

MT4

MetaTrader 4 and mobile users

MT4 cannot run this EA. Instead, save your history as a statement and import it: in MT4 open Terminal → Account History, right-click → All History, right-click again → Save as Detailed Report. On your journal press ⬆ Import and choose the saved .htm file. Repeat whenever you want to update; trades already imported are skipped. The same Import also reads MT5 reports, cTrader, Binance futures and TradingView strategy CSV exports.

On a phone? The MT4/MT5 mobile apps cannot run EAs or save statements. Sync from a computer or a VPS, then use the journal on your phone: it is the same account.
MT4: save a detailed statement from Account History (illustration)

Questions

Do I have to give my MT5 password?

No. The EA runs inside your own MetaTrader and sends only closed-trade details with your private sync key. Your password never leaves your computer.

Can CROZAX place or close trades on my account?

No. CROZAX Sync only reads your closed trade history. It has no code that opens, changes or closes orders.

Does it work on the MT5 mobile app?

No. Phone and tablet MetaTrader apps cannot run Expert Advisors. Use MT5 on a Windows or Mac computer (or a VPS). On mobile you can still import a statement file.

Must MT5 stay open?

Yes, the EA works while MT5 is running. Trades you close while it is off are sent the next time MT5 starts (up to 30 days back by default).

I use MetaTrader 4. What can I do?

MT4 cannot run the MT5 EA. Save a detailed statement (Account History → right-click → All History → Save as Detailed Report) and import it on the journal page with Import.

Disclaimer: CROZAX Sync only displays your own trade history on our website in a well-structured way. We never receive your MetaTrader password and we have no access to your trading account: we cannot see your balance live, and we cannot place, change or close any trade. Your broker account has nothing to do with CROZAX. The journal and its statistics are for your own record and learning; nothing on CROZAX is financial advice. The pictures on this page are illustrations made by CROZAX, not screenshots of a real account.

Page last updated 20 November 2026 · Report an error · How we calculate