what is the correct way to code for a result in a void segment

Back to topics list To post a new topic, please log in or register
avatar
108
BigAl 2015.02.25 10: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

avatar
2017
gooly 2015.02.25 10: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.

avatar
108
BigAl 2015.02.25 10: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


avatar
9
darelco 2015.02.25 11: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

avatar
Moderator
3418
GumRai 2015.02.25 12: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. 

avatar
13001
WHRoeder 2015.02.25 13: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

Back to topics list  

To add comments, please log in or register