datetime EarliestSellTime = TimeCurrent(); int EarliestSellTicket = -1; for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) { if (!OrderSelect(pos, SELECT_BY_POS))return (-1); if (OrderOpenTime()>EarliestSellTime)
When will you ever get an OpenOrderTime in the future?if(OrderSelect(EarliestOpenBuyTicket(),SELECT_BY_POS,MODE_TRADES)){
The function returns a ticket number. Do you expect it to ever select by position?
whroeder1:
- When will you ever get an OpenOrderTime in the future?
- The function returns a ticket number. Do you expect it to ever select by position?
Thanks whroeder I should have noticed these issues but they escaped me due to being somewhat of a novice to MQL.
Its now selecting the order but instead its closing the entire basket. Is there something simple I am missing here?
Thanks for your support.
//--- if(ch_b!=0){ if(UseTrailing){Trailing();} if(Profit(OP_BUY)<AccountBalance()*(-max_dd/100)) while(ch_b!=0){CloseBuyOrders();ch_b = check(OP_BUY);} } //--- if(ch_s!=0){ if(UseTrailing){Trailing();} if(Profit(OP_SELL)<AccountBalance()*(-max_dd/100)) while(ch_s!=0){CloseSellOrders();ch_s = check(OP_SELL);} } // ----------------------------- // void CloseBuyOrders(){ if (OrderSelect(EarliestOpenBuyTicket(),SELECT_BY_TICKET)){ if (OrderClose(OrderTicket(),OrderLots(),Bid,3,clrNONE)) Alert("the order isn't close because Err no. ", GetLastError()); } } // ----------------------------- // void CloseSellOrders(){ if (OrderSelect(EarliestOpenSellTicket(),SELECT_BY_TICKET)){ if (OrderClose(OrderTicket(),OrderLots(),Ask,3,clrNONE)) Alert("the order isn't close because Err no. ", GetLastError()); } } // ----------------------------- // int EarliestOpenSellTicket(){ datetime CurrentTime=TimeCurrent(); int EarliestSellTicket = -1; for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) { if (!OrderSelect(pos,SELECT_BY_POS))return (-1); if (OrderSymbol()==Symbol()) if (OrderOpenTime()<CurrentTime) EarliestSellTicket = OrderTicket(); } return(EarliestSellTicket); } // ----------------------------- // int EarliestOpenBuyTicket(){ datetime CurrentTime=TimeCurrent(); int EarliestBuyTicket = -1; for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) { if (!OrderSelect(pos,SELECT_BY_POS))return (-1); if (OrderSymbol()==Symbol()) if (OrderOpenTime()<CurrentTime) EarliestBuyTicket = OrderTicket(); } return(EarliestBuyTicket); }
I have solved the issues.
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
I have an EA that enters in a pyramid type grid. When DD hits a certain percentage it closes the first order opened in the basket, I tried coding this but it just seems to hang the EA.
Can someone find the culprit in this code?
Thanks in advance.