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::vectorof 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
tradespointer must point to a validstd::vector<TradeRecord>object. - If no trades are found, the function returns
RET_NOT_FOUNDand leavestradesunchanged. - Always check the return code before accessing
trades.