//+------------------------------------------------------------------+
//|                                                          Buy.mq4 |
//|                                                       bfis108137 |
//|                                                baaaaaary@msn.com |
//+------------------------------------------------------------------+
#property copyright "bfis108137"
#property link      "baaaaaary@msn.com"
#property show_inputs
extern double lots=0.01;
extern int slippage=30;
extern string ext="type 0=long 1=short";
extern int type=0;
extern double sl=100;
extern double tp=100;
extern int magic = 543416;
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   
   double prc = Ask;
   if(type % 2 == 1)prc = Bid;
   int tic = OrderSend(Symbol(),type,lots,prc,slippage,0,0,"close open script");
   if(tic == -1)
   {
      Alert("order send failed code=",GetLastError());
   }
   else
   {      
      if(OrderSelect(tic,SELECT_BY_TICKET))
      {
         double ourSl = sl;
         double ourTp = tp;
         if(sl > 0)
         {
            ourSl = OrderOpenPrice() - sl * Point;
            if(type % 2 == 1)
            {
               ourSl = OrderOpenPrice() + sl * Point;
            }
         } 
         if(tp > 0)
         {
            ourTp = OrderOpenPrice() + tp * Point;
            if(type % 2 == 1)
            {
               ourTp = OrderOpenPrice() - tp * Point;
            }
         } 
         if(!OrderModify(tic,OrderOpenPrice(),ourSl,ourTp,OrderExpiration()))
         {
            Alert("order modify error code=",GetLastError());
         }
      }
      else
      {
         Alert("order select failed code=",GetLastError());
      }
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+