functin errors

Back to topics list To post a new topic, please log in or register
avatar
32
m_shafiei2006 2016.04.29 03:13
 

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 ?


avatar
Moderator
3427
GumRai 2016.04.29 03:36 #
 

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


avatar
32
m_shafiei2006 2016.04.29 03:42 #
 

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);
        }
avatar
Moderator
3427
GumRai 2016.04.29 04:08 #
 

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

avatar
32
m_shafiei2006 2016.04.29 04:11 #
 
thank you very much.
avatar
13012
WHRoeder 2016.04.29 14:43 #
 
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);

Back to topics list  

To add comments, please log in or register