RetCode: 10021

 
Hi

this is a snippet, executed on ChartEvent click event :
double SL_price=0, TP_price=0;
bool SL_retrieved = ObjectGetDouble(0, "UTA_SL_LINE", OBJPROP_PRICE, 0, SL_price);
bool TP_retrieved = ObjectGetDouble(0, "UTA_TP_LINE", OBJPROP_PRICE, 0, TP_price);
if(SL_retrieved && TP_retrieved)
{
        MqlTradeRequest OS_req;
        MqlTradeResult OS_res;
        ZeroMemory(OS_req);
        ZeroMemory(OS_res);
        OS_req.symbol           = _Symbol;
        OS_req.type_filling     = Sym_Filling;
        OS_req.magic            = INPUT_MAGIC;
        OS_req.deviation        = INPUT_DEV;
        OS_req.action           = TRADE_ACTION_DEAL;
        OS_req.volume           = INPUT_VOL;
        OS_req.type             = (SL_price<TP_price)? ORDER_TYPE_BUY : ORDER_TYPE_SELL;
        OS_req.price            = (SL_price<TP_price)? SymbolInfoDouble(_Symbol, SYMBOL_ASK) : SymbolInfoDouble(_Symbol, SYMBOL_BID);
        OS_req.sl               = SL_price;
        OS_req.tp               = TP_price;
        OS_req.comment          = INPUT_COMMENT;
        if(!OrderSend(OS_req, OS_res)) Print("Error : ", OS_res.retcode);       // prints 10021 sometimes
        else if(OS_res.retcode!=10009) Print("Porition opened successfully. (ret_code=",OS_res.retcode,")");
}
else Print("Error occurred retrieving SL,TP prices.");
on some clicks on the object, it prints 10021, sometimes it opens the trade without problem.
the TP and SL HLINE objects, are verified to be valid, before this snippet is executed.
(they are out of symbol freeze range, and are OK to be used as stop prices. because on some clicks, they open the desired trade.)

what causes a server to return 10021 error code ?
 

Please declare and initialize the trade request.

//--- declare and initialize the trade request and result of trade request
   MqlTradeRequest request={0};
   MqlTradeResult  result={0};
 
Marco vd Heijden:

Please declare and initialize the trade request.

ZeroMemory() won't do that ?

the strange thing is, I don't always get this error, just sometimes.
this code is executed on click event, even when the SL and TP objects lines are NOT moved, I get thetrade done successfully, and sometimes it gets the 10021 error.

I think it's safe to assume it's a server issue , right ?
 

I would think so too but you can try mqltick in stead of SymbolInfo because it is a lot faster.

Or alternatively you could analyze Bid and Ask before like you did with those other values..

Reason: