Hi, experts
New to mql5 scripting here. I come across this issue where pending order keep on activated because I cannot seem to stop it using OrdersTotal() function.
The script should be, pending order can only open 1 at a time. It would be nice to have workaround for this issue.
Thanks,
Amir H
Show your MQL5 code, please.
My mistake here is the code
#include <Trade\Trade.mqh> CTrade trade; input double lotSize=0.1; input int StopLoss=150; input int TakeProfit=100; input string StartTradingTime="02:00"; input string StopTradingTime="05:00"; string CurrentTime; bool TradingIsAllowed=false; double Resistance=99999; void OnTick() { //initialize time datetime time=TimeTradeServer(); CurrentTime=TimeToString(time,TIME_MINUTES); //initialize Close & Open double close[]; ArraySetAsSeries(close,true); CopyClose(_Symbol,_Period,0,3,close); double open[]; ArraySetAsSeries(open,true); CopyOpen(_Symbol,_Period,0,3,open); //Detect resistance if(close[1]<close[2] && open[1]>open[2]) { Resistance=close[2]; } //Trade if(CheckTradingTime()==true) if(close[1] > Resistance && OrdersTotal()==0)//Breakout with no pending order open { trade.SellStop(lotSize,Resistance,_Symbol,Resistance+StopLoss*_Point,Resistance-TakeProfit*_Point,ORDER_TIME_GTC,0,NULL); } } bool CheckTradingTime() { if (StringSubstr(CurrentTime,0,5)==StartTradingTime) TradingIsAllowed=true; if (StringSubstr(CurrentTime,0,5)==StopTradingTime) TradingIsAllowed=false; return TradingIsAllowed; }
I confirm. After a while, OrdersTotal stops seeing pending orders!!!
MetaTrader 5 x64 build 3333 started for MetaQuotes Software Corp. Windows 11 build 22621, 12 x Intel Core i7-9750H @ 2.60GHz, 23 / 31 Gb memory, 706 / 946 Gb disk, UAC, GMT+2 C:\Users\barab\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075
This exactly what happened through the tester which the code only work until the 5th order.
May I ask is there another workaround to disable any pending order to activate when there is already a pending order?
This exactly what happened through the tester which the code only work until the 5th order.
May I ask is there another workaround to disable any pending order to activate when there is already a pending order?
There is no workaround as the 'OrdersTotal' system function is broken :(
For Future Readers, This code is flawed. too many order makes the OrdersTotal() overwhelmed. I found another workaround.
Sincerely,
M Amir
For Future Readers, This code is flawed. too many order makes the OrdersTotal() overwhelmed. I found another workaround.
Sincerely,
M Amir
Are you not going to share this "workaround"?
//Trade Time:Sell stop when breakout happen if(TimeCheck()==true && close[1] > Resistance && OrdersTotal()==0 && TradeCounter<1) { trade.SellStop(lotSize,Resistance,_Symbol,Resistance+StopLoss*_Point,Resistance-TakeProfit*_Point,ORDER_TIME_DAY,0,NULL); TradeCounter=TradeCounter+1; } //No Trade Time : Reset Parameter & Close Order if ( TimeCheck() == false ) { Resistance=99999; ulong order_ticket=OrderGetTicket(0); trade.OrderDelete(order_ticket); TradeCounter=0; }
Build 3335 is out - looks like the bug with 'OrdersTotal' has been fixed.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, experts
New to mql5 scripting here. I come across this issue where pending order keep on activated because I cannot seem to stop it using OrdersTotal() function.
The script should be, pending order can only open 1 at a time. It would be nice to have workaround for this issue.
Thanks,
Amir H