Download MetaTrader 5

return value of 'OrderSend' should be checked

To add comments, please log in or register
Log in to MQL5.community using OpenID. It is convenient!
Icham Aidibe
10044
Icham Aidibe 2014.05.03 03:43 

Hi !

I'm wondering how to do that ...:/ the warning appeared @ the last update

 //--- preparing a request
                           MqlTradeRequest request;
                           ZeroMemory(request);
                           //--- placing an immediate order
                           request.action=TRADE_ACTION_SLTP;
                           //--- instrument
                           request.symbol=Symbol();
                           //--- Stop Loss 
                           request.sl=100;
                           //--- Take Profit is not specified
                           request.tp=0;
               
                           MqlTradeResult result;
                           ZeroMemory(result);
                           MqlTradeCheckResult CheckResult;
                           //--- sending the order
                           if(OrderCheck(request,CheckResult)) { 
                           OrderSend(request,result);
                                                     }
                           
                           else
                             {
                              //--- printing the server response to the log  
                              Print(CheckResult.retcode,"  -error ");
                              Print(request.sl,"  ",LastPrice,"  buy  ");
                              Print(__FUNCTION__,":",CheckResult.comment);
                             }
                             
Rogerio Figurelli
Moderator
39652
Rogerio Figurelli 2014.05.03 04:08  
blouf:

Hi !

I'm wondering how to do that ...:/ the warning appeared @ the last update

Note that you must define SL as price and not as relative points, as you are doing.

The exception is value 0, that indicates no SL or no TP.

Icham Aidibe
10044
Icham Aidibe 2014.05.03 04:36  
figurelli:

Note that you must define SL as price and not as relative points, as you are doing.

The exception is value 0, that indicates no SL or no TP.

yeah ...  what about the ordercheck ?
haoxiang xie
1076
haoxiang xie 2014.05.03 04:53  
blouf:

Hi !

I'm wondering how to do that ...:/ the warning appeared @ the last update

just modify as followed...

if(OrderSend(request,result)) {...};

 warning should disappear.

Rogerio Figurelli
Moderator
39652
Rogerio Figurelli 2014.05.03 05:18  
blouf:
yeah ...  what about the ordercheck ?

Sorry but your question is not clear to me.

Anyway, if you are meaning that OrderCheck() is so smart to know this SL difference or even convert points in price, I see no way, you must check this for the symbol you are trading. 

Rogerio Figurelli
Moderator
39652
Rogerio Figurelli 2014.05.03 05:26  
xhxiang:

just modify as followed...

 warning should disappear.

Right, this will solve the OrderSend() return value check warning, but will not check the return (you need the else condition, as below).

if(OrderSend(request,result)) {...}; else {... return error value check here ...};
Alain Verleyen
Moderator
30739
Alain Verleyen 2014.05.03 11:10  
figurelli:

Right, this will solve the OrderSend() return value check warning, but will not check the return (you need the else condition, as below).

Documentation of Ordersend :

In case of a successful basic check of structures (index checking) returns true. However, this is not a sign of successful execution of a trade operation. For a more detailed description of the function execution result, analyze the fields of result structure.

Rogerio Figurelli
Moderator
39652
Rogerio Figurelli 2014.05.03 15:31  
angevoyageur:

Documentation of Ordersend :

Really? I think you misunderstood my point.
Alain Verleyen
Moderator
30739
Alain Verleyen 2014.05.03 15:41  
figurelli:
Really? I think you misunderstood my point.

Not at all. You are right that he has to add an "else" statement. But not in the way your code is showing. Even if OrderSend() return true, you can have a problem with your trading operation.

bool res=OrderSend(request,result);

if(res && (result.retcode=xx || result.retcode=yy ....))
 { Trade operation is ok ...}; 
else 
 {... return error value check here ...};
Rogerio Figurelli
Moderator
39652
Rogerio Figurelli 2014.05.03 15:52  
angevoyageur:

Not at all. You are right that he has to add an "else" statement. But not in the way your code is showing. Even if OrderSend() return true, you can have a problem with your trading operation.

Sorry, but I really think you misunderstood my point.

First of all, I said that there was an error at the original code (about SL), and that this is the first and more relevant point to me.

And after, I was trying to say that post below, before mine (and not mine), is not enough to test all OrderSend() return conditions, as looks like you are trying to say.

Forum on trading, automated trading systems and testing trading strategies

return value of 'OrderSend' should be checked

xhxiang, 2014.05.03 04:53

just modify as followed...

if(OrderSend(request,result)) {...};

 warning should disappear.


Alain Verleyen
Moderator
30739
Alain Verleyen 2014.05.03 16:01  
figurelli:

Sorry, but I really think you misunderstood my point.

First of all, I said that there was an error at the original code (about SL), and that this is the first and more relevant point to me.

And after, I was trying to say that post below, before mine (and not mine), is not enough to test all OrderSend() return conditions, as looks like you are trying to say.


Yes, and your answer is not enough either. So my post.
123
To add comments, please log in or register