Error 1 on OrderSend

 

Hi guys,

Error 1 on ordermodify is an old issue with a well known cause, but i'm getting error 1 on opening an order.

I searched the forum and the internet with no avail. Has anyone encountered similar problem?

Thanks.

 
bentbawer:

Hi guys,

Error 1 on ordermodify is an old issue with a well known cause, but i'm getting error 1 on opening an order.

I searched the forum and the internet with no avail. Has anyone encountered similar problem?

Thanks.

Show your code . . .


The most likely answer is that your error handling is wrong and you are seeing an error that is not related to your OrderSend()

 

I'll try to post everything that is relevant

void OpenOrders(int dir, string tradeCom, 
                                int ATR_Multiplier, int ATR_period, 
                                int StopLoss, bool MoneyManage, 
                                double lots, double Risk, string Acc_Type,
                                bool UseATR, bool UseStopLoss,
                                bool UseTakeProfit, int TakeProfit,
                                int Slippage, int MagicNumber, string Symb,
                                bool Notification) // dir = direction 1 BUY 2 SELL


(...)


        if(dir == 1) 
        {
                
                arrowColor = Coral;
                if (UseStopLoss) StopLossLevel = NormalizeDouble(Ask - (TotalSL * pips2dbl), Digits); 
                else StopLossLevel = 0.0;
                
                if (UseTakeProfit) 
                        {
                                TakeProfitLevel = NormalizeDouble(Ask + (TakeProfit * pips2dbl), Digits); 
                                arrowColor = MediumBlue;
                        }
                else TakeProfitLevel = 0.0;
        
        
                if(UseATR) 
                {
                        ATR_spread = SpreadSymb * pips2dbl;
                        StopLossLevel = NormalizeDouble(Ask - ((ATR * ATR_Multiplier) + ATR_spread), Digits);
                        
                        TakeProfitLevel = NormalizeDouble(Ask + (ATR * ATR_Multiplier * 2), Digits);
                
                }
                
                
                // -----------------------------------------------------------------
                //              Check for minimum SL and TP levels 
                // -----------------------------------------------------        
        
                if(SymbStop > 0 && (Bid - StopLossLevel) < (SymbStop * pips2dbl))
                                {
                                        StopLossLevel = NormalizeDouble(Bid - ((SymbStop + 1) * pips2dbl), Digits);
                                }
                        
                if(SymbStop > 0 && TakeProfitLevel - Bid < ((SymbStop + 1) * pips2dbl))
                                {
                                        TakeProfitLevel = NormalizeDouble(Bid + (SymbStop * pips2dbl), Digits);
                                }
                        
                        
                //------------------------------- // -------------------------------------
                                
                Ticket = 0;
                
                while(Ticket <= 0)
                {
                        
                        RefreshRates();
                        Ticket=OrderSend(Symb,OP_BUY,Lots,Ask,Slippage * pips2points,StopLossLevel,TakeProfitLevel, tradeCom, MagicNumber, arrowColor);  //Opening Buy
                        
                        
                        if(Ticket == -1) err = GetLastError();
                        else return(true);
                        
                        if(MaxRetries > 0 && ErrorCheck(err)) MaxRetries--;
                        else
                        {
                                
                                Print("Error opening BUY order: " + err + " = " + ErrorDescription(err));
                                string note1 = ErrorDescription(err);
                                string msg = StringConcatenate("Error opening BUY order: ", err, " = ", note1);
                                if(Notification) SendNotification(msg);
                                break;
                        }
                        
                }
        
        }

This OpenOrders function is in a library. I can't replicate the problem in back tests.

Thanks for looking at this.

 
bentbawer:

I'll try to post everything that is relevant

This OpenOrders function is in a library. I can't replicate the problem in back tests.

Thanks for looking at this.

Just to be certain that the error is coming from the code above, can you:

  1. copy and paste the line(s) from the log that show the error
  2. confirm that this error message text ( see below ) is not present anywhere else in the code ?

Print(   "Error opening BUY order: "    + err + " = " + ErrorDescription(err));

What were the values of these variables when the error occurred ?

Symb, Lots, Ask, Slippage, pips2points, StopLossLevel, TakeProfitLevel, tradeCom, MagicNumber, arrowColor ?

Why don't you print these variables as part of your error reporting ?


This may well be your issue . . . MagicNumber, arrowColor . . . I'm guessing arrowColor isn't a valid value for expiration, the expiration parameter comes between magic and arrow_color ( OrderSend() ) if you want to specify arrow_color you must also specify expiration

 

Hi Raptor,

I'll add the extra info in my error report, but just a quick comment regarding expiration. According to this https://docs.mql4.com/trading/ordersend expiration is for pending orders only. The code above and the equivalent for sell are for market orders, hence no expiration needed.

I must add that i'm not getting this error 1 all the time with all EAs (i have about 8 using the same library) which leads me to believe that the error might not be in the library and/or is pair dependent.

Here is number 1:

2013.10.30 12:31:59 JagLibrary NZDJPYi,M15: Error opening BUY order: 1 = no error

JagLibrary is the name of my library

Number 2:

I double checked it and that error message is only inside the Buy if of the OpenOrders function.

Again, i'll follow your suggestion to print more info in the error message to see if i can spot it.

Thanks.

 
bentbawer:

Hi Raptor,

I'll add the extra info in my error report, but just a quick comment regarding expiration. According to this https://docs.mql4.com/trading/ordersend expiration is for pending orders only. The code above and the equivalent for sell are for market orders, hence no expiration needed.

You have to have the parameter even if you don't use it . . if you want to use arrow_color . . . how can the function know if your value for arrow_color is meant for expiration or arrow_color ? it can't read your mind . . . so add in a 0 for expiration and retest.
 

Hi Raptor,

I got my first error since making the changes you suggested.

This is from the Experts window:

2013.10.30 17:37:13 JagLibrary NZDJPY,M15: dir: 2 Symb: NZDJPYi Lots: 0.65000000 Slippage: 2 Slip * pips2points: 20.00000000 StopLossLevel: 81.18800000 TakeProfitLevel: 80.37700000 tradeCom: SELL LIB MagicNumber: 2012 arrowColor: 255

Just to confirm, i did add the expiration time as well.

By analysing the Journal and experts, I seem to have spotted that the EA is trying to open a trade with opening price at 0.000. This would cause an error [Trade Timeout], I just wasn't expecting error 1.

The error occurs with NZDJPY and GBPJPY.

 
bentbawer:

Hi Raptor,

I got my first error since making the changes you suggested.

This is from the Experts window:

2013.10.30 17:37:13 JagLibrary NZDJPY,M15: dir: 2 Symb: NZDJPYi Lots: 0.65000000 Slippage: 2 Slip * pips2points: 20.00000000 StopLossLevel: 81.18800000 TakeProfitLevel: 80.37700000 tradeCom: SELL LIB MagicNumber: 2012 arrowColor: 255

Just to confirm, i did add the expiration time as well.

By analysing the Journal and experts, I seem to have spotted that the EA is trying to open a trade with opening price at 0.000. This would cause an error [Trade Timeout], I just wasn't expecting error 1.

The error occurs with NZDJPY and GBPJPY.

Did you also Print Ask and Bid ? I don't see them . . . while you are at it also Print your attempted opening price, Freezelevel and Stoplevel.
 
Yeah, i'm adding these now.
 
NZDJPY,M15: dir: 2 Symb: NZDJPYi
Why does it say you're on the NZDJPY chart but trying to open an order on the pair "NZDJPYi" ?
 

Hi WHRoeder,

I believe i might have changed the name of the pair by accident when posting the info here.

After spotting that i was getting an error 1 because the EA was trying to open a trade with price 00, i added MarketInfo(Symbol(),MODE_BID) and ask to my OrderSend instead of just Bid and Ask. I don't think there is normally a need for that, but since my OpenOrders function is inside an external library, this might do the trick. I changed the code and haven't received an error yet.

Reason: