Check before open a new trade with same symbol

 

Hello guys, sameone know how to manage this situation?

Basically in my ea before to open a new order i want check if i have another trade with that symbol open and in that case i want skip i new trade.

 
Mirco: i want check if 

OrderSelect loop and look.

 
William Roeder #:

OrderSelect loop and look.

thanks but maybe i have done wrong a question, situation is little bit complicate. In my ea there are multiple types of operation , every type have a magic number, i want allow to open a new grid on same magic number (with that symbol) but i dont want open a new trade with same symbol. Issue is that magic number is dynamic (because pair is insert on set randomly) so i cannot check for fix magic number to look at it.

 
Mirco #:

thanks but maybe i have done wrong a question, situation is little bit complicate. In my ea there are multiple types of operation , every type have a magic number, i want allow to open a new grid on same magic number (with that symbol) but i dont want open a new trade with same symbol. Issue is that magic number is dynamic (because pair is insert on set randomly) so i cannot check for fix magic number to look at it.

You need to create your magicnos thru a process you can replicate when necessary.....for example have an array of magicnos you use for each type of operation.....
 
Mirco #: . Issue is that magic number is dynamic (because pair is insert on set randomly) so i cannot check for fix magic number to look at it.

You created your own problem. PICNIC. Stop with the dynamic MNs.

Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number/symbol filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
          Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum (2013)
          PositionClose is not working - MQL5 programming forum (2020)
          MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
          Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles (2011)
          Limit one open buy/sell position at a time - General - MQL5 programming forum (2022)

You need one Magic Number for each symbol/timeframe/strategy. Trade current timeframe, one strategy, and filter by symbol requires one MN.

If trading multiple timeframes, and filter by symbol requires use a range of MN (base MN plus timeframe).
          Why are MT5 ENUM_TIMEFRAMES strange? - General - MQL5 programming forum - Page 2 #11 (2020)