
extern double TakeProfit =  15; 
extern double StopLoss   =   0; 
extern double Lots       = 0.1; 
extern double Slippage   =   0;
extern double Filter_In  =   1;
extern double Filter_Out =   1;
extern double Day_Open   =   6;
extern int    Start_Trade =  6;
extern int    Stop_Trade  = 21;

int NumOrder ; 

//+------------------------------------------------------------------+ 
//|                                                                  | 
//+------------------------------------------------------------------+ 

int start() 
  { 
  bool Inside_Long_1, Inside_Long_2, Inside_Long_3, Inside_Long_4 ;
  bool Inside_Short_1, Inside_Short_2, Inside_Short_3, Inside_Short_4;
 
  bool Long_1, Long_2, Long_3, Long_4  ;
  bool Short_1, Short_2, Short_3, Short_4 ;
  
  int cnt, ticket, total;

   if(Bars<100) 
     { 
      Print("bars less than 100"); 
      return(0);  
     } 

     if(isNewBar()) {NumOrder = 0;} 

     if(TakeProfit<10) 
     { 
      Print("TakeProfit less than 10"); 
      return(0);  // check TakeProfit 
     } 
     
   total=OrdersTotal();

// to simplify the coding and speed up access 
// data are put into internal variables 

   Inside_Long_1   =  High[1] <= High[2] && Low[1] >= Low[2] && High[1] >= iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0) && Hour() > Start_Trade && Hour() < Stop_Trade ; 
   Inside_Long_2   =  High[2] <= High[3] && Low[2] >= Low[3] && High[2] >= iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0) && High[1] <= High[2] && Hour() > Start_Trade && Hour() < Stop_Trade ;  
   Inside_Long_3   =  High[3] <= High[4] && Low[3] >= Low[4] && High[3] >= iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0) && High[2] <= High[3] && High[1] <= High[3] && Hour() > Start_Trade && Hour() < Stop_Trade ;  
   Inside_Long_4   =  High[4] <= High[5] && Low[4] >= Low[5] && High[4] >= iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0) && High[3] <= High[4] && High[2] <= High[4] && High[1] <= High[4] && Hour() > Start_Trade && Hour() < Stop_Trade ;  
      
   Inside_Short_1  =  High[1] <= High[2] && Low[1] >= Low[2] && Low[1] <= iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0) && Hour() > Start_Trade  && Hour() < Stop_Trade ; 
   Inside_Short_2  =  High[2] <= High[3] && Low[2] >= Low[3] && Low[2] <= iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0) && Low[1] >= Low[2] && Hour() > Start_Trade && Hour() < Stop_Trade ;  
   Inside_Short_3  =  High[3] <= High[4] && Low[3] >= Low[4] && Low[3] <= iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0) && Low[2] >= Low[3] && Low[1] >= Low[3] && Hour() > Start_Trade && Hour() < Stop_Trade ;  
   Inside_Short_4  =  High[4] <= High[5] && Low[4] >= Low[5] && Low[4] <= iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0) && Low[3] >= Low[4] && Low[2] >= Low[4] && Low[1] >= Low[4] && Hour() > Start_Trade && Hour() < Stop_Trade ;  
       
   Long_1 = Bid > (High[1] + Filter_In*Point) && Inside_Long_1 && Bid > iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0); 
   Long_2 = Bid > (High[2] + Filter_In*Point) && Inside_Long_2 && Bid > iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0); 
   Long_3 = Bid > (High[3] + Filter_In*Point) && Inside_Long_3 && Bid > iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0); 
   Long_4 = Bid > (High[4] + Filter_In*Point) && Inside_Long_4 && Bid > iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0); 
     
   Short_1  = Ask < (Low[1] - Filter_In*Point) && Inside_Short_1 && Ask < iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0); 
   Short_2  = Ask < (Low[2] - Filter_In*Point) && Inside_Short_2 && Ask < iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0); 
   Short_3  = Ask < (Low[3] - Filter_In*Point) && Inside_Short_3 && Ask < iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0); 
   Short_4  = Ask < (Low[4] - Filter_In*Point) && Inside_Short_4 && Ask < iCustom(NULL,0,"daily_open_line",Day_Open,6,0,0); 
   
// no opened orders identified 

      if(AccountFreeMargin()<(500*Lots)) 
        { 
         Print("We have no money. Free Margin = ", AccountFreeMargin()); 
         return(0);  
        } 
       
// check for long position (BUY) possibility 

      if(Long_1 || Long_2 || Long_3 || Long_4) 
      {
       SendMail("from Inside Bar Expert", "Price dropped up previous Inside Bar High");
       return(0); 
      }
           
      
// check for short position (SELL) possibility 

      if(Short_1 || Short_2 || Short_3 || Short_4)
        {           
         SendMail("from Inside Bar Expert", "Price dropped down previous Inside Bar High");
        return(0); 
        } 
      
} 

// the end. 

bool isNewBar() 

{ 

   static datetime lastbar=0; 
   datetime curbar = Time[0]; 
   if(lastbar!=curbar) 
   { 
   lastbar=curbar; 
      return (true); 
   } 
   else 
   { 
      return(false); 
   } 
}

