0
votes

I'm beginner in MQL5. I am trying to create OrderSend expert.

I write this code :

int OnInit()
{
    MqlTradeRequest request ;
    MqlTradeResult result ;

    request.action = TRADE_ACTION_PENDING;
    request.type = ORDER_TYPE_BUY_LIMIT;
    request.symbol = _Symbol;
    request.volume = 100 ;

    request.price = 45400  ;
    request.sl = request.price - (request.price*0.1);
    request.tp = request.price + (request.price*0.2);
    request.expiration = D'2021.10.10 13:00:00';
    request.type_filling = ORDER_FILLING_RETURN ;

    OrderSend(request,result);

    return(INIT_SUCCEEDED);
}

But when run I am getting this expert error :

" 2021.10.01 00:00:00 failed buy limit 100 [my symbol] at 45400 sl: 40860 tp: 54480 [Invalid expiration]"

In Strategy Tester window I enter custom period from 2021.10.01 to 2021.10.20. I also tried my hard and select different date but not worked anything.

Any advise will be appreciated!

1

1 Answers

0
votes

The error message is very self-explaining. I think, your order is run after "2021.10.10 13:00:00" during the test process in startegy tester (as defined by "request.expiration").

As a solution, try to use "TimeCurrent()" function to get the current DataTime stamp and add your desired expiration period to it.

At least this modification will solve the logical bug in your "SendOrder()" function.