Price Data Components
Series array that contains open time of each bar
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reached
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
57.00 %
Total Trades 846
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -0.14
Gross Profit 153.77
Gross Loss -272.01
Total Net Profit -118.24
-100%
-50%
0%
50%
100%
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);
   }
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---