//+------------------------------------------------------------------+
//|                                              BUY con SL y TP.mq4 |
//|               Marisa Matamoros © 2010, MetaQuotes Software Corp. |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Marisa Matamoros © 2010, MetaQuotes Software Corp."
#property link      ""

extern double Lotes = 0.4;
extern bool   MoneyManagement = false;
extern double PorcentajeRiesgo = 5;
extern bool   UsarSL = true;
extern bool   UsarTP = true;
extern double StopLoss = 30;
extern double TakeProfit = 30;
extern string Poner = "0 en Precio para compra a precio de mercado";
extern double Precio = 0.0000;

string Input = " Buy Price ";

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+

int start()
  { 
  double Riesgo = PorcentajeRiesgo / 100;
  if (MoneyManagement)  
   Lotes = NormalizeDouble(AccountBalance()*Riesgo/StopLoss/(MarketInfo(Symbol(),MODE_TICKVALUE)),2); 
  
  int Mode = OP_BUYSTOP;
  if (Ask > Precio && Precio > 0) Mode = OP_BUYLIMIT; 
  if (Precio == 0)  {Precio = Ask; Mode = OP_BUY;}
  
  double SLB = Precio - StopLoss*Point, TPB = Precio + TakeProfit*Point;
  if (UsarSL == false) SLB = 0;
  if (UsarTP == false) TPB = 0;
  
  if(Lotes > 0)
   OrderSend(Symbol(),Mode, Lotes, Precio, 2, SLB, TPB, "Buy Script", 0, NULL, LimeGreen);
   
  return(0);
  }
//+------------------------------------------------------------------+


