• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 2:05am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 2:05am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

EA to manage manually set pending orders 1 reply

Free trading simulator where I can place orders manually? 2 replies

Closing orders script by comment phrase 1 reply

Script: Closing All Orders 8 replies

Is there a mt script for manually putting on an order? 0 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
Tags: MT4: closing orders manually vs script
Cancel

MT4: closing orders manually vs script

  • Post #1
  • Quote
  • First Post: May 15, 2012 12:52pm May 15, 2012 12:52pm
  •  MT4Coder
  • | Joined Apr 2012 | Status: Member | 29 Posts
Can someone offer an explanation as to why I sometimes get errors (like 146) when using a "close all orders" script yet if I immediately try to close the orders manually there's no problem.

The script is not at fault, it's a well known script called "close-all-orders.mq4" which may be familiar to many, the issue seems to be related to how MT4 handles manual closures as opposed to those initiated by a script.

I'm not familiar with the internal workings of MT4 and would like to understand exactly what's going on here, so any help would be appreciated...
  • Post #2
  • Quote
  • Edited 2:31pm May 15, 2012 2:21pm | Edited 2:31pm
  •  CodeMeister
  • Joined Sep 2009 | Status: Making Code While Making Pips | 1,672 Posts
Error 146 is trade context busy which means that the MT4 trading thread on your machine is performing another trade operation. This problem would only come up in scripts or EAs which try to do too much to soon. The MT4 terminal has code to prevent from happening - in other words you can't close another order if the previous one is still being handled. EAs and scripts can avoid this error by using the IsTradeContextBusy() and Wait() functions. If you are not up to coding, just run the script repeatedly until all orders are closed.

You can't assume that because a script is well known and widely used that it was written properly or that you have the latest version.
 
 
  • Post #3
  • Quote
  • May 16, 2012 3:44pm May 16, 2012 3:44pm
  •  MT4Coder
  • | Joined Apr 2012 | Status: Member | 29 Posts
Thank you for your advice, but I'm fully versed in everything from assembly to C++ (I put MQL somewhere in the middle) and I know what I'm doing in that regard. I've looked at the code in the script and I know exactly what it does.

My post clearly wasn't detailed enough so let me clarify. This is not an issue with the script I'm using, it's an internal issue within MT4 which happens *sometimes*, not every time. For example:

1) I open a few positions.

2) I apply the "close all" script.

3) Given that the MT4 terminal is not doing anything else at this time it should close all orders unless, as you said, the trade context is busy.

4) Nothing happens, I assume trade context is busy.

5) I try to close one order manually - it closes immediately.

6) I wait for the script to close the remaining orders - I know the trade context is not busy as I've just closed an order, but nothing happens.

7) I manually close another order - it closes immediately.

8) I wait for the script to close the rest - still nothing happens.

Now this has happened many times and I'd like to know why I can close orders manually when the script can't, it's not a trade context issue.
 
 
  • Post #4
  • Quote
  • Last Post: May 16, 2012 6:42pm May 16, 2012 6:42pm
  •  fxtr51
  • Joined Jan 2010 | Status: Member | 1,163 Posts
Quoting MT4Coder
Disliked
Thank you for your advice, but I'm fully versed in everything from assembly to C++ (I put MQL somewhere in the middle) and I know what I'm doing in that regard. I've looked at the code in the script and I know exactly what it does.

My post clearly wasn't detailed enough so let me clarify. This is not an issue with the script I'm using, it's an internal issue within MT4 which happens *sometimes*, not every time. For example:

1) I open a few positions.

2) I apply the "close all" script.

3) Given that the MT4 terminal is not doing anything...
Ignored
I had the same thing happen in live trading on Mt4 and I have no explanation for it.

Sometimes I thought that maybe the script had just stopped although there were still open orders, but I am not sure.
Closing the orders manually worked as you described it.

But sometimes even closing them manually did not work because
I got the "trade context is busy" message and then
only shutting down Mt4 and restarting it cleared the way to
close the open orders.
 
 
  • Platform Tech
  • /
  • MT4: closing orders manually vs script
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023