I tested order select for false condition of a closed ticket which returns true and not false.
How to know if a ticket was closed, by not being an open order to select?
Always check the documentation
The pool parameter is ignored if the order is selected by the ticket number. The ticket number is a unique order identifier.
I tested order select for false condition of a closed ticket which returns true and not false.
How to know if a ticket was closed, by not being an open order to select?
If you select by ticket it returns "true" if the ticket exists, regardless of whether the position is closed, open, pending, etc. True = exists, false = doesn't exist. Selecting by position has a mode which lets you filter if you wanna look at the pool of trades (open + pending) or the history pool (closed). That mode parameter is ignored when selecting by ticket.
I understand, tho, that if you have the ticket number it's more convenient, faster and clean to check the ticket directly. In that case, if you wanna check if the order is closed or not just add...
if(SelectOrder(myTicket, SELECT_BY_TICKET, MODE_TRADES) && !OrderCloseTime()) // This is true if the order exists and is OPEN
...or, of course, the opposite...
if(SelectOrder(myTicket, SELECT_BY_TICKET, MODE_TRADES) && OrderCloseTime()) // This is true if the order exists and is CLOSED
Hope that helps.
-
The question has been answered: bool isClosed=OCT!=0;
-
EAs must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover?
Use a OrderSelect / Position select loop on the first tick, or persistent storage (GV+flush or files) of ticket numbers required.
Please note that OrderCloseTime() returns a datetime, not a bool.
Although
may do what you want, the correct way is
Damn, I knew someone was gonna reply with that LOL. Yeah, I know it returns a DATETIME but any numeric value equals to zero is considered FALSE logically, and any numeric value different from zero is considered logically TRUE. Therefore the code does what I want because zero is FALSE and any other date is considered TRUE.
See the second example of my post here: https://www.mql5.com/en/forum/410367/page36#comment_42323466. Cheers.
EDIT: Since it's an interesting topic that a lot of people don't know about, I'll leave some more reading:
Boolean Operations
Logical Negation NOT (!)
Operand of the logical negation (!) must be of arithmetic type. The result is TRUE (1), if the operand value is FALSE (0); and it is equal to FALSE (0), if the operand differs from FALSE (0).
- 2022.09.27
- www.mql5.com
OrderCloseTime()==0 for closed trades
OrderCloseTime()!=0 for open trades
-
Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. We don't know what you want to read.
-
You have those backwards. You have to check if you select by ticket.
-
If you select by position, you only have open and pending orders.
-
If you select by position in MODE_HISTORY, you will never have open orders.
MT4:
-
Do not assume history has only closed orders.
OrderType() == 6, 7 in the history pool? - MQL4 programming forum (2017) -
Do not assume history is ordered by date, it's not.
Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum (2012)
Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 (2020) -
Total Profit is OrderProfit() + OrderSwap() + OrderCommission(). Some brokers don't use the Commission/Swap fields. Instead, they add balance entries. (Maybe related to Government required accounting/tax laws.)
"balance" orders in account history - Day Trading Techniques - MQL4 programming forum (2017)Broker History FXCM Commission - <TICKET>
Rollover - <TICKET>>R/O - 1,000 EUR/USD @0.52 #<ticket> N/A OANDA Balance update
Financing (Swap: One entry for all open orders.)
-
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I tested order select for false condition of a closed ticket which returns true and not false.
How to know if a ticket was closed, by not being an open order to select?