Download MetaTrader 5

OrderSend

To add comments, please log in or register
Any problems with the code? Find solution in documentation!
abhamid
10
abhamid 2014.12.31 02:14 

Hi,

 I create an EA and i use Strategy tester to test it. 

 I use Alpari Demo account.

Unfortunately, when i want send order, i recieve an error "invalid request 10013", but when i run EA manually, a same order is sent, without error  "Request completed 10009". 

Please help.

hereafter, the send order function

 bool trade_cl::open_posi()

  {

     MqlTradeRequest  request={0};      // query structure

     MqlTradeResult   result ;

     MqlTradeCheckResult   result1;

     

     PrintFormat(" open_posi- Signal_act 0/1/2: %d", signal_act);

     if (signal_act==0)

     {

       return(true);

     }    

     request.magic=order_magic;

     request.action=TRADE_ACTION_DEAL;

     request.symbol=symbol;

     request.deviation= 1 * _Point;

     request.volume=volume;

     request.stoplimit=2.6;

     request.type_filling=ORDER_FILLING_IOC;

//    signal_act=2;

     if (signal_act==2)

     {

      request.type=ORDER_TYPE_BUY;

      request.price=SymbolInfoDouble(symbol,SYMBOL_ASK);;

     }

     if (signal_act==1)

     {

      request.type=ORDER_TYPE_SELL;

      request.price=SymbolInfoDouble(symbol,SYMBOL_BID);

      //verifier s'il y a une position ouverte sur ce symbol

      if (!PositionSelect(  symbol))

        {

        PrintFormat("verification de position opened the symbol %s, error code %d",

                  symbol,GetLastError());

              return(false);

        }

     }

     request.sl=request.price - stoploss*_Point;

     request.tp=request.price + takepro*_Point;

     if ( !OrderCheck(request,result1))

     {

      string texte=" resultat order, balance : " + DoubleToString(result1.balance) +" equity : " + DoubleToString(result1.equity) + "profit : " + DoubleToString(result1.profit);

      ecrire_div(texte, "chkorder.txt", result1.retcode );

       

     }

    PrintFormat(" resultat ordercheck : %d", result1.retcode);

    if (!OrderSend(request,result))

     {

       string texte=" resultat order, price : " + DoubleToString(result.price) + " BID : " + DoubleToString(result.bid) + "Ask : " + DoubleToString(result.ask);

       ecrire_div(texte, "order.txt", result.retcode );

 

     }

    PrintFormat(" resultat ordersend : %d", result.retcode);

    return(true);

  }
Alain Verleyen
Moderator
30737
Alain Verleyen 2014.12.31 11:57  

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
30737
Alain Verleyen 2014.12.31 12:00  
abhamid:

Hi,

 I create an EA and i use Strategy tester to test it. 

 I use Alpari Demo account.

Unfortunately, when i want send order, i recieve an error "invalid request 10013", but when i run EA manually, a same order is sent, without error  "Request completed 10009". 

Please help.

hereafter, the send order function

Your SL/TP cannot be the same for BUY and SELL :

     request.sl=request.price - stoploss*_Point;

     request.tp=request.price + takepro*_Point;

This code is only valid for a BUY order. For a SELL tp should be lower than current price and sl higher.

abhamid
10
abhamid 2014.12.31 13:48  

HI angevoyageur,

     Thank you for your help, the order was sent successufly.

regards

Hamid 

To add comments, please log in or register