martiniy





//+------------------------------------------------------------------+
//|                                                     martiniy.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                      http://forum.alpari-idc.ru/thread32672.html |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://forum.alpari-idc.ru/thread32672.html"
static int magicNumber = 666;
static datetime last_time = '';

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
      Print(CurTime() - last_time);
      last_time = CurTime();
      
   int find = ObjectFind("RES1");
   if (find == -1)
   {
      Print("line not found");
      return (0);
   }
   else
   {
      // íàøëè ëèíèþ, îïðåäåëèì óðîâåíü
      double price = NormalizeDouble(ObjectGet("RES1", OBJPROP_PRICE1), Digits);
      
      if (price < Ask)
      {
         Print("Öåíà ìåíüøå Ask!");
         return (0);
      }
      
      bool found = false;
      for (int i = 0; i < OrdersTotal(); i++)
      {
         // Íàøëè íàø îòëîæåííûé îðäåð
         if((OrderSelect(i, SELECT_BY_POS, MODE_MAIN) == true) &&
            (OrderType       () == OP_BUYSTOP)        &&
            (OrderMagicNumber() == magicNumber)       &&
            (OrderSymbol     () == Symbol()))
         {
            found = true;
            
            if (CurTime() - last_time < 60 * 30)
               break;
            
            if (NormalizeDouble(OrderOpenPrice(), Digits) != NormalizeDouble(price, Digits))
            {
               double tp = OrderTakeProfit();
               double sl = OrderStopLoss();
               
               if (tp > 0)
                   tp = OrderTakeProfit() + (price - OrderOpenPrice());
               
               if (sl > 0)
                   sl = OrderStopLoss()   + (price - OrderOpenPrice());

               OrderModify(OrderTicket(), NormalizeDouble(price, Digits),
                                          NormalizeDouble(sl, Digits), 
                                          NormalizeDouble(tp, Digits), 
                                          OrderExpiration(), CLR_NONE);
               last_time = CurTime();
            }
         }
      }
      
      if (!found)
      {
         if (
         OrderSend(Symbol(), 
                   OP_BUYSTOP, 
                   0.1, 
                   price, 
                   3,
                   0,
                   0,
                   "buy stop",
                   magicNumber,
                   0,
                   CLR_NONE) == -1)
         {
            Print("Îøèáêà :"+GetLastError());
         }
         else
            Print("îðäåð îòêðûò ïî öåíå :"+price);
      }
   }

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



Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders

It can change open orders parameters, due to possible stepping strategy

Other Features: