Download MetaTrader 5
To add comments, please log in or register
How to buy a product in MetaTrader AppStore? Read the article!
BigAl
487
BigAl 2015.02.25 09:31 

When coding within a void?

If i use the code:

     OrderClose(MyTicket, OrderLots(), OrderClosePrice(), 3, Blue);

On compilation I get a warning "return value of 'OrderClose' should be checked"

If i use the code:

     if (!OrderClose(MyTicket, OrderLots(), OrderClosePrice(), 3, Blue)) return(-1);

On compilation I get a warning "'void' function returns a value"

But if I use the code:

     Result = OrderClose(MyTicket, OrderLots(), OrderClosePrice(), 3, Blue);

Then I get no warnings but have a variable "Result" that is of no use to me at all as I have no idea what it contains

Is it me or is this just MQL just wierd in this area

Carl Schreiber
5952
Carl Schreiber 2015.02.25 09:35  

What about reading? All you nee you fin in either the Book or Documentation (links are above) or in the editor's reference.

You would have found for order close:

Returned value

Returns true if successful, otherwise false. To get additional error information, one has to call the GetLastError() function.

BigAl
487
BigAl 2015.02.25 09:39  

Gooly - I know that but you missed the point of my query which is the warnings inside from inside void() code which seem to be weird

darelco
24
darelco 2015.02.25 10:50  

... instead of trying to discover an America once again ... just do a quick search within previous topics on this forum ...

and surely, you'll be able to find a correct answer to your query ... for example: Loops and Closing or Deleting Orders

Keith Watford
Moderator
7953
Keith Watford 2015.02.25 11:27  
BigAl:

Gooly - I know that but you missed the point of my query which is the warnings inside from inside void() code which seem to be weird


Isn't the warning self-explanatory?

A void function does not return a value, but you are trying to do just that. 

whroeder1
13620
whroeder1 2015.02.25 12:38  
BigAl: Is it me or is this just MQL just wierd in this area
if (!OrderClose(MyTicket, OrderLots(), OrderClosePrice(), 3, Blue)) return(-1); 
It's you. How can a void function return a value? You have:
void funtion(){ ... return(-1); ... }
What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
/
To add comments, please log in or register