Automated Equity Management Overview
The EqutyTrawlerXR_V00 is an automated trading assistant designed to monitor your trading account's performance in real-time. Rather than making decisions on when to enter a trade, this script acts as a protective layer that manages existing open positions based on your account's overall profit and equity.
Core Functionality
The primary logic of the script revolves around "Equity Tracking." It constantly scans your account to see if your current floating profit exceeds your actual balance (meaning you are currently in a winning position). Once a profitable state is detected, the script initiates a dynamic monitoring system.
Key Logic Components:
-
Dynamic Profit Scaling: The script uses a "step" system to evaluate your success. When your account enters a positive profit state, it measures that profit against a percentage of your total equity (which you can define in the settings). As your profits grow, the script internally increases its target threshold. This means the software "follows" your gains, aiming to lock in progress as the market moves in your favor.
-
Automatic Safety Exit: The most critical feature of this tool is its automated closing mechanism. If the market reverses and your current profit drops back down to the previous "step" level, the script identifies that the initial winning momentum has been lost. It will then automatically trigger a command to close all active trading positions simultaneously.
-
Continuous Monitoring: The tool operates on a continuous loop. It checks the status of your account at very frequent intervals (configurable by the user). This ensures that if a sudden market swing occurs, the script can react quickly to protect your gains before they turn into losses.
-
Execution Management: When the exit criteria are met, the script handles the technical heavy lifting of closing trades. It systematically identifies all open buy and sell orders and executes the necessary commands to exit them. It includes built-in "retry" logic, meaning if the market is too volatile to execute a close instantly, the script will wait for a clear window to ensure the trades are successfully finalized.
Summary for the User
Think of this script as a dynamic trailing stop for your entire account. Instead of setting a fixed profit target on every individual trade, this tool looks at the "big picture." It allows you to ride a winning streak as far as possible while providing an automated "emergency brake" that closes your positions if the profit starts to recede significantly from its peak.
//+------------------------------------------------------------------+
//| EqutyTrawlerXR_V00.mq4 |
//| Copyright © 2009, XrustSolution. |
//| http://www.xrust.ucoz.net |
//+------------------------------------------------------------------+
#property copyright "#Copyright © 2009, XrustSolution.#"
#property link "#http://www.xrust.ucoz.net#"
extern double EqutyPersent = 1;
extern double RepeatTimeinSec = 1;
//+------------------------------------------------------------------+
void start(){double step=1;
if(RepeatTimeinSec==0){RepeatTimeinSec=0.1;}
while(!IsStopped()&&IsExpertEnabled()){
Sleep(1000*RepeatTimeinSec);
if(AccountEquity()>AccountBalance()){
if(AccountProfit()>AccountEquity()/100*EqutyPersent*step){step++;}
if(step>1){
if(AccountProfit()<=AccountEquity()/100*EqutyPersent*(step-1)){
CloseAll();
}
}
}
}
return;}
//+------------------------------------------------------------------+
// Çàêðûâàåò âñå îðäåðà íà äàííîì èíñòðóìåíòå |
//+------------------------------------------------------------------+
void CloseAll(){
for(int n=OrdersTotal()+1;n>=0;n--){
if(OrderSelect(n,SELECT_BY_POS,MODE_TRADES)){
if(OrderType()<2){
del(OrderTicket());
}
}
}
return;
}
//+------------------------------------------------------------------+
//Óäàëÿåò ðûíî÷íûé îðäåð ñ óêàçàííûì åé òèêåòîì |
//+------------------------------------------------------------------+
void del(int ticket){int err;
for(int i=0;i<1;i++){
GetLastError();//îáíóëÿåì îøèêó
OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);
string symbol = OrderSymbol();
if(OrderType()==OP_BUY){RefreshRates();
double prise = MarketInfo(symbol,MODE_BID);
if(!OrderClose(ticket,OrderLots(),prise,3,Green)){err = GetLastError();}}
if(OrderType()==OP_SELL){RefreshRates();
prise = MarketInfo(symbol,MODE_ASK);
if(!OrderClose(ticket,OrderLots(),prise,3,Green)){err = GetLastError();}}
if(err == 0){PlaySound("expert.wav");break;}
if(err != 0){PlaySound("timeout.wav");Print("Error for Close Funtion =",err);}
while(!IsTradeAllowed()){Sleep(5000);}// åñëè ðûíîê çàíÿò òî ïîäîæäåì 5 ñåê
if (err==146) while (IsTradeContextBusy()) Sleep(1000*11);
}
}
Comments