Show your code.
/* there are different arrays where all details for the trades are stored in: int trade_status[50]; // 0=empty ; 1=ready for ordersend ; 2=order is in the market ; 3=order has closed string trade_symbol[50]; // symbol int trade_tf[50]; // timeframe DIRECTION trade_dir[50]; // UP, DOWN double trade_price[50]; double trade_amount[50]; datetime trade_signaltime[50]; // when the trade entry was calculated datetime trade_starttime[50]; // entry time datetime trade_expiretime[50]; // expire time int trade_ticket[50]; int trade_magicnr[50]; int trade_ordertry[50]; // counter for the tries, how often ordersend() was called unsuccessfully */ void ORDER_orders_from_tradearray () { int ticket = 0; int order_type = 0; // go through all trades for (int i=0 ; i<trade_array_size ; i++) { bool time_over = TimeCurrent()>trade_starttime[i] + timeout_in_sec ; ticket = 0; // if trade is ready for ordersend and starttime has come if (trade_status[i]==1 && trade_starttime[i] <= TimeCurrent() ) { // check before ordersend if ( !time_over && !IsTesting() && (!IsExpertEnabled() || !IsConnected() || IsTradeContextBusy() || !IsTradeAllowed()) ) { FileWrite(filehandle,LOG_time_format(),"|",trade_symbol[i],"M"+string(trade_tf[i]),i,""," ORDER WAIT ... because of '!IsExpertEnabled() OR !IsConnected() OR IsTradeContextBusy() OR !IsTradeAllowed()' " ); continue; } if (trade_dir[i]==UP ) order_type= OP_BUY; if (trade_dir[i]==DOWN) order_type= OP_SELL; double amount = int ( trade_amount[i] ); FileWrite(filehandle,LOG_time_format(),"|",trade_symbol[i],"M"+string(trade_tf[i]),i,""," timeover check - log the differences: (tradetime:"+string(trade_starttime[i])+", signaltime:"+string(trade_signaltime[i])+")"); if ( !time_over ) { ticket = OrderSend(trade_symbol[i],order_type,amount,iClose(trade_symbol[i],trade_tf[i],0),0,0,0,"BO exp:"+IntegerToString(trade_ablauf_in_sec[i]),trade_magicnr[i],0,clrWhite); } // analyse ordersend() return if (ticket>0) { if ( OrderSelect(ticket,SELECT_BY_TICKET) ) { // store order details in the trade..[] arrays trade_ticket[i] = ticket; trade_starttime[i] = OrderOpenTime(); trade_expiretime[i] = trade_starttime[i] + expire_time; trade_price[i] = OrderOpenPrice(); } FileWrite(filehandle,LOG_time_format(),"|",trade_symbol[i],"M"+string(trade_tf[i]),i,"&"," ORDER NEW from trade","amount:", DoubleToStr(amount,2), "ticket:",ticket,"trade_dir:",trade_dir[i],"signal_time:",trade_signaltime[i],"orderCloseTime:",trade_expiretime[i], "orderOpenPrice:",trade_price[i], "broker-order-open-time:", TimeToStr(trade_starttime[i],TIME_DATE|TIME_SECONDS) ); trade_status[i]=2; // 2 means trade is in the market, success } else { // check GetLastError() ERROR_check4error_output_to_logfile(); trade_ordertry[i]++; // max 10 tries or timeover if (trade_ordertry[i] >= 10 || time_over ) { FileWrite(filehandle,LOG_time_format(),"|",trade_symbol[i],"M"+string(trade_tf[i]),i,""," TimeOver or ToManyTries" ); trade_status[i]=0; // 0 means the array-item with index "i" is empty } else { FileWrite(filehandle,LOG_time_format(),"|",trade_symbol[i],"M"+string(trade_tf[i]),i,"."," ORDER - TRY #",trade_ordertry[i], "amount:",DoubleToStr(trade_amount[i],2),"trade_dir:",trade_dir[i]); } } } } }hello Alain, here's the code. this function is called by OnTick() or OnTimer() and its the only function that calls OrderSend()
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
before I call OrderSend() I check the following conditions:
The point is, that in the logfile very often there's just one try. So it looks like the OrderSend() returned a ticked at its first call. But when i look at the journal there are more OrderSend() calls listed with "Trade context is busy". How can that be?
Here the journal:
how can i fix that?