//+------------------------------------------------------------------+
//|                                                   dranzerbot.mq4 |
//|                                                            Brent |
//|                                     http://www.mt4awesomizer.com |
//+------------------------------------------------------------------+
#property copyright "Brent"
#property link      "http://www.mt4awesomizer.com"
#property version   "1.00"
#property strict

extern double SL = 20;
extern double TP = 10;
extern double LOTS = 0.1;
datetime BarTime = 0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
      
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   NewBar(); 
   
  }

void NewBar()
{   
    if (BarTime < Time[0])
    {       
        BarTime = Time[0]; 
        
        CloseTrade();
        OpenTrade();     
    }
}

void CloseTrade()
{    
    for(int i=OrdersTotal()-1;i>=0;i--)
    {
        bool selection = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        bool result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, clrNONE );        
    }
    return; 
}

void OpenTrade()
{
   double stopLoss = Ask - (SL * Point);
   double takeProfit = Ask + (TP * Point);
   if(OrdersTotal() == 0) bool send = OrderSend(Symbol(),OP_BUY,LOTS,Ask,5,stopLoss,takeProfit,NULL,123,0,clrNONE);
}