trailing_Alligator_v2
Download scriptThis automated trading tool is designed to manage open positions by monitoring specific technical indicators and price trends. It functions as a "trailing" management system, meaning it dynamically evaluates your active trades to determine the optimal moment to exit based on market behavior.
Core Monitoring Logic
The script primarily relies on two distinct methods to decide when a trade should be closed:
1. The Alligator Indicator System The tool utilizes the "Alligator" technical indicator, which consists of different moving averages (referred to as "teeth" and "lips"). Depending on your settings, the script focuses on one of these specific lines:
- Green Line Control: Uses the "Lips" of the Alligator.
- Red Line Control: Uses the "Teeth" of the Alligator.
The software constantly compares the current closing price of the market against these indicator lines. If the price crosses these levels in a specific direction (depending on whether you are in a Buy or Sell position), the script triggers an automatic exit to secure your trade.
2. Price Trend Analysis (Momentum) In addition to the Alligator indicator, the script can monitor "momentum" by analyzing the relationship between recent price bars. It looks for consistent trends:
- For potential exits in specific directions, it checks if the last five price bars are moving consistently upward or downward.
- If a clear, sequential trend is detected (e.g., each bar closing higher than the previous one), the script identifies this as a signal to manage the trade.
Operational Workflow
- Real-Time Monitoring: The script continuously scans all open positions on your specific trading symbol. It refreshes market data frequently to ensure it is reacting to the most current prices.
- Automated Execution: When either the Alligator indicator condition or the price trend condition is met, the script automatically executes a closing order for that position.
- Performance Tracking: The tool calculates the real-time profit and swap fees for your open positions. It provides an on-screen visual summary (a "Comment") that displays:
- The current total profit of the active trades.
- The specific profit for the individual symbol being monitored.
- The specific control settings currently in use (e.g., which Alligator line is being tracked).
- Trade Completion Alerts: Once a trade is successfully closed by the script, it calculates the final result and provides an alert notification to inform you of the final profit or loss.
User Experience
For the trader, this means the script acts as an automated "exit guard." Instead of needing to watch the charts constantly to see when a trend has exhausted itself, the script watches the Alligator indicators and price momentum for you, closing trades automatically when your predefined criteria are met.
//+------------------------------------------------------------------+
//| traling_Alligator_v2.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
extern bool ControlBar5 = true;
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())||
bar5 (OrderSymbol(),1)==true)
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())||
bar5 (OrderSymbol(),-1)==true)
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);}
}
bool bar5 (string OS, int t)
{if(ControlBar5 == true) return (false);
switch (t)
{
case 1:
{if (Close [1]>Close [2]&&
Close [2]>Close [3]&&
Close [3]>Close [4]&&
Close [4]>Close [5])return (true);
else return (false);}
case -1:
{if (Close [1]<Close [2]&&
Close [2]<Close [3]&&
Close [3]<Close [4]&&
Close [4]<Close [5])return (true);
else return (false);}
}
}
Comments