trailing_Alligator





//+------------------------------------------------------------------+
//|                                            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);}
   }



Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:

Bill Williams Alligator


Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders


Other Features: