I'm testing what I have done so far and for now it works as I want. I trade only one pair so there is no need to look for symbol. I think all I need is to look at last trade and that is all. If I have 6 pending orders and two trades EA will do nothing because I will set it to work only if number of trades is < 8. When one trade will close it will open another pending order where last closed order was. Will test and see.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I forgot to add () and edit this mistake.
My I get some help how to loop through all closed orders and compare OrderCloseTime?
Is this correct code?
May I put more info of this last order in same function, or I have to create new function for each info I want (TP, SL, OrderType,...)
Just look in the reference for OrdersTotal(), OrdersHistoryTotal() and OrderCloseTime().
datetime-type can be treated link ulong numbers: >, >= ==, !=, ...
int last_ticket = LastClosedTicket();
if (last_ticket > 0){
if (OrderSelect(last_ticket,SELECT_BY_TICKET,MODE_HISTORY))
return(OrderTakeProfit());
}
return(0.0);
}
:
double LastClosedLots(){
int last_ticket = LastClosedTicket();
if (last_ticket > 0){
if (OrderSelect(last_ticket,SELECT_BY_TICKET,MODE_HISTORY))
return(OrderLots());
}
return(0.0);
}
int last_ticket = LastClosedTicket();
return OrderSelect(last_ticket,SELECT_BY_TICKET);
}
double LastClosedTP(){
return SelectLastClosed() ? OrderTakeProfit() : 0.0;
}
:
double LastClosedLots(){
return SelectLastClosed() ? OrderLots() : 0.0;
}
int LastClosedTicket(){
datetime last_closed = 0;
int last_ticket = -1;
for (int i=0; i<OrdersHistoryTotal(); i++) {
if (!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
if (OrderType()<=1) {
if (OrderCloseTime() > last_closed) {
last_closed = OrderCloseTime();
last_ticket = OrderTicket();
}
}
}
return(last_ticket);
}
int LastClosedTicket(){
datetime last_closed = 0;
int last_ticket = -1;
string marketPair = Symbol();
for (int i=OrdersHistoryTotal() - 1; i>=0; --i) if(
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)
&& OrderMagicNumber() == MagicNumber
&& OrderCloseTime() > last_closed
&& OrderIsOpen()
&& OrderSymbol() == marketPair
) {
last_closed = OrderCloseTime();
last_ticket = OrderTicket();
}
return(last_ticket);
}
bool OrderIsPending(void){ return OrderType() >= OP_BUYLIMIT; }
bool OrderIsOpen(void){ return !OrderIsPending(); }
Thanks for the help!
I'm testing what I have done so far and for now it works as I want. I trade only one pair so there is no need to look for symbol.
I think all I need is to look at last trade and that is all. If I have 6 pending orders and two trades EA will do nothing because I will set it to work only if number of trades is < 8. When one trade will close it will open another pending order where last closed order was. Will test and see.
Thanks again!