trailing_Alligator
Download scriptThis automated trading tool is designed to manage and monitor active market positions by interacting with a specific technical indicator known as the "Alligator." Rather than manually watching every price movement, this script acts as an automated supervisor that executes exit commands based on predefined price boundaries.
Core Functionality
The primary purpose of this script is to identify optimal moments to close open trades (both Buy and Sell orders) by comparing the current market price against specific "color" lines generated by the Alligator indicator.
How the Logic Works:
- Dynamic Monitoring: The script continuously scans all currently open trades on your trading account. It specifically looks for positions that match the current currency pair you are viewing.
- The Trigger Mechanism: The tool uses two distinct components of the Alligator indicator—referred to as "Teeth" and "Lips." Depending on your preference, you can choose which of these lines will act as your exit signal (Red or Green).
- Smart Exit Rules:
- For Buy Positions: If the market price drops below the designated control line, the script automatically closes the trade.
- For Sell Positions: If the market price rises above the designated control line, the script automatically closes the trade.
- Real-Time Reporting: The tool provides a live visual dashboard on your trading screen. This includes:
- The current total profit of all active trades.
- The specific profit/loss for the individual currency pair being monitored.
- A status message confirming which control settings are currently active.
Notifications and Feedback
Once all trades have been closed by the script, it provides a clear summary alert on your screen, displaying the final result of the trading session. This ensures that you are always informed of the performance of the automated logic without needing to manually calculate gains or losses.
In essence, this tool automates the "exit strategy" phase of trading, ensuring that positions are closed systematically as soon as the market hits specific technical thresholds defined by the Alligator indicator.
//+------------------------------------------------------------------+
//| traling_Alligator.mq4 |
//| Copyright © 2009, Fibook.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Fibook.ru"
#property link "http://www.fibook.ru"
extern int ControlBar = 1, // Bar closes control
PeriodControl = 60; // Period Control
extern string CCC = "0-Control Green, 1-Control Red";
extern int CloseColorControl = 1; // Line Control
double profit,result;
string Line;
int init()
{
result = 0;
// Comment ("");
return(0);
}
int start()
{
if (IsExpertEnabled())
{
Sleep (50);
RefreshRates();
for (int i=OrdersTotal();i>=1;i--)
{
OrderSelect (i-1,SELECT_BY_POS,MODE_TRADES);
{
if (OrderType()==OP_BUY && Symbol() == OrderSymbol())
{
double price = MarketInfo (OrderSymbol(),MODE_BID);
if (Close [ControlBar] < ColorControl (OrderSymbol()))
OrderClose (OrderTicket(),OrderLots(),price,3,0);
result = OrderProfit()+result;
}
if (OrderType()==OP_SELL && Symbol() == OrderSymbol())
{
price = MarketInfo (OrderSymbol(),MODE_ASK);
if (Close [ControlBar] > ColorControl (OrderSymbol()))
OrderClose (OrderTicket(),OrderLots(),price,3,0);
result = OrderProfit()+result;
}
}
}
for (i=OrdersTotal();i>=1;i--)
{
OrderSelect(i-1,SELECT_BY_POS,MODE_TRADES);
profit = OrderProfit()+OrderSwap()+profit;
}
for (i=OrdersTotal();i>=1;i--)
{
OrderSelect(i-1,SELECT_BY_POS,MODE_TRADES);
if (OrdersTotal()!=0 && Symbol() == OrderSymbol())
Comment ("Traling on Alligator. Bar Control - ",ControlBar,". Line control - ",Line," ",ColorControl (OrderSymbol()),"\n",
"Total profit ", profit,"\n",
"Profit ",OrderSymbol(), " ",OrderProfit() + OrderSwap());
}
if (OrdersTotal()==0 && Symbol() == OrderSymbol())
{
Alert ("EA closes deal on the Alligator with result ", result);
result = 0;
}
profit =0;
}
//----
return(0);
}
//+------------------------------------------------------------------+
// Ðàññ÷åò Àëëèãàòîðà
//+------------------------------------------------------------------+
double ColorControl (string OS)
{
double AlligatorRed = NormalizeDouble(iAlligator(OS, PeriodControl, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORTEETH, ControlBar),Digits);
double AlligatorGreen = NormalizeDouble(iAlligator(OS, PeriodControl, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORLIPS, ControlBar),Digits);
if (CloseColorControl == 0) {Line = "Green"; return (AlligatorGreen);}
if (CloseColorControl == 1) {Line = "Red"; return (AlligatorRed);}
}
Comments