Download MetaTrader 5

Problems in placing a simple order

To add comments, please log in or register
24h-worker
86
24h-worker 2009.12.04 00:56 

One of the hardest work in the computer industry is to place an order with MQL5.

It needs time, you must be passioned, but some day it will happen, I hope.

 

Was anyone here in the Forum successful ?

 

  MqlTradeRequest EURUSD_Buy;
 
  EURUSD_Buy.action = TRADE_ACTION_DEAL;
  EURUSD_Buy.symbol = "EURUSD";
  EURUSD_Buy.volume = 1;
  EURUSD_Buy.type = ORDER_TYPE_BUY;
  EURUSD_Buy.type_filling = ORDER_FILLING_AON;

 
  MqlTradeResult EURUSD_Buy_Result;

 
  OrderSend(EURUSD_Buy,EURUSD_Buy_Result);
 
  Alert(EURUSD_Buy_Result.retcode);                  // Mistake 10016 (Invalid stops in request)

 

 In the documentation I could read that  stoploss / takeprofit  values are not neccessary.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Trade Operation Types - Documentation on MQL5
Paul
784
Paul 2009.12.04 03:58  
24h-worker :

One of the hardest work in the computer industry is to place an order with MQL5.

It needs time, you must be passioned, but some day it will happen, I hope.

 

Was anyone here in the Forum successful ?

 

  MqlTradeRequest EURUSD_Buy;
 
  EURUSD_Buy.action = TRADE_ACTION_DEAL;
  EURUSD_Buy.symbol = "EURUSD";
  EURUSD_Buy.volume = 1;
  EURUSD_Buy.type = ORDER_TYPE_BUY;
  EURUSD_Buy.type_filling = ORDER_FILLING_AON;


  MqlTradeResult EURUSD_Buy_Result;


  OrderSend(EURUSD_Buy,EURUSD_Buy_Result);
 
  Alert(EURUSD_Buy_Result.retcode);                  // Mistake 10016 (Invalid stops in request)

 

 In the documentation I could read that  stoploss / takeprofit  values are not neccessary. 


The 10016 error is probably because you didn't set the open price.  You should really explicitly set all the members of MqlTradeRequest to something, so deviation should be set to something like 50, sl and tp should be set to zero even if you don't want to use them, and I'd also assign a number to magic.

 

 

 

 

 

24h-worker
86
24h-worker 2009.12.04 21:47  

Now I know, where the problem is.

 

  MqlTick XXX;
  Alert(XXX.ask);  // result 0

 

I get always 0 (XXX.ask and XXX.bid).

 

When I use a real number like 1.50487  (for EURUSD_Buy.price) I could place the order. 

 

There is something wrong with MqlTick in my code or general.

 

Greetings

Achim R. 

24h-worker
86
24h-worker 2009.12.04 22:21  

With this values I can place an order:

 

  MqlTick Preis;

  MqlTradeRequest EURUSD_Buy;
 
  EURUSD_Buy.action = TRADE_ACTION_DEAL;
  EURUSD_Buy.symbol = "EURUSD";
  EURUSD_Buy.volume = 1;
  EURUSD_Buy.price = 2.00000;   //1.48731 at the moment;  //Preis.ask: not possible
  EURUSD_Buy.deviation = 60000;
  EURUSD_Buy.sl = 0;
  EURUSD_Buy.tp = 0;
  EURUSD_Buy.type = ORDER_TYPE_BUY;
  EURUSD_Buy.type_filling = ORDER_FILLING_AON;
 
 
  MqlTradeResult EURUSD_Buy_Result;

 
  OrderSend(EURUSD_Buy,EURUSD_Buy_Result);
 
  Alert(EURUSD_Buy_Result.retcode);  // Return Code 10009: Order done, perfect programming 

 

I take a fantasy price like 2.0 until Preis.ask is working.

MQL5 insert the right ask-price.

 

 

24h-worker
86
24h-worker 2009.12.04 22:39  

Now I know how it runs:

 

  MqlTick Preis;
  SymbolInfoTick("EURUSD",Preis);

 

 Alert(Preis.ask);

 

You must previously use SymbolInfoTick() and then you have access to the variables ask, bid in the structure Preis.

With MqlTradeRequest you have direct access to the variables.

 

 

 

Andriy Moraru
1261
Andriy Moraru 2009.12.05 11:18  
24h-worker :

Now I know how it runs:

 

  MqlTick Preis;
  SymbolInfoTick("EURUSD",Preis);

 

 Alert(Preis.ask);

 

You must previously use SymbolInfoTick() and then you have access to the variables ask, bid in the structure Preis.

With MqlTradeRequest you have direct access to the variables.

 

 

 


You can use SymbolInfoDouble(Symbol(), SYMBOL_BID) and SymbolInfoDouble(Symbol(), SYMBOL_ASK) to get the current Bid/Ask price.
To add comments, please log in or register