-
Play videoPlease edit your post.
For large amounts of code, attach it. - In the presence of multiple orders (one EA multiple charts, multiple EA's, manual trading) you must count down when closing/deleting/modifying in a position loop and check OrderSelect when dealing with multiple orders. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
-
You must RefreshRates after sleep and between multiple server calls if
you want to use the Predefined Variables (Bid/Ask) or
OrderClosePrice() instead.
- Check your return codes and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Thanks WHRoader !!
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
Hi:
I wrote a script to close all orders at the same time. But I don't know why it closes orders one at a time. I need to run the script repeatedly in order to close all open orders. Does anyone know what I might have done wrong?
The script I wrote is as follows:
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link "http://www.mql4.com"
#property version "1.00"
#property strict
bool selectresult=false,closeresult=false,deleteresult=false;
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
for(int z=OrdersTotal()-1;z>=0;z--)
{
selectresult=OrderSelect(z,SELECT_BY_POS,MODE_TRADES);
if (OrderType()==OP_BUY) closeresult=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(), MODE_BID),10,clrNONE);
if (OrderType()==OP_SELL) closeresult=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(), MODE_ASK),10,clrNONE);
if (OrderType()==OP_BUYLIMIT ||
OrderType()==OP_BUYSTOP ||
OrderType()==OP_SELLLIMIT ||
OrderType()==OP_SELLSTOP) deleteresult=OrderDelete(OrderTicket());
}
}