⋮ // Close Order if (SlowMovingAverage > FastMovingAverage) OrderClose(OrderOpenID, LotSize, Ask,0,clrRed); } // This bracket terminates OnTick. Lines below are outside of any function. if (SlowMovingAverage < FastMovingAverage) { OrderClose(int OrderOpenID, LotSize, Bid, 0, clrBlue); }Like wise
bool CheckIfOpenOrdersByMagicNB(int MagicNB) { int openOrders = OrdersTotal(); for (int i = 0; i<OrdersTotal(); i++) if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==True) { if (OrderMagicNumber() == MagicNumber) { return true; } } } // This braket terminates CheckIfOpenOrdersByMagicNB. Everything below is outside of any function. return false; }
for (int i = OrdersTotal()-1; i>=0 && !_StopFlag; i--)
- Op's problem is a compilation problem.
- #2 is your first post in this thread. You didn't tell him anything before.
- The function returns true if an order exists with the magic number. Counting down or counting up makes no difference.
- Op's problem is a compilation problem.
- #2 is your first post in this thread. You didn't tell him anything before.
- The function returns true if an order exists with the magic number. Counting down or counting up makes no difference.
Dominik Christian Egert #:
If any of the orders disappears while looping through, you get to skip one, right?
-
Orders do not "disappear" unless you delay the loop with server calls/sleep.
-
In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading), while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing and order count:
-
For non-FIFO (non-US brokers), (or the EA only opens one order per symbol), you can simply count down, in an index loop, and you won't miss orders. Get in the habit of always counting down.
Loops and Closing or Deleting Orders - MQL4 programming forum -
For In First Out (FIFO rules — US brokers), and you (potentially) process multiple orders per symbol, you must find the earliest order (count up), close it, and on a successful operation, reprocess all positions (from zero).
CloseOrders by FIFO Rules - Strategy Tester - MQL4 programming forum - Page 2 #16
MetaTrader 5 platform beta build 2155: MQL5 scope, global Strategy Tester and built-in Virtual Hosting updates - Best Expert Advisors - General - MQL5 programming forum #1.11 -
and check OrderSelect in case later positions were deleted.
What are Function return values ? How do I use them ? - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles -
and if you (potentially) process multiple orders, must call RefreshRates() after server calls if you want to use, on the next order / server call, the Predefined Variables (Bid/Ask.) Or instead, be direction independent and just use OrderClosePrice().
-
-
Orders do not "disappear" unless you delay the loop with server calls/sleep.
-
In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading), while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing and order count:
-
For non-FIFO (non-US brokers), (or the EA only opens one order per symbol), you can simply count down, in an index loop, and you won't miss orders. Get in the habit of always counting down.
Loops and Closing or Deleting Orders - MQL4 programming forum -
For In First Out (FIFO rules — US brokers), and you (potentially) process multiple orders per symbol, you must find the earliest order (count up), close it, and on a successful operation, reprocess all positions (from zero).
CloseOrders by FIFO Rules - Strategy Tester - MQL4 programming forum - Page 2 #16
MetaTrader 5 platform beta build 2155: MQL5 scope, global Strategy Tester and built-in Virtual Hosting updates - Best Expert Advisors - General - MQL5 programming forum #1.11 -
and check OrderSelect in case later positions were deleted.
What are Function return values ? How do I use them ? - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles -
and if you (potentially) process multiple orders, must call RefreshRates() after server calls if you want to use, on the next order / server call, the Predefined Variables (Bid/Ask.) Or instead, be direction independent and just use OrderClosePrice().
-
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use