//+------------------------------------------------------------------+
//|                                                  PO_Buy_Stop.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#property show_confirm
#property show_inputs

input double Lots = 0.1;
input int Slippage   = 3;
input int Buy_Stop_Distance = 100;
input int StopLoss = 100;
input int TakeProfit =100;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   if(!IsExpertEnabled())
        {
         MessageBox("You need to enable AutoTrading! "+" Check your Settings!");
         return;
        }

      if(!IsTradeAllowed())
        {
         MessageBox("You need to Allow Live Trading! "+" Check your Settings!"+"\n"+
                    "Common tab -> Live Trading -> Allow live trading");
         return;
        }
   int ticket;
   /*,expiration;*/
   double point;

   point=MarketInfo(Symbol(),MODE_POINT);
   //expiration=CurTime()+PERIOD_D1*60;
   
   double BS_distance_L1 = Ask+Buy_Stop_Distance*point;
   double BS_distance_L2 = Ask+Buy_Stop_Distance*point*2;
    
   while(true)
     {
       ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,BS_distance_L1,Slippage,BS_distance_L1-StopLoss*point,BS_distance_L1+ TakeProfit*Point,NULL,16384,0,clrNONE); // BUYSTOP LEVEL 1
       ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,BS_distance_L2,Slippage,BS_distance_L2-StopLoss*point,BS_distance_L2+ TakeProfit*Point,NULL,16384,0,clrNONE); // BUYSTOP Level 2
        
       PlaySound("ok.wav");
      if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket); break; }
      //---- 10 seconds wait
     // Sleep(10000);
     }
     return;
  }

