Saturday, 9 February 2013

Close All Orders This Symbol Only MQL4 Script for Metatrader

If you trade like me, sometimes you just need to exit a particular forex pair, and quickly! This script will do that for a single currency chart. Simply double click the script from the navigator pane after copying into the correct folder, and the selected chart's open trades should all be closed.

CloseAll_ThisSymbol.mq4 is a MQL4 script for closing all orders for a single forex symbol. The code is explained in greater detail in the MQL4 code tutorial titled, "How To Write a Close All Script in MQL4?" If you have questions about the MQL4 code, please refer to that document. 

Default values for slippage and magic number have been placed in the script as follows:

// 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. 

The default value for MagicNumber is -1. This value indicates that magic number should not be used to limit the trades that should be closed for this fx symbol. In other words, when MagicNumber equals -1, all open trades for the currently selected chart will be closed. Change MagicNumber to the desired number if you wish to only close out certain trades that use the magic number tag.

How to use CloseAll_ThisSymbol MQL4

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_ThisSymbol 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 trades on the currently selected chart 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.

Updated 12/1/2012 to make script compatible with FIFO order exit rule.

1 comment:

  1. Hey Everybody,

    Below is a list of the most recommended FOREX brokers:
    1. Most Recommended Forex Broker
    2. eToro - $50 minimum deposit.

    Here is a list of money making forex instruments:
    1. ForexTrendy - Recommended Odds Software.
    2. EA Builder - Custom Indicators Autotrading.
    3. Fast FX Profit - Secret Forex Strategy.

    Hopefully these lists are benificial to you.

    ReplyDelete