hocok





//+------------------------------------------------------------------+
//|                                                        hocok.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//---- input parameters
extern int TakeProffit   = 0;
extern int StopLoss      = 0;
extern int signal_period = 9;

static int     magic = 1;
static datetime opentime;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
  
void CloseOrders()
{
   for (int i = OrdersTotal() - 1; i > -1; i--)
   {
      if (OrderSelect(i, SELECT_BY_POS, MODE_MAIN))
      {
         if (OrderMagicNumber() == magic)
         {
            if (OrderType() == OP_BUY)
               OrderClose(OrderTicket(), OrderLots(), Bid, 3, Yellow);
            else         
               OrderClose(OrderTicket(), OrderLots(), Ask, 3, Yellow);
         }
      }
   }
}
  
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
   double SL = 0, TP = 0;
   int fast_ema_period = 21;
   int slow_ema_period = 34;
   
   if (opentime == Time[1])
      return (0);

   opentime = Time[1];
   
   double prev = iMACD(Symbol(), 0, fast_ema_period, slow_ema_period, signal_period, PRICE_CLOSE, MODE_SIGNAL, 2);
   double curr = iMACD(Symbol(), 0, fast_ema_period, slow_ema_period, signal_period, PRICE_CLOSE, MODE_SIGNAL, 1);
   
   // Ñèãíàë ê ïîêóïêå
   if ((prev < 0) && (curr > 0))
   {
      CloseOrders();

      if (StopLoss    != 0) SL = Bid - StopLoss    * Point;
      if (TakeProffit != 0) TP = Bid + TakeProffit * Point;
      OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, NormalizeDouble(SL, Digits), 
                                               NormalizeDouble(TP, Digits), "", magic, 0, Red);
      return (0);
   }

   // Ñèãíàë ê ïðîäàæå
   if ((prev > 0) && (curr < 0))
   {
      CloseOrders();

      if (StopLoss    != 0) SL = Ask + StopLoss    * Point;
      if (TakeProffit != 0) TP = Ask - TakeProffit * Point;
      OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, NormalizeDouble(SL, Digits), 
                                                NormalizeDouble(TP, Digits), "", magic, 0, Red);
      return (0);
   }

   return(0);
}
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar


Indicator Curves created:


Indicators Used:

MACD Histogram


Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders

It Closes Orders by itself

Other Features: