Skip to content

Get Open Trades By Magic

GetOpenTradesByMagic

Retrieves all open trades that match a specific magic number.

int GetOpenTradesByMagic(int magic, std::vector<TradeRecord>* trades);

Parameters

  • magic — integer representing the trade magic number used to identify trades opened by a specific strategy or expert advisor.
  • trades — pointer to a std::vector of TradeRecord structures where the retrieved open trades will be stored.

Return Value

  • RET_OK — open trades with the specified magic number found and successfully retrieved.
  • RET_NOT_FOUND — no open trades found with the specified magic number.
  • RET_* — other error codes.
  • Return Codes

Example

std::vector<TradeRecord> magicTrades;
if (GetOpenTradesByMagic(12345, &magicTrades) == RET_OK) {
    // Process trades opened by EA with magic 12345
}

Warning

  • The trades pointer must point to a valid std::vector<TradeRecord> object.
  • If no trades are found, the function returns RET_NOT_FOUND and leaves trades unchanged.
  • Always check the return code before accessing trades.