Returning error codes which I have told my EA to ignore.

 

So is there any particular valid reason as to why my EA is doing the very opposite to what I have told it do to? 

Any valid reason as to why It's returning known OrderSelect() error messages when I have set my EA to ignore certain error codes. I know why the EA is retuning these error codes and is just a by-product of the EA, & does not render the EA useless.

Below is the code, I have set it to ignore error 0, 4105, and 4202 (line175)

Can anybody shed any light as to why it's still returning error code 4105, which have told it to ignore?

It's just getting really tedious, only I could code an algorithm that behaves like a disobedient child, especially when my EA correctly selects the order from the ledger and displays the correct information on the chart.

This EA is spread over a number of charts simultaneously.

This will open a position on the next opening bar, so the 1m timeframe is advised. 


//+------------------------------------------------------------------+
//|                                                        blank.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

int         lastError = GetLastError();
datetime    BarTime = 0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

BarTime                 =  Time[0];
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

for(int s = OrdersTotal()-1; s>= 0; s--){
   
      if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES) && Symbol() == OrderSymbol() && Period() == OrderMagicNumber()){ 
      
         ObjectCreate("MovingText", OBJ_TEXT, 0,0,0);
        
            ObjectCreate(
            
               0,
   
                "ClosePosition",
   
                        OBJ_BUTTON,
   
                                0,
   
                                        0,
   
                                                0
      
            );
    
            ObjectSetInteger(0,"ClosePosition", OBJPROP_XDISTANCE, 0);
     
               ObjectSetInteger(0,"ClosePosition", OBJPROP_XSIZE, 400);
           
                  ObjectSetInteger(0,"ClosePosition", OBJPROP_YDISTANCE, 20);
           
                     ObjectSetInteger(0,"ClosePosition", OBJPROP_YSIZE, 50);
           
                        ObjectSetInteger(0,"ClosePosition", OBJPROP_CORNER,CORNER_LEFT_UPPER);
            
                           ObjectSetInteger(0,"ClosePosition", OBJPROP_COLOR,clrWhite);
            
                              if(OrderProfit() > 0.01){
                              
                                 ObjectSetInteger(0,"ClosePosition", OBJPROP_BGCOLOR, clrGreen);
                                 
                                    ObjectSetString(0,"ClosePosition", OBJPROP_TEXT,"Close Ticket #"+IntegerToString(OrderTicket(),0)+" with profit "+AccountCurrency()+DoubleToString(OrderProfit(),2));
                  
                              }
            
                              else {
                              
                                 ObjectSetInteger(0,"ClosePosition", OBJPROP_BGCOLOR,clrCrimson);
                                 
                                    ObjectSetString(0,"ClosePosition", OBJPROP_TEXT,"Close Ticket #"+IntegerToString(OrderTicket(),0)+" with loss "+AccountCurrency()+DoubleToString(OrderProfit(),2));
                              
                              }
         
                              ObjectSetInteger(0,"ClosePosition", OBJPROP_FONTSIZE,10);
                     
                                 ObjectCreate(
                                 
                                    0,
                                    
                                       "pip_indicator",
                                       
                                          OBJ_LABEL,
                                          
                                             0,
                                             
                                                0,
                                                
                                                   0
                                 );
                             
                                 ObjectSetInteger(0,"pip_indicator", OBJPROP_XDISTANCE, 20);
                       
                                    ObjectSetInteger(0,"pip_indicator", OBJPROP_XSIZE, 400);
                             
                                       ObjectSetInteger(0,"pip_indicator", OBJPROP_YDISTANCE, 100);
                             
                                          ObjectSetInteger(0,"pip_indicator", OBJPROP_YSIZE, 50);
                             
                                             ObjectSetInteger(0,"pip_indicator", OBJPROP_CORNER,CORNER_LEFT_UPPER);
                                                                           
                                               ObjectSetString(0,"pip_indicator", OBJPROP_FONT,"Impact");
                                                      
                                                  ObjectSetInteger(0,"pip_indicator", OBJPROP_BGCOLOR, clrNONE);
                                                   
                                                     ObjectSetInteger(0,"pip_indicator", OBJPROP_FONTSIZE,30);
                                                      
                                                        if(OrderType() == OP_BUY){
                                                         
                                                            if(OrderProfit() >= 0.01){
                                                            
                                                               ObjectSetString(0,"pip_indicator", OBJPROP_TEXT,Symbol()+" +"+DoubleToString((Bid - OrderOpenPrice())/Point,0));
                                                               
                                                                  ObjectSetText("MovingText",Symbol()+" +"+DoubleToString((Bid - OrderOpenPrice())/Point,0));
                                                            
                                                            } else {
                                                            
                                                               ObjectSetString(0,"pip_indicator", OBJPROP_TEXT,Symbol()+" "+DoubleToString((Bid - OrderOpenPrice())/Point,0));
                                                               
                                                                  ObjectSetText("MovingText",Symbol()+" "+DoubleToString((Bid - OrderOpenPrice())/Point,0));
                                                            
                                                            }
                                                            
                                                        } else if(OrderType() == OP_SELL) {
                                                         
                                                            if(OrderProfit() >= 0.01){
                                                            
                                                               ObjectSetString(0,"pip_indicator", OBJPROP_TEXT,Symbol()+" +"+DoubleToString((OrderOpenPrice() - Ask)/Point,0));
                                                                  
                                                                  ObjectSetText("MovingText",Symbol()+" +"+DoubleToStr((OrderOpenPrice() - Ask)/Point,0));
                                                                  
                                                            
                                                            } else {
                                                            
                                                               ObjectSetString(0,"pip_indicator", OBJPROP_TEXT,Symbol()+" "+DoubleToString((OrderOpenPrice() - Ask)/Point,0));
                                                                  
                                                                  ObjectSetText("MovingText",Symbol()+" "+DoubleToStr((OrderOpenPrice() - Ask)/Point,0));
                       
                                                            }
                                                         
                                                        }
                                                                                                                  
                                                        if (OrderProfit()>= 0.01){
                                                         
                                                            ObjectSetInteger(0,"pip_indicator", OBJPROP_COLOR,clrGreen); 
                                                            
                                                               ObjectSetInteger(0,"MovingText", OBJPROP_COLOR,clrGreen); 
                                                         
                                                        } else {
                                                      
                                                            ObjectSetInteger(0,"pip_indicator", OBJPROP_COLOR,clrCrimson); 
                                                            
                                                               ObjectSetInteger(0,"MovingText", OBJPROP_COLOR,clrCrimson); 
                                                         
                                                        }
                                 
                                                        ObjectMove("MovingText",0,Time[0],Bid);
                                                         
                                                            ObjectSetString(0,"MovingText", OBJPROP_FONT,"Impact");  
                                                            
                                                                  ObjectSetInteger(0,"MovingText", OBJPROP_FONTSIZE,20);                             
      
      } else {
      
         if(lastError >= 1){
         
            if(lastError != 4202){
            
               if(lastError != 4105){
               
                  MessageBox("You have an order selection error. Please report error #"+IntegerToString(lastError,0),"Order Seect Error",MB_ICONERROR | MB_OK);
                  
                     Print("Please report error #"+IntegerToString(lastError,0));
                  
                        BarTime = Time[0];
                        
                           return;
               
               }
            
            } //lastError != 4202
         
         } //lastError >= 1
      
      } //OrderSelect(!s,SELECT_BY_POS,MODE_TRADES) && Symbol() == OrderSymbol()
            
   }  //for(int s = OrdersTotal()-1; s>= 0; s--)
   
   if(BarTime != Time[0]){
  
         bool openShort = OrderSend(Symbol(),OP_SELL,1,MarketInfo(Symbol(),MODE_BID),100,((Bid/Point)+(100))*Point,((Bid/Point)-(100*3))*Point,"comment",Period(),0,clrGainsboro);
  
		BarTime = Time[0];

   }
   
  }
  
  
//+------------------------------------------------------------------+
 
William Roeder #:
  1. Format your code so you can see what lines belong to what group.
  2. That is not an assignment; it's initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.

    1. They are initialized once on program load.

    2. They don't update unless you assign to them.

    3. In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).

      MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and

      Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:

      1. Terminal starts.
      2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
      3. OnInit is called.
      4. For indicators OnCalculate is called with any existing history.
      5. Human may have to enter password, connection to server begins.
      6. New history is received, OnCalculate called again.
      7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

    4. Unlike indicators, EAs are not reloaded on chart change, so you must reinitialize them, if necessary.
                external static variable - MQL4 programming forum #2 (2013)

  3. Yes, you told it wrong. Delete the useless variable and use the proper _LastError

  4. Why are you rejecting 4105 and zero? Those statements will only be called if OrderSelect fails. You will never get those values.

Hi William

You're a familiar name here :) 

1. Unless I'm missing something, the code is formatted. The appropriate indentations to the code are present, so the reader can easily see the closing bracket is aligned with the start of the opening IF statement? Sorry if this isn't the correct formatting - happy to learn. 
3. Is GetLastError() not the same as _LastError?
4. I'm rejecting zero because I was getting #0 - which isn't and error at all - and the 4105 error because it was contradicting itself, it was selecting the order correctly but then it was returning error 4105. 

All the best,


 
William Roeder #:

Yes, because you told it wrong, but since you were argumentative (https://www.mql5.com/en/forum/382355) and used bad language (https://www.mql5.com/en/forum/378059) You are on my do not help list. Live in ignorance.

You have literally just heled me - which is great - but why the sudden attack? 

 
William Roeder #:

Yes, because you told it wrong, but since you were argumentative (https://www.mql5.com/en/forum/382355) and used bad language (https://www.mql5.com/en/forum/378059) You are on my do not help list. Live in ignorance.

Oh Boo Hoo William, Get Over Yourself & grow up. How big is your ego right now? 

"Oh no, I'm on your Do No Help list, what will I do with myself? How will I sleep at night knowing that I'm on The Great & Legendary Almighty William's Do Not Help List?"

*gasps in shock* 

How many times do you gaslight people on here?

Argumentative ? No Almighty William , I was defending myself against the silly little boys on here who think they can play hard ball with the grown ups, staying up way past their bedtimes and thinking they're "Well 'ard, Innit!". No, Will, they got butt - hurt because I called them out of the fact that their suggestion did not work - on a public forum for all to see - so they went crying to their mothers because the "big mean man on the MQL4 forum hurt my feelings", right before coming back on here and have the nerve to berate me for being "incompetent". People come here to learn and better their craft, not to have some crying, not to have to deal with adults who behave like crying, whinging little children.

Guess what, Almighty William, it's laughable, its pathetic and the admin of this forum needs to have a serious look at how much of a schoolyard this forum has become  some people on here need to grow a pair of balls and grow up.

Do not help list? Oh please, do you seriously think I give a toss whose list I'm on, or not on? 

Here's an idea William, instead of trying to outdo me with big, fancy words, how about you just don't reply to me? Can you do that William, or does the Oppositional Defiant Disorder - sorry, I mean the chip on your shoulder - you clearly have, prevent you from backing down? You have a serious problem, you need to sort it out. 

You could not resist yourself could you? In the post you refer to,  EA is not carrying out the function I'm telling it to. - Trading Algorithms - MQL4 and MetaTrader 4 - MQL4 programming forum (mql5.com) when that other gentleman, Paul, who actually solved the issue, you just could not help yourself.

Even way after everyone else stopped talking, you carried on, going on about me apparently wanting you to debug my code (not true), & told me I did not undergo any error reporting (I did, hence why I knew the error code my EA was returning).

You want to carry on making a total prat of yourself, William, you keep posting on here. I have seen many people on here comment on your smug little attitude so don't think you're perfect and don't think you can do no wrong. You clearly don't know how forums work, people come on here to get better at their craft, not for immature, insecure, ill-disciplined little boys like you to tell people how inferior they are to them, just because they don't exactly conform to your style of coding, or your way of thinking, or just because they don't bow down to you.

Tell me, William, is that why you hate me? Because I'm telling you exactly what everyone else on this forum thinks about you, because I'm the only one on this forum who won't bow down to you and kiss your feet every time you reply to a topic I post on here? Is that the real reason as to why you have a chip with me William? 

Go on, man up and admit it. You hate me because I stand up for myself.  So you carry on hating me, you carry on berating me, and you can leave me on your little Do Not Help list. You want to bully me, Sunshine? Well I welcome it. 

Let me make one thing clearly with you right now, William, I would rather be hated for standing up for myself against bullies like you, than to be respected for rolling over and bowing down to you.

You are a total and utter disgrace and Trevor is failing all of us for allowing you to be on here. It's people like you who put people off of learning to code - I just hope to God you're not a teacher as your occupation. 

Reason: