Can't get my orders count filtering by Magic Number, can someone help my code to check, please? (MT4)
-
Don't double post! You already had this thread open.
General rules and best pratices of the Forum. - General - MQL5 programming forum #6 (2017) -
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
Forum rules and recommendations - General - MQL5 programming forum (2023)
Messages Editor If it is a buy order, then it isn't a sell and you continue.
Loop does nothing, ever.for(int i=0; i<OrdersTotal(); i++) { if(OrderSelect(i, SELECT_BY_POS) == false) break; if(OrderSymbol() != Symbol()) continue; if(OrderType() != OP_BUY || OrderType() != OP_SELL) continue;
Don't use negative logic. for(int i=0; i<OrdersTotal(); i++) if( OrderSelect(i, SELECT_BY_POS) &&(OrderType() == OP_BUY || OrderType() == OP_SELL) && OrderSymbol() == Symbol() ){
-
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)
Hello, thank you for your reply.
Maybe I could have done my edit following your reply No.1 & 2.
The last No3, I can't figure it out what you are talking about.
It means, 1 EA can only have 1 Magic Number by each Period?
So what is your suggested code to manage/count number of orders by each Magic Number by each period?
I need 3 Magic Numbers for each period.(Buy, Sell and Hedging settlement )
-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
Forum rules and recommendations - General - MQL5 programming forum (2023)
Messages Editor If it is a buy order, then it isn't a sell and you continue.
Loop does nothing, ever.Don't use negative logic. -
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)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone, I hope someone can help to check my code.
I wrote my own function that counts the number of orders aggregated separately by the magic number.
However, when I ran the Strategy Tester, I found that the function might not work as well.
Here is what I wanted to do in the code. (I will write only part of the code, not all of it. The main function "MyCurrentOrders" is written at the last.)
======================================================