Hi Guys,
I'm working on my new EA which has an ability to open a pending order in the opposite direction of the last closed order. I've been searching and testing for days now but there's a weird malfunction (sometimes EA is opening a lot pending orders at once, and most of the time not opening any pending orders aymore) and I can't solve it.
Is there anyone who could help me out here?
Thanks in advance!
Why are you checking open orders?
if(OrderOpenTime()> lastOrderTime) { lastOrderTime = OrderOpenTime(); lastOrderType = OrderType(); lastOrderPrice = OrderOpenPrice(); SignalOK = true; break; }
Why the break after the first run through the loop?
else continue;
None of these are necessary
if (lastOrderType == OP_BUY && SignalOK == true) { NewSellTicket = OrderSend(_Symbol,OP_SELLSTOP,LotSize,lastOrderPrice,MaxSlippage,0,Bid-100,"New Sell Ticket 01",MagicNumber,0,clrRed); SignalOK = false; Sleep(1000); }
You are not checking if the stop order has already been opened
Hi Keith,
Thanks for your reply.
The break I added in my search to find a solution, originally it wasn't there... But I thought it was the cause of the 'echo' (a lot of orders at the same moment).
Same for the Sleep command, just trying to find the cause of the problem...
I'm trying to open a STOP order in the opposite direction of the last closed order but with the opening value of the last closed order. So if the last BUY opened at 1.05 and closed at 1.15 I want to set a SELL_STOP at 1.05 at the moment the buy closes...
Is this possible is an simple way?
Hi Keith,
Thanks for your reply.
The break I added in my search to find a solution, originally it wasn't there... But I thought it was the cause of the 'echo' (a lot of orders at the same moment).
Same for the Sleep command, just trying to find the cause of the problem...
I'm trying to open a STOP order in the opposite direction of the last closed order but with the opening value of the last closed order. So if the last BUY opened at 1.05 and closed at 1.15 I want to set a SELL_STOP at 1.05 at the moment the buy closes...
Is this possible is an simple way?
Do it in steps.
First thing to do is to find the last closed order, you won't find it by looping through open trades.
Once you have coded that, print out the trade details so that you know that your code works.
Then and only then move on to the next section of code.
I want to get such expert for pending order and place order on last hit order.Can anybody help me?
hi,
I want to get such expert for pending order and place order on last hit order.Can anybody help me?
Working on it... :-)
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi Guys,
I'm working on my new EA which has an ability to open a pending order in the opposite direction of the last closed order. I've been searching and testing for days now but there's a weird malfunction (sometimes EA is opening a lot pending orders at once, and most of the time not opening any pending orders aymore) and I can't solve it.
Is there anyone who could help me out here?
Thanks in advance!