Download MetaTrader 5

Open Buy (instead of sell) - or - Open Sell (instead of buy)

To add comments, please log in or register
SDMInvest
11
SDMInvest  

From the 1045 version has made its appearance a serious mistake: When sending in sequence two orders of opposite direction, the second order, sometimes runs in the wrong direction plus without entering the comment and magic number. I find myself in substance to have two buy or two sell instead of one for type, one of which being with MagicNumber 0 is not be managed by my EA which controls only its orders.

I find the following message on the log that is truly terrifying: 2 15: 44: 00,305 sdDynamicGrid v10b EURUSD, M5: open # 50135621 buy (instead of sell) 1.10 EURUSD at 1.07529 ok


In backtest everything works fine. only real occurs, occasionally, this terrible mistake.



whroeder1
17116
whroeder1  
There are no mind readers here. We can't see your broken code.
SDMInvest
11
SDMInvest  
whroeder1:
There are no mind readers here. We can't see your broken code.


Ok, here the code:


int iOOT=OpenedOrders(MagicNumber)+OpenedOrders(MagicNumber+1);

if(iOOT==0)
{
   //Openings
   Print("Send new V2A and V2B...");
   int iFool = OrderSend(Symbol(),OP_BUY, Lots,Ask,3,0,0,EA_NAME + "A LONG" ,MagicNumber  ,0,clrGreen);
   RefreshRates();
   
   if(OpenedOrders(MagicNumber)+OpenedOrders(MagicNumber+1)==1)
   {
        if(IsTradeContextBusy()==false)
        {
                iFool = OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,EA_NAME + "B SHORT",MagicNumber+1,0,clrRed);
        }
   }
   if(OpenedOrders(MagicNumber)+OpenedOrders(MagicNumber+1)==1)
   {
      Print("ERROR !!!! Safety closure.");
      CloseAllOrders(MagicNumber);
      CloseAllOrders(MagicNumber+1);
      return;
   }
}


OpenedOrders function returns the numbers of opened orders for specific magic number and CloseAllOrders function close all the order with specific magic number.

whroeder1
17116
whroeder1  
  1. Where are your Print statements indicating which call you executed.
  2. Where do you check your return codes? What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. You do understand that your code to close all orders will never be called (except if the sell fails?)
  4. Your log message is meaning less as you don't print the MN or comment
To add comments, please log in or register