Need Help with my code

 

Please tell me what is wrong with my code on the snippet below, after compiling there is a warning that says I 'OrderSelect' and 'OrderClose' should be checked and when I execute the EA on my chart, it does not close at the specified points.

void CloseBuyPositions()
 {
 for(int i=OrdersTotal()-1; i>=0;i--)
 {
 OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
 string CurrencyPair=OrderSymbol();
 if(_Symbol==CurrencyPair)
 if(OrderType()==OP_BUY)
 {
 OrderClose(OrderTicket(),OrderLots(),Bid,0,NULL);
 }
 }
 }   
 void CloseSellPositions()
 {
 for(int k=OrdersTotal()-1; k>=0;k--)
 {
 OrderSelect(k,SELECT_BY_POS,MODE_TRADES);
 string CurrencyPair=OrderSymbol();
 if(_Symbol==CurrencyPair)
 if(OrderType()==OP_SELL)
 {
 OrderClose(OrderTicket(),OrderLots(),Ask,0,NULL);
 }
 }
 }   

 
20843712: Please tell me what is wrong with my code on the snippet below, after compiling there is a warning that says I 'OrderSelect' and 'OrderClose' should be checked
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  3. What is wrong is you don't check.

    Check your return codes for errors, and report them including GLE/LE, your variable values, and the market. That way we would know that at least you are calling your code.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

    Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  4. Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
              PositionClose is not working - MQL5 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles