int lastOrder = -1;
int total = OrdersTotal();
for(int i = total-1; i >= 0; i--)
if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
lastOrder = i;
return(lastOrder >= 0);
int direction = 0;
if(OrderType() == OP_BUY)
direction = 1;
else if(OrderType() == OP_SELL)
direction = -1;
Good Day to all traders. I am developing an ea that will buy or sell if the price will crosses the trend line. I want to refine some conditions that makes the EA buy and sell and buy and so on...and vice versa. Is it possible to have a code that will determine the last open position (buy/sell) so that the position will not be repeated (buy, buy, sell, sell)?
if there is a buy open, then the next well be sell open, and then buy open ans so on... and vice versa.
is it possible to insert the date and time i think something is lack in here
Thank you in advance and God Bless you all.
We could do that but in stead i'm just gonna tell you this: "Pastperformance is no guarantee of future results."
If you really want you can filter
But you can also just use a boolean or integer called
And set it when you open the order then there is no need to select orders for that.
Bare in mind there is practically nothing that has not been programmed for MQ4/5 yet! So search first! Its easier and the result has fff: far fewer faults than a do-it-yourself-EA generally speaking!
For example look here: https://www.mql5.com/en/docs/event_handlers/ontester!
And there are many many others following this idea!
Please do not double post.
I have removed your other topic.