//+------------------------------------------------------------------+
//|                                              Buy  with SL and TP |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "   "
#property link      "   "


#property show_inputs

extern double Lots = 0.01;
extern double Entry = 0.0000;
extern double TakeProfit = 300;
extern double StopLoss = 500.0;
extern bool   UseActualSLTP = true;
extern double StopLossPrice = 0.0000;
extern double TakeProfitPrice = 0.0000;
extern int    NumberOfOrders = 3;
extern bool   MicroOrdersAllowed = true;
extern bool   MiniOrdersAllowed = true;
extern bool   UseMoneyMgmt = false;
extern double RiskPercent = 1.0;
extern string Note="0 in Entry field means Market Order Buy";
extern string Comments = "Buy Script";



//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  { 
  double Risk = RiskPercent / 100;
  int OrdersizeAllowed = 0;
  int Mode = OP_BUYSTOP;
  if (Ask > Entry && Entry > 0) Mode = OP_BUYLIMIT; 
  if (Entry == 0)  {Entry = Ask; Mode = OP_BUY;}
  double SLP = Entry - StopLoss*Point, TPP = Entry + TakeProfit*Point;

  if (UseActualSLTP)
      {
         StopLoss = (Entry-StopLossPrice)/Point;
         SLP = StopLossPrice;
         TPP = TakeProfitPrice;    
      }
  if (MiniOrdersAllowed) OrdersizeAllowed=1;
  if (MicroOrdersAllowed) OrdersizeAllowed=2;        
  if (UseMoneyMgmt)  
      Lots = NormalizeDouble( AccountBalance()*Risk/StopLoss/(MarketInfo(Symbol(), MODE_TICKVALUE)),OrdersizeAllowed);       

  if ((Lots < 0.01&&MicroOrdersAllowed) || (Lots < 0.01&&MiniOrdersAllowed&&MicroOrdersAllowed==false))
      {
         Comment("YOUR LOTS SIZE IS TOO SMALL TO PLACE!");
      } 

  if(Lots > 0)
  for (int i=0;i<NumberOfOrders;i++)
      {
         OrderSend(Symbol(),Mode, Lots, Entry, 2,SLP , TPP, Comments, 0, NULL, LimeGreen);
      }

           
   return(0);
  }
//+------------------------------------------------------------------+