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

 

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

 

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.

 

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

 

... 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

 
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. 

 
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
Reason: