can not open market order on MT5 demo account - page 2

 

@phi,nuts

I tried your code and the message received was:

2013.01.21 14:31:53 Buy_SellOrderMarketPrice (EURUSD,M1) error 4756 check code 10013
I look at both 4756 and 10013 explanations but I can not figure what is wrong.... 

 
tenlau:

@phi,nuts

I tried your code and the message received was:

2013.01.21 14:31:53 Buy_SellOrderMarketPrice (EURUSD,M1) error 4756 check code 10013
I look at both 4756 and 10013 explanations but I can not figure what is wrong.... 

Forgot nulling the structure ;(

     MqlTradeRequest request   = {0}; // nulling MqlTradeRequest structure
     MqlTradeResult result     = {0}; // nulling MqlTradeResult structure
     MqlTradeCheckResult check = {0}; // nulling MqlTradeCheckResult structure

If you like , you also may add deviation, since AlpariUK is using fractional pips.

     request.price  = latest_price.bid;       //--- get the bid price (did Wahoo, achidayat, and tuoitrecuoi tell you so ?)
     request.sl           = 0;                   // sl ==>> we add sl later or using limit pending order as sl           
     request.tp           = 0;                   // tp ==>> we add tp later or using stop pending order as tp 
     request.deviation    = 10;                  // change the slippage from 2 to 10
 
phi.nuts:

Forgot nulling the structure ;(

If you like , you also may add deviation, since AlpariUK is using fractional pips.

 

Thank you! It works ! One last question: way is needed to null the structure (why it is not working the code without nulling)?
 
tenlau:
Thank you! It works ! One last question: way is needed to null the structure (why it is not working the code without nulling)?

way or why ?

The answer is : why not ;D.

To reset all pointer to the mql5 trade structure.

Basically we don't have to use all member of trade structure, and if we do that without resetting the structure, we may send wrong request to broker.

Another way to null the structure is by using ZeroMemory() 

     MqlTradeRequest request;
     MqlTradeResult result;
     MqlTradeCheckResult check;

     ZeroMemory(request);
     ZeroMemory(result);
     ZeroMemory(check);

I re-read your topic again, and try to send orders without any price, using code like this

request.price  = 0.0; //--- open price at 0.0000 price

... and the position gets opened. I won't recommend using this way, because broker may change it's execution type on the fly without telling us, which may cost us the position not opened. If this is happen, we can ask our trading log from broker (yes they have logs of our trading activity and you can ask them), and compare it with our log, but it's a little late for that, position already not opened.

 
phi.nuts:

way or why ?

The answer is : why not ;D.

To reset all pointer to the mql5 trade structure.

Basically we don't have to use all member of trade structure, and if we do that without resetting the structure, we may send wrong request to broker.

Another way to null the structure is by using ZeroMemory() 


I re-read your topic again, and try to send orders without any price, using code like this

... and the position gets opened. I won't recommend using this way, because broker may change it's execution type on the fly without telling us, which may cost us the position not opened. If this is happen, we can ask our trading log from broker (yes they have logs of our trading activity and you can ask them), and compare it with our log, but it's a little late for that, position already not opened.

Thank you very much for all !