functin errors

 

Hi


I get 2 errors on this function

#property strict
#import "stdlib.ex4"
#import


void    CloseLongTicket()
        {
           for(int i=OrdersTotal()-1;i>=0;i--)
           if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)
              {
                 if(OrderType() == OP_BUY)
                 bool order = OrderClose(OrderTicket(),OrderLots(),Bid,3,clrRed);
                 if (order == false)
                 Alert("Close Long Error = ",ErrorDescription(GetLastError()));
              }
           return;
        }



which is :

1.'order' - undeclared identifier

2.'ErrorDescription' - function not defined


can anybody explain what are these errors and how can I fix them ? and is return; necessary or not ?

 

For the error description, I use

#include <stdlib.mqh>


void    CloseLongTicket()
        {
           for(int i=OrdersTotal()-1;i>=0;i--)
           if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)
              {
                 if(OrderType() == OP_BUY)
                 {
                 bool order = OrderClose(OrderTicket(),OrderLots(),Bid,3,clrRed);
                 if (order == false)
                 Alert("Close Long Error = ",ErrorDescription(GetLastError()));
                 }
              }
           return;
        }

You need the {} as highlighted

 

thanks,


and is return; necessary ? compile with and without return;


i ask this because i get confused whit this code ! it gives me error too.


int     BuyPosIndex()
        {
           for(int i=OrdersTotal()-1;i>=0;i--)
           {
              if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)
              {
                 if(OrderType() == OP_BUY)
                 return(i);
              }
           }   
           return(i);
        }
 

return is necessary except for a void function.

int     BuyPosIndex()
  {
   int i;
   for(i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
        {
         if(OrderType()==OP_BUY)
            return(i);
        }
     }
   return(i);
  }

You need to declare int i before the loop or it is only local to the loop

Otherwise, you could just return(-1) for the final return

 
thank you very much.
 
This does nothing
use #include <stdlib.mqh>
#import "stdlib.ex4"
#import
#import "stdlib.ex4"
string ErrorDescription(int error_code);
int    RGB(int red_value,int green_value,int blue_value);
bool   CompareDoubles(double number1,double number2);
string DoubleToStrMorePrecision(double number,int precision);
string IntegerToHexString(int integer_number);
Reason: