Download MetaTrader 5
To add comments, please log in or register
Write articles and earn money. We pay 200 USD for them!
Aecio de Feo Flora Neto
3507
Aecio de Feo Flora Neto 2014.08.29 13:14 

Hello all,

I am building an EA and it is properly sending orders, but every time it reports [invalid expiration].

I would need this EA to send orders as pending orders, since the strategy requires a start order.

 

The code I have is below, please advise.

 

    MqlTradeRequest request;

   MqlTradeResult result;

   ZeroMemory(request);

   ZeroMemory(result);

   datetime expiration = TimeCurrent()+PeriodSeconds(PERIOD_M30); 


   request.symbol       = Symbol();

   request.volume       = Lots;

   request.stoplimit    = 0;

   request.sl           = 0;

   request.tp           = 0;

   request.type_filling = ORDER_FILLING_FOK;

   request.type_time    = ORDER_TIME_SPECIFIED;

   request.expiration = expiration;

   request.type=ORDER_TYPE_BUY_STOP;

   request.price=myprice;

   request.tp=mytp;

   dummy = OrderSend(request, result);


Stanislav Korotky
16371
Stanislav Korotky 2014.08.29 14:36  
You did not specify an action for the request. Should be  TRADE_ACTION_PENDING.
Aecio de Feo Flora Neto
3507
Aecio de Feo Flora Neto 2014.08.29 18:20  
marketeer:
You did not specify an action for the request. Should be  TRADE_ACTION_PENDING.

My mistake: the action is there indeed.

Here goes the full code again below.

 

    MqlTradeRequest request;

   MqlTradeResult result;

   ZeroMemory(request);

   ZeroMemory(result);

   datetime expiration = TimeCurrent()+PeriodSeconds(PERIOD_M30); 

   request.symbol       = Symbol();

   request.volume       = Lots;

   request.stoplimit    = 0;

   request.sl           = 0;

   request.tp           = 0;

   request.type_filling = ORDER_FILLING_FOK;

   request.type_time    = ORDER_TIME_SPECIFIED;

   request.expiration = expiration;

   request.action=TRADE_ACTION_PENDING; 

   request.type=ORDER_TYPE_BUY_STOP;

   request.price=myprice;

   request.tp=mytp;

   dummy = OrderSend(request, result); 
Alain Verleyen
Moderator
28518
Alain Verleyen 2014.08.29 20:07  

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.


Alain Verleyen
Moderator
28518
Alain Verleyen 2014.08.29 20:15  
aecioneto:

My mistake: the action is there indeed.

Here goes the full code again below.

 

Did you check that ORDER_TIME_SPECIFIED is allowed for the symbol you trade ?
Aecio de Feo Flora Neto
3507
Aecio de Feo Flora Neto 2014.08.29 21:07  
angevoyageur:
Did you check that ORDER_TIME_SPECIFIED is allowed for the symbol you trade ?

Many thanks, I did not know this!

I should use the code to verify this in the expert code, right? 

Alain Verleyen
Moderator
28518
Alain Verleyen 2014.08.29 23:19  
aecioneto:

Many thanks, I did not know this!

I should use the code to verify this in the expert code, right? 

Yes, it's broker/symbol dependent. It's probably your problem, please report here when you will check.
Aecio de Feo Flora Neto
3507
Aecio de Feo Flora Neto 2014.08.29 23:53  
angevoyageur:
Yes, it's broker/symbol dependent. It's probably your problem, please report here when you will check.

Just to complete my understanding on this: I can use the mouse to manually create a pending order, buy/sell stop.

Doing the same via EA is a different thing? 

Alain Verleyen
Moderator
28518
Alain Verleyen 2014.08.30 01:45  
aecioneto:

Just to complete my understanding on this: I can use the mouse to manually create a pending order, buy/sell stop.

Doing the same via EA is a different thing? 

I don't think so. What I wrote is only a suggestion, please try it and report the result.
Aecio de Feo Flora Neto
3507
Aecio de Feo Flora Neto 2014.08.30 14:38  
angevoyageur:
I don't think so. What I wrote is only a suggestion, please try it and report the result.

Just did tests and results were key!!

Only SYMBOL_EXPIRATION_DAY is allowed. I changed code to only use it with BUY_LIMIT and SELL_LIMIT orders and now orders are routing throught.

Infinite thanks, man! 

/
To add comments, please log in or register