Alert show up

To add comments, please log in or register
18081961
687
18081961  

Hi all,

 While the order is placed and works fine every time a new order is open the alert shown up. This should only happen if the order fail and that is not the case.

Follow is the code. Could any of you tell me if the way and place of the error lines are wrong ?

 

void OpenOppositeOrder()
    {//0     
     int Op; 
  
     for(int Counter = OrdersTotal()-1; Counter >= 0; Counter--)
      {//1
      if(!OrderSelect(Counter,SELECT_BY_POS,MODE_TRADES))continue;          
         {//2
         if(OrderSymbol() == Symbol()&& OrderMagicNumber() == MagicNumber)           
            {//3
             Op = OrderType();            
             if (Op == OP_BUY && (OrderOpenPrice() - OrderClosePrice())/Point >= OppositeDistance && SellAllowed)
               {//4  
                 RefreshRates();                             
                 SellTicket = OrderSend(Symbol(), OP_SELL, MLots, Bid, Slippage*pips2points, 0, 0, "Sell Opposite Order", MagicNumber, 0, Red);
                 if(SellTicket > -1)                   
                  {//5
                    AddLimitsSell();
                    BuyAllowed=true;SellAllowed=false;                                                                                
                    Print(" Opposite Sell order placed: ",SellTicket," StopLoss: ",DoubleToStr(OrderStopLoss(),Digits)," Open Price: ",DoubleToStr(OrderOpenPrice(),Digits));
                  return;
                  }//5                 
               else
                  {//6                  
                    ErrorCode = GetLastError();
                    string ErrDesc =ErrorDescription(ErrorCode);
                   
                    string ErrAlert = StringConcatenate(" Opposite Sell Failed: ",ErrorCode, ": ",ErrDesc);
                    Alert(ErrAlert);
         
                    string ErrLog = StringConcatenate(" Bid: ",DoubleToStr(Bid,Digits)," Open Price: ",DoubleToStr(OrderOpenPrice(),Digits)," Ticket: ",SellTicket," Spread: ",
                                    DoubleToStr(Spread,Digits)," Lots: ",MLots," Stop Level: ",StopLevel," Freeze Level: " ,FreezeLevel);
                    Print(ErrLog);                    
                  }//6
                }//4                      
             if(Op == OP_SELL && (OrderClosePrice() - OrderOpenPrice())/Point >= OppositeDistance && BuyAllowed)  
                {//7  
                       RefreshRates();                          
                  BuyTicket = OrderSend(Symbol(), OP_BUY, MLots, Ask, Slippage*pips2points, 0, 0, "Buy Opposite Order", MagicNumber, 0, Green); 
                  if(BuyTicket > -1)
                   {//8
                     AddLimitsBuy();
                     BuyAllowed=false;SellAllowed=true;                                                                            
                     Print(" Opposite Buy order placed: ",BuyTicket," StopLoss: ",DoubleToStr(OrderStopLoss(),Digits)," Open Price: ",DoubleToStr(OrderOpenPrice(),Digits));
                return;
                  }//8
               else
                  {//9                     
                    ErrorCode = GetLastError();
                    ErrDesc =ErrorDescription(ErrorCode);
                  
                    ErrAlert = StringConcatenate(" Opposite Buy Failed: ",ErrorCode, ": ",ErrDesc);
                    Alert(ErrAlert);
         
                    ErrLog = StringConcatenate(" Ask: ",DoubleToStr(Ask,Digits)," Open Price: ",DoubleToStr(OrderOpenPrice(),Digits)," Ticket: " ,BuyTicket," Spread: ",
                                                  DoubleToStr(Spread,Digits)," Lots: ",MLots," Stop Level: " ,StopLevel," Freeze Level: ",FreezeLevel);
                    Print(ErrLog);
                  }//9   
               }//7
            }//3
         }//2   
      }//1          
   }//0  

Thank you in advance 

Luis 

Simon Gniadkowski
17644
Simon Gniadkowski  
luisneves:

Hi all,

 While the order is placed and works fine every time a new order is open the alert shown up. This should only happen if the order fail and that is not the case.

Follow is the code. Could any of you tell me if the way and place of the error lines are wrong ?

So in the log you get the following . . .

 Opposite Sell order placed: ",SellTicket," StopLoss: ",

followed immediately by . . . 

 Bid: ",DoubleToStr(Bid,Digits)," Open Price: ",Double

 

Please post the log entry that shows this  . . . .  I don't believe it can happen,  if the OrderSend returns > -1 you execute a block of code that finishes with a return;  so the Alert cannot be called.

You should add the function name to your Alerts and log entries so you know where they are coming from . . . so this:

string ErrLog = StringConcatenate(" Bid: ",DoubleToStr(Bid,Digits)," Open Price: ",DoubleToStr(OrderOpenPrice(),Digits)," Ticket: ",SellTicket," Spread: ",
                                    DoubleToStr(Spread,Digits)," Lots: ",MLots," Stop Level: ",StopLevel," Freeze Level: " ,FreezeLevel);

 changes to this:

string ErrLog = StringConcatenate("OpenOppositeOrder - Bid: ",DoubleToStr(Bid,Digits)," Open Price: ",DoubleToStr(OrderOpenPrice(),Digits)," Ticket: ",SellTicket," Spread: ",
                                    DoubleToStr(Spread,Digits)," Lots: ",MLots," Stop Level: ",StopLevel," Freeze Level: " ,FreezeLevel);

 And this:

ErrAlert = StringConcatenate(" Opposite Buy Failed: ",ErrorCode, ": ",ErrDesc);

 changes to this:

ErrAlert = StringConcatenate("OpenOppositeOrder - Opposite Buy Failed: ",ErrorCode, ": ",ErrDesc);
18081961
687
18081961  
RaptorUK:

So in the log you get the following . . .

 Opposite Sell order placed: ",SellTicket," StopLoss: ",

followed immediately by . . . 

 Bid: ",DoubleToStr(Bid,Digits)," Open Price: ",Double

 

Please post the log entry that shows this  . . . .  I don't believe it can happen,  if the OrderSend returns > -1 you execute a block of code that finishes with a return;  so the Alert cannot be called.

You should add the function name to your Alerts and log entries so you know where they are coming from . . . so this:

 changes to this:

 And this:

 changes to this:



Hi RaptorUK,

Thank you for your attention to my issue.

So here is the log registered as soon the ea start to run;

 I call for your attention to the fact that sometimes Lots is 0 while it should be 0.01. Could this be the problem ?

Nevertheless  the order opens and the lot is 0.01 (......)

2013.04.02 14:42:11     market_order_ecn_80_800_v7_v3 EURUSDi,M1:  Initial Buy order placed BuyTicket: 6618550
2013.04.02 14:42:11     market_order_ecn_80_800_v7_v3 EURUSDi,M1: Add Limits Buy Failed - Ask: 1.28141 Ticket: 6618550 Spread: 1.00000 Lots: 0 Buy Stop Loss: 1.27862 Stop Level: 0 Freeze Level: 0
2013.04.02 14:42:11     market_order_ecn_80_800_v7_v3 EURUSDi,M1: Alert:  Add Limits Buy Failed - Error: 0: no error
2013.04.02 14:42:11     stdlib EURUSDi,M1: loaded successfully

 Thank you in advance

Luis 

Simon Gniadkowski
17644
Simon Gniadkowski  
luisneves:


Hi RaptorUK,

Thank you for your attention to my issue.

So here is the log registered as soon the ea start to run;

 I call for your attention to the fact that sometimes Lots is 0 while it should be 0.01. Could this be the problem ?

Nevertheless  the order opens and the lot is 0.01 (......)

Is the alert  . . .

2013.04.02 14:42:11     market_order_ecn_80_800_v7_v3 EURUSDi,M1: Alert:  Add Limits Buy Failed - Error: 0: no error

coming from this function  AddLimitsBuy();  ?   rather than the code you showed above ?

18081961
687
18081961  
RaptorUK:

Is the alert  . . .

coming from this function  AddLimitsBuy();  ?   rather than the code you showed above ?



Hi RaptorUK,

Yes, the Alert comes from the code that is showed above. Again when the first order opens the Lot showed in the log is 0 instead of 0.01, but in Trade tab the order opens and the lot is 0.01. From there when an opposite orders opens the Lot is ok but the alert show up anyway. 

At this moment I have and per your advise I have identified all error  and alert lines spread in the whole code.

2013.04.02 15:09:32     market_order_ecn_80_800_v7_v3 EURUSDi,M1:  Opposite Buy order placed: 6619254 StopLoss: 0.00000 Open Price: 1.28229
2013.04.02 15:09:32     market_order_ecn_80_800_v7_v3 EURUSDi,M1: Add Limits Buy Failed - Ask: 1.28229 Ticket: 6619254 Spread: 2.00000 Lots: 0.04 Buy Stop Loss: 1.27703 Stop Level: 0 Freeze Level: 0  <-----------Lot 0.04 ok
2013.04.02 15:09:32     market_order_ecn_80_800_v7_v3 EURUSDi,M1: Alert:  Add Limits Buy Failed - Error: 0: no error
2013.04.02 15:09:32     market_order_ecn_80_800_v7_v3 EURUSDi,M1: modify #6619254 buy 0.04 EURUSDi at 1.28229 sl: 1.27703 tp: 1.28703 ok
2013.04.02 15:09:31     market_order_ecn_80_800_v7_v3 EURUSDi,M1: open #6619254 buy 0.04 EURUSDi at 1.28229 ok
2013.04.02 15:03:07     market_order_ecn_80_800_v7_v3 EURUSDi,M1:  Opposite Sell order placed: 6619137 StopLoss: 0.00000 Open Price: 1.28203  <------------------------Could this be the problem ?
2013.04.02 15:03:07     market_order_ecn_80_800_v7_v3 EURUSDi,M1: Add Limits Sell Failed - Bid: 1.28203 Ticket: 6619137 Spread: 2.00000 Lots: 0.02 Sell Stop Loss: 1.28680 Stop Level: 0 Freeze Level:  0 <-----------Lot 0.02 ok
2013.04.02 15:03:07     market_order_ecn_80_800_v7_v3 EURUSDi,M1: Alert:  Add Limits Sell Failed - Error: 0: no error
2013.04.02 15:03:07     market_order_ecn_80_800_v7_v3 EURUSDi,M1: modify #6619137 sell 0.02 EURUSDi at 1.28203 sl: 1.28680 tp: 1.27680 ok
2013.04.02 15:03:07     market_order_ecn_80_800_v7_v3 EURUSDi,M1: open #6619137 sell 0.02 EURUSDi at 1.28203 ok
2013.04.02 15:00:39     market_order_ecn_80_800_v7_v3 EURUSDi,M1:  Initial Buy Order Placed - BuyTicket: 6619088
2013.04.02 15:00:39     market_order_ecn_80_800_v7_v3 EURUSDi,M1: Add Limits Buy Failed - Ask: 1.28225 Ticket: 6619088 Spread: 2.00000 Lots: 0 Buy Stop Loss: 1.27680 Stop Level: 0 Freeze Level: 0  <-----------Lot 0 should show 0.01
2013.04.02 15:00:39     market_order_ecn_80_800_v7_v3 EURUSDi,M1: Alert:  Add Limits Buy Failed - Error: 0: no error
2013.04.02 15:00:39     stdlib EURUSDi,M1: loaded successfully

 

Thank you in advance

Luis 

Simon Gniadkowski
17644
Simon Gniadkowski  
luisneves:


Hi RaptorUK,

Yes, the Alert comes from the code that is showed above. Again when the first order opens the Lot showed in the log is 0 instead of 0.01, but in Trade tab the order opens and the lot is 0.01. From there when an opposite orders opens the Lot is ok but the alert show up anyway. 

No it doesn't . . .  unless you have changed the code.

From the code above . . .

ErrAlert = StringConcatenate(" Opposite Buy Failed: ",ErrorCode, ": ",ErrDesc);
                    Alert(ErrAlert);

 So the text in the Alert will start . . . .   Opposite Buy Failed: 

 The Alert you have shown in the log starts . . .   Add Limits Buy Failed

The code producing this Alert is not the code you have shown above . . . 

Simon Gniadkowski
17644
Simon Gniadkowski  
Please show the code for this function :  AddLimitsBuy();
18081961
687
18081961  
RaptorUK:

No it doesn't . . .  unless you have changed the code.

From the code above . . .

 So the text in the Alert will start . . . .   Opposite Buy Failed: 

 The Alert you have shown in the log starts . . .   Add Limits Buy Failed

The code producing this Alert is not the code you have shown above . . . 

 


Hi RaptorUK,

I updated the code, here it is;

 

void OpenOppositeOrder()
    {//0     
     int Op; 
  
     for(int Counter = OrdersTotal()-1; Counter >= 0; Counter--)
      {//1
      if(!OrderSelect(Counter,SELECT_BY_POS,MODE_TRADES))continue;          
         {//2
         if(OrderSymbol() == Symbol()&& OrderMagicNumber() == MagicNumber)           
            {//3
             Op = OrderType();            
             if (Op == OP_BUY && (OrderOpenPrice() - OrderClosePrice())/Point >= OppositeDistance && SellAllowed)                 
               {//4  
                 RefreshRates();                             
                 SellTicket = OrderSend(Symbol(), OP_SELL, MLots, Bid, Slippage*pips2points, 0, 0, "Sell Opposite Order", MagicNumber, 0, Red);
                 if(SellTicket > -1)                   
                  {//5
                    AddLimitsSell();
                    BuyAllowed=true;SellAllowed=false;                                                                                
                    Print(" Opposite Sell Order Placed: ",SellTicket," StopLoss: ",DoubleToStr(OrderStopLoss(),Digits)," Open Price: ",DoubleToStr(OrderOpenPrice(),Digits));                 
                  return;
                  }//5                 
               else
                  {//6                  
                    ErrorCode = GetLastError();
                    string ErrDesc =ErrorDescription(ErrorCode);
                   
                    string ErrAlert = StringConcatenate(" Open Opposite Order - Opposite Sell Failed: ",ErrorCode, ": ",ErrDesc);
                    Alert(ErrAlert);
         
                    string ErrLog = StringConcatenate(" Open Opposite Order - Bid: ",DoubleToStr(Bid,Digits)," Open Price: ",DoubleToStr(OrderOpenPrice(),Digits)," Ticket: ",SellTicket," Spread: ",DoubleToStr(Spread,Digits)," Lots: ",MLots," Stop Level: ",StopLevel," Freeze Level: " ,FreezeLevel);
                    Print(ErrLog);                    
                  }//6
                }//4                      
             if(Op == OP_SELL && (OrderClosePrice() - OrderOpenPrice())/Point >= OppositeDistance && BuyAllowed)  
                {//7  
                       RefreshRates();                          
                  BuyTicket = OrderSend(Symbol(), OP_BUY, MLots, Ask, Slippage*pips2points, 0, 0, "Buy Opposite Order", MagicNumber, 0, Green); 
                  if(BuyTicket > -1)
                   {//8
                     AddLimitsBuy();
                     BuyAllowed=false;SellAllowed=true;                                                                            
                     Print(" Opposite Buy Order Placed: ",BuyTicket," StopLoss: ",DoubleToStr(OrderStopLoss(),Digits)," Open Price: ",DoubleToStr(OrderOpenPrice(),Digits));                                   
                return;
                  }//8
               else
                  {//9                     
                    ErrorCode = GetLastError();
                    ErrDesc =ErrorDescription(ErrorCode);
                  
                    ErrAlert = StringConcatenate(" Open Opposite Order - Opposite Buy Failed: ",ErrorCode, ": ",ErrDesc);
                    Alert(ErrAlert);
         
                    ErrLog = StringConcatenate(" Open Opposite Order -  Ask: ",DoubleToStr(Ask,Digits)," Open Price: ",DoubleToStr(OrderOpenPrice(),Digits)," Ticket: " ,BuyTicket," Spread: ",DoubleToStr(Spread,Digits)," Lots: ",MLots," Stop Level: " ,StopLevel," Freeze Level: ",FreezeLevel);
                    Print(ErrLog);
                  }//9   
               }//7
            }//3
         }//2   
      }//1          
   }//0

Thank you for time spent

Luis 

18081961
687
18081961  

Hi RaptorUK,

My Apologies. You are right... here is the code for Add Limits;

 

void  AddLimitsBuy()
      {//0
        OpenPrice = OrderOpenPrice();
        OrderSelect(BuyTicket,SELECT_BY_TICKET);
                      
        BuyStopLoss = OpenPrice - (StopLoss * pips2dbl); 
        BuyTakeProfit = OpenPrice + (TakeProfit * pips2dbl);
            
        if(BuyStopLoss < MinimumStop)        
           BuyStopLoss = MinimumStop;
                                                                   
         RefreshRates();        
         if(!OrderModify(BuyTicket,OpenPrice,BuyStopLoss,BuyTakeProfit,0,CLR_NONE))
                
         ErrorCode = GetLastError();
         string ErrDesc = ErrorDescription(ErrorCode);
                  
         string ErrAlert = StringConcatenate(" Add Limits Buy Failed - Error: " , ErrorCode,": ",ErrDesc);
         Alert(ErrAlert);
                  
         string ErrLog = StringConcatenate("Add Limits Buy Failed - Ask: ", DoubleToStr(Ask,Digits)," Ticket: ",BuyTicket," Spread: ", DoubleToStr(Spread,Digits)," Lots: ", MLots," Buy Stop Loss: ", DoubleToStr(BuyStopLoss,Digits)," Stop Level: " , StopLevel," Freeze Level: " , FreezeLevel);
         Print(ErrLog);                          
        }//0
      
    //+------------------------------------------------------------------------------------------------------------------+ 
   //Add limits after sent order (ECN Brokers)   

   void   AddLimitsSell()
      {//0
       
       OrderSelect(SellTicket,SELECT_BY_TICKET);
                                                                              
            SellStopLoss = OpenPrice + (StopLoss * pips2dbl);
            SellTakeProfit = OpenPrice - (TakeProfit * pips2dbl); 
         
            if(SellStopLoss < MinimumStop)           
               SellStopLoss = MinimumStop;
                                                                      
                RefreshRates(); 
         if(!OrderModify(SellTicket,OpenPrice,SellStopLoss,SellTakeProfit,0,CLR_NONE))
         
         ErrorCode = GetLastError();
         string ErrDesc =ErrorDescription(ErrorCode);
                  
         string ErrAlert = StringConcatenate(" Add Limits Sell Failed - Error: ", ErrorCode, ": ",ErrDesc);
         Alert(ErrAlert);
         
         string ErrLog = StringConcatenate("Add Limits Sell Failed - Bid: ", DoubleToStr(Bid,Digits)," Ticket: " ,SellTicket," Spread: " ,DoubleToStr(Spread,Digits)," Lots: " ,MLots," Sell Stop Loss: ",DoubleToStr(SellStopLoss,Digits)," Stop Level: " , StopLevel," Freeze Level: " , FreezeLevel);
         Print(ErrLog);
         }//0

 

THank you to keep attention to my faults

Luis 

Simon Gniadkowski
17644
Simon Gniadkowski  
luisneves:

Hi RaptorUK,

My Apologies. You are right... here is the code for Add Limits;

OK,  very easy to fix this  . . .  you need some braces . . .

 RefreshRates();        
         if(!OrderModify(BuyTicket,OpenPrice,BuyStopLoss,BuyTakeProfit,0,CLR_NONE))  // this line says . . . if the OrderModify fails
                
         ErrorCode = GetLastError();    //   execute this code,  if the OrderModify succeeds don't execute it.


         string ErrDesc = ErrorDescription(ErrorCode);  //  this line and those that follow is executed regardless of what happens with he OrderModify
                  
         string ErrAlert = StringConcatenate(" Add Limits Buy Failed - Error: " , ErrorCode,": ",ErrDesc);
         Alert(ErrAlert);
                  
         string ErrLog = StringConcatenate("Add Limits Buy Failed - Ask: ", DoubleToStr(Ask,Digits)," Ticket: ",BuyTicket," Spread: ", DoubleToStr(Spread,Digits),
                     " Lots: ", MLots," Buy Stop Loss: ", DoubleToStr(BuyStopLoss,Digits)," Stop Level: " , StopLevel," Freeze Level: " , FreezeLevel);
         Print(ErrLog);  

 so you need to do this . . .

       RefreshRates();        
       if(!OrderModify(BuyTicket,OpenPrice,BuyStopLoss,BuyTakeProfit,0,CLR_NONE))
          {                                                                           //  add these braces
          ErrorCode = GetLastError();
          string ErrDesc = ErrorDescription(ErrorCode);
                  
          string ErrAlert = StringConcatenate(" Add Limits Buy Failed - Error: " , ErrorCode,": ",ErrDesc);
          Alert(ErrAlert);
                  
          string ErrLog = StringConcatenate("Add Limits Buy Failed - Ask: ", DoubleToStr(Ask,Digits)," Ticket: ",BuyTicket," Spread: ", DoubleToStr(Spread,Digits),
                   " Lots: ", MLots," Buy Stop Loss: ", DoubleToStr(BuyStopLoss,Digits)," Stop Level: " , StopLevel," Freeze Level: " , FreezeLevel);
          Print(ErrLog);

          }                                                     //  add these braces

      }  //0 

 Do the same for the Sell

18081961
687
18081961  
RaptorUK:

OK,  very easy to fix this  . . .  you need some braces . . .

 so you need to do this . . .

 Do the same for the Sell


Hi RaptorUk,

Thank you for your support. Now is working fine and I've done the same to all others instances of error routines.

Best Regards

Luis 

12
To add comments, please log in or register