Close All Open Orders Script All Symbols in Profit

There are times when having the quick ability to double click a script to close out all profitable trades on an account or on a given magic number comes in handy. Whether you are taking a large or small profit, the CloseAll_AllSymbols_Profit MQL4 script for Metatrader belongs in every forex trader's arsenal of tools. Simply double click the script from the Navigator pane after copying it into the correct folder, and all open profitable trades (open orders) should be closed for the magic number selected. The default value is to close all trades for all magic numbers (MagicNumber = -1).

CloseAll_AllSymbols_Profit MQL4 is a Metatrader 4 Script that searches through an account and closes out all open trades that match the selected magic number. By default all profitable trades are closed so this makes a handy way to exit the market and take that profit in a flash. The script contains default values that will execute unless you manually edit the code from within the MetaEditor.

// when MagicNumber = -1 then close all magic numbers
extern int MagicNumber = -1;
// pips of slippage to allow
extern int Slippage = 7; 

If you wish to change the maximum allowance for slippage, you must change the value in the code prior to executing the script on your chart. Right-click on the navigator pane while selecting the script's name, and choose Modify. This should open up the MetaEditor and load the script into memory. Change the value as desired, then click the "Compile" button at the top of the MetaEditor.

How to use CloseAll_AllSymbols.mq4

Download the file below and copy it into your "..\experts\scripts" folder. After restarting Metatrader 4 so that it has a chance to compile and find the script and place it in the Navigator pane. You should see the script CloseAll_AllSymbols_Profit listed under "Scripts" if you copied the file into the right location, and restarted your Metatrader. Be careful because when you double click the MT4 script all profitable trades on ALL selected charts should close immediately!

You may post this MT4 script to other sites, but if you do, you must post a link to this page directly and you may not sell it or the source code. You are otherwise free to copy, use and distribute this MQL4 script for non-commercial use.

Note: updated 11/11/2011 to eliminate a small bug that prevented the script from unloading correctly, and reworked the for loop direction to take all fill possibilities into account.

Follow patrickmwhite on Twitter

For updates