Wipeout
Download scriptThis script is an automated trading tool designed to act as a safety net for your trading account. Its primary purpose is to monitor your total account performance and automatically clear all active positions once a specific profit goal is reached.
How the System Works
1. Continuous Monitoring
The tool constantly scans your account in real-time. It calculates your current floating profit by comparing your total account equity (the value of your assets plus open trades) against your account balance (the amount of capital deposited or held).
2. Profit Target Detection
You can set a specific monetary target through the settings. Once the script detects that your current floating profit has met or exceeded this pre-defined amount, it triggers its main action sequence.
3. Automated Order Liquidation
If the profit goal is reached and there are any open trades currently running on your account, the script systematically goes through every single one of them. It identifies whether each trade is a "Buy" or a "Sell" and executes an immediate closing command for each. This effectively "wipes out" all active positions, locking in your gains instantly.
4. Precision and Error Handling
The logic includes several underlying mechanics to ensure smooth execution:
- Price Accuracy: It automatically detects the decimal precision of the currency pair to ensure that prices are handled correctly during the closing process.
- Slippage Management: It accounts for market fluctuations (slippage) to ensure that even in a fast-moving market, the trades are closed as close to your desired price as possible.
- Stability Measures: If the trading platform experiences a momentary delay or becomes "busy" while trying to close a trade, the script is designed to recognize this, wait for a fraction of a second, and retry the action until it succeeds.
Summary of Behavior
Think of this tool as an automated "Take Profit" button for your entire account. Instead of you having to manually monitor every individual trade to see when you've made enough money, this script watches the big picture and shuts everything down the moment your total profit reaches your target.
//+------------------------------------------------------------------+
//| Wipeout.mq4 |
//| Copyright © 2011, www.FxAutomated.com |
//| http://www.FxAutomated.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, www.FxAutomated.com"
#property link "http://www.FxAutomated.com"
//---- input parameters
extern string Product="Wipeout v1";
extern double CloseAllWhenProfitIs=300;
extern int Slippage=5;
extern string MoreAvailableAt="www.FxAutomated.com";
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int start()
{
//----
int StopMultd;
int digits=MarketInfo("EURUSD",MODE_DIGITS);
if(digits==5){StopMultd=10;} else{StopMultd=1;}
int Slip=Slippage*StopMultd;
double CurrentProfit=NormalizeDouble(AccountEquity()-AccountBalance(),Digits);
if(CurrentProfit>=CloseAllWhenProfitIs){ // start check
if(OrdersTotal()>0){
for(int i=1; i<=OrdersTotal(); i++) // Cycle searching in orders
{
if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
{
if(OrderType()==OP_BUY){OrderClose(OrderTicket(),OrderLots(),Bid,Slip,CLR_NONE);}
if(OrderType()==OP_SELL){OrderClose(OrderTicket(),OrderLots(),Ask,Slip,CLR_NONE);}
int Error=GetLastError();
if(Error>0){
if(Error==2){Alert("Common error.");}
if(Error==146){Alert("Trading subsystem is busy. Retrying."); Sleep(500); RefreshRates();}
}
}
}
}
}// start check
//----
return(0);
}
//+------------------------------------------------------------------+
Comments