Download MetaTrader 5
To add comments, please log in or register
MQL5.community allows users to store their source codes in MQL5 Storage. Try it!
jupp
27
jupp 2016.02.06 12:33 
Hi, guys this below is a script that is used to place a buy pending order.
It is not complete because it is missing a part, but I do not know where to start, if any of you can help me I would be really happy.
In fact it is not even a part but it is enter an activation command.
In fact, what I would like is that the script began to run after a previous order has entered the market.
In a nutshell, I position it in manual mode, a pending order on the market, well, when this order came to the market, the script where "action" and place another pending order, that is, to do what it is programmed.
Script to place the order is already there (this below), the problem, as mentioned, is that I do not know to change it. I searched on the site different codes but I have not found the right one, or at least I have not been able to figure out how to use these codes.

So if someone is kind enough to help me out, I would be truly grateful.

_______________________________________________________________________________________________________________________________________________________________________


//+------------------------------------------------------------------+
//|                                                      buyStop.mq4 |
//|                      Copyright © 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property show_inputs  // This key property for scripts brings up a popup window of the external variables.

extern double Lots = 0.01;
extern double LotExponent = 2;
extern double PipStep = 30;
extern int TotalTradeNumber = 10;
extern double value = 1.33220;
extern int MagicNumber = 478;
extern int TradeReverse = 0;

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
   int    ticket;  
  
   int trades = 0;
   double lotVal = 0.0;
     
      if (TotalTrades() < TotalTradeNumber)
      {
         trades = TotalTradeNumber - TotalTrades();
      }
      else
      {
         return (0);
      }
     
      if (TradeReverse == 0)
      {
         for ( int i = 0; i < trades; i++)
         {
            lotVal = NormalizeDouble( Lots * MathPow(LotExponent, i), 2);         
            ticket=OrderSend(Symbol(),OP_BUYSTOP,lotVal,value+(PipStep*10*Point*i),0,0,0,"some comment",MagicNumber,0,Green);
            if(ticket<=0)
               Print("Error = ",GetLastError());
            else
            {
               Print("ticket = ",ticket);
               while(IsTradeContextBusy())
               Sleep(100);           
           
            }           
         }
      }
    
   return(0);
  }
 
  int TotalTrades()
  {
      int totalTrades = 0;
      for (int trade = OrdersTotal() - 1; trade >= 0; trade--)
      {
         OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
             
         if (OrderSymbol() == Symbol())
         {
            if (OrderMagicNumber() == MagicNumber)
            {
               if (OrderType() == OP_BUYSTOP)
               {
                  totalTrades++;
               }
            }
         }
      }
      return (totalTrades);
  } 
 
//+------------------------------------------------------------------+

Files:
buystop.mq4 3 kb
/
To add comments, please log in or register