gail_2





//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
// original Free EA Grail_2.mq4 on http://articles.mql4.com/163
// cleaned ,fixed and translated by finimej
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
extern int TakeProfit=50;                                 // TakeProfit in pips
extern int StopLoss= 290;                                 // StopLoss in pips
extern int Distan   = 20;                                 // MA distans in pips
extern int Cls      = 20;                                 // Close at 2 pips profits
extern int period_MA=16;                                 // MA_period=16
extern int Time_1   = 0;                               // 
extern int Time_2   = 0;                               // 
extern int Prots    = 0;                                 // 

//--------------------------------------------------------------------------------------------
int
   Nom_bl,                                               // number of BuyLimit
   Nom_sl,                                               // number of SellLimit
   total,                                                // total OrderClose
   bl = 0,                                               // 1 = has BuyLimit
   sl = 0,                                               // 1 = has SellLimit
   b  = 0,                                               // 1 = has Buy
   s  = 0;                                               // 1 = has Sell 
//--------------------------------------------------------------------------------------------
double 
   OP,                                                   // OpenPrice 
   SL,                                                   // StopLoss   
   TP,                                                   // TakeProfit 
   Level,                                                // level 
   OP_bl,                                                // OpenPrice BuyLimit 
   OP_sl,                                                // OpenPrice SellLimit
   cls,                                                  // close at profits
   MA,                                                   // MA
   spred,                                                // spread
   dist,
   Lot;                                                  // Lot size 
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
int init()
   {   
   Level=MarketInfo(Symbol(),MODE_STOPLEVEL);            // get brokers stoploss level in pips
   if (Level==0) Level=5;                                //some broker has the stoploss = 0, set it to 5 to make the logic works
   Level=(Level+1)*Point;                                // :)
   SL=StopLoss*Point;                                    // StopLoss  
   TP=TakeProfit*Point;                                  // TakeProfit 
   dist=Distan*Point;                                    // distance from MA
   cls=Cls*Point;                                        // close at profits 
   spred=Ask-Bid;                                        // spread
   return;
   } 
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
int start()
   {   
//============================================================================================
   total=OrdersTotal();                                  // total OrderSelect
   bl=0;                                                 // initialize has buylimit orders
   sl=0;                                                 // initialize has buylimit orders
   b=0;                                                  // initialize has buy orders
   s=0;                                                  // initialize has sell orders
//--------------------------------------------------------------------------------------------
   for (int i=total; i>=0; i--)                          // go through the order loops
      {                                               
      if (OrderSelect(i,SELECT_BY_POS)==true &&         // select the orders
         OrderSymbol()==Symbol())
         {
      
//--------------------------------------------------------------------------------------------
         if (OrderType()==OP_BUY)                        // get the order Buy
            {
            b =1;                                        // set the system, has buy order
            Close_B(OrderTicket(),OrderLots());          // close the Buy order if it has 2 pips profits
            }
//--------------------------------------------------------------------------------------------
         if (OrderType()==OP_SELL)                        // get the order Sell
            {
            s =1;                                        // set the system, has sell order
            Close_S(OrderTicket(),OrderLots());          // close the sell order if it has 2 pips profits
            }
//--------------------------------------------------------------------------------------------
         if (OrderType()==OP_BUYLIMIT)                   // get the order BuyLimit
            {
            OP_bl=NormalizeDouble(OrderOpenPrice(),Digits);//OpenPrice BuyLimit
            Nom_bl=OrderTicket();
            bl=1;                                        // set the has buylimit orders
            }
//--------------------------------------------------------------------------------------------
         if (OrderType()==OP_SELLLIMIT)                  // get the order SellLimit
            {
            OP_sl=NormalizeDouble(OrderOpenPrice(),Digits);//OpenPrice SellLimit
            Nom_sl=OrderTicket();
            sl=1;                                        // set the has sellLimit orders
            }
//--------------------------------------------------------------------------------------------
         }
      }   
//--------------------------------------------------------------------------------------------
   MA = iMA(NULL,0, period_MA, 0,MODE_LWMA, PRICE_TYPICAL, 0);// get the current MA level, use line weighted MA, and use the typical price HLC/3
   Modify_order();                                       // move the limit orders along the MA line
   Open_order() ;                                        // open order 
//============================================================================================
   return;
   } 
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
void Close_B(int Nomber, double lots)                    // close order Buy
   {
//============================================================================================
   if (NormalizeDouble(Bid-OrderOpenPrice(),Digits)>=cls)// if order in profits 2 pips
      {
      OrderClose( Nomber, lots, Bid, 1, Yellow);         // close order
      b = 0;                                             // set the has buy order = 0
      }
//============================================================================================
   return;
   }
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
void Close_S(int Nomber, double lots)                    // close order Sell
   {
//============================================================================================
   if (NormalizeDouble(OrderOpenPrice()-Ask,Digits)>=cls)// if order in profits 2 pips
      {
      OrderClose( Nomber, lots, Ask, 1, Yellow);         // close order
      s = 0;                                             // set the has sell order = 0
      }
//============================================================================================
   return;
   }
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
void Modify_order()                                      //move the limit orders alone the line
   {
//============================================================================================
   if (bl==1)                                            // if has buylimit orders
      {
      OP=MA-dist;                                        // get the current buylimit openprice
      if (MathAbs(OP_bl-OP)>0.5*Point)                   // if old buylimit openprice diff than current buylimit openprice for half point
         {
         OrderModify(Nom_bl,OP,OP-SL,OP+TP,0,DeepSkyBlue);// modify the limit order alongs the side of MA line
         }
      }
//--------------------------------------------------------------------------------------------
   if (sl==1)                                            // if has selllimit orders
      {
      OP=MA+spred+dist;                                  // get the current selllimit openprice
      if (MathAbs(OP_sl-OP)>0.5*Point)                   // if old selllimit openprice diff than current selllimit openprice for half point
         {
         OrderModify( Nom_sl, OP, OP+SL, OP-TP, 0, Pink);// modify the limit order alongs the side of MA line
         }
      }
//============================================================================================
   return;
   }
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
void Open_order()                                        // send limit orders
   {
     int Tek_Time=TimeHour(CurTime());                   // if we use hours limit
     if (Tek_Time>Time_2 && Tek_Time<Time_1) return;     // EA then runs only from Time 1 to Time 2
//============================================================================================
   if (b==0 && bl==0)                                    // if we do not have any buylimit or buy orders
      {
      OP=MA-dist;                                        // get the current buylimit openprice     
      if(OP>Ask-Level) OP=Ask-Level;                     // if the Ask price hit the current buylimit openprice 
      OP=NormalizeDouble(OP,Digits);                     // normalize the computer double to nice normal mathmatical double 
      OrderSend(Symbol(),OP_BUYLIMIT, Lots(),OP,3,OP-SL,OP+TP,"",0,0,Blue);// send in order
      bl=1;                                              // set the has buylimit order = true
      }      
//--------------------------------------------------------------------------------------------
   if (s==0 && sl==0)                                    // if we do not have any selllimit or sellorders
      {
      OP=MA+spred+dist;                                  // get the current selllimit openprice   
      if(OP<Bid+Level) OP=Bid+Level;                     // if the bid price hit the current selllimit openprice 
      OP=NormalizeDouble(OP,Digits);                     // normalize the computer double to nice normal mathmatical double 
      OrderSend(Symbol(),OP_SELLLIMIT,Lots(),OP,3,OP+SL,OP-TP,"",0,0,Red);// send in order
      sl=1;                                              // set the has selllimit order = true
      }
///============================================================================================
   return;
   }
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ
double Lots()                                            // calculate the lot size
   {
//============================================================================================
   Lot=NormalizeDouble(AccountEquity()*Prots/100/1000,1);// calculate the lot size according to margin
   double Min_Lot = MarketInfo(Symbol(), MODE_MINLOT);   // get the broker minimum level of lot
   if (Lot == 0 ) Lot = Min_Lot;                         // if the calculated the lots less than the minimum lot, then take the minimumlot.
//============================================================================================
   return(Lot);
   }
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ





Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders

It Closes Orders by itself
It can change open orders parameters, due to possible stepping strategy
It automatically opens orders when conditions are reached

Other Features:

BackTest : EURUSD on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.41 Total Net Profit:-207.04

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.40 Total Net Profit:-106.88

BackTest : USDCHF on H1

From 2009-12-01 to 2010-01-01 Profit Factor:0.20 Total Net Profit:-183.26

BackTest : EURUSD on H1

From 2009-12-01 to 2010-01-17 Profit Factor:0.54 Total Net Profit:-234.68

BackTest : USDCAD on H1

From 2009-12-01 to 2010-01-01 Profit Factor:0.71 Total Net Profit:-61.58

BackTest : EURUSD on H1

From 2009-08-01 to 2009-10-01 Profit Factor:0.71 Total Net Profit:-185.23

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:0.49 Total Net Profit:-420.35

BackTest : EURUSD on H1

From 2010-04-01 to 2010-04-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-05-01 to 2010-05-31 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-06-01 to 2010-06-30 Profit Factor:0.00 Total Net Profit:0.00

Request Backtest for gail_2


From : (yyyy/mm/dd) To: (yyyy/mm/dd)

Pair: Period: