//+------------------------------------------------------------------+
//|                                            Morning Break Out.mq4 |
//|                                                           Akhmad |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Akhmad"
#property link      ""
extern int StartTime;
extern int EndTime;

extern double    TakeProfit=5;
extern double    StopLoss = 25;
extern double    Lots=1;

int RunningTime;
double BidPrice, HighPrice, LowPrice;
bool TakeData = false, FlagFirst = true, FlagOrder = false;
string StartString, EndString;

int BuyStop, SellStop;
double MyAskPrice, MyBidPrice;

double StopLevel, DiffAsk, DiffBid;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   StartString = "00:00";
   EndString = "07:59";
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   StartTime = StrToTime(StartString);
   EndTime = StrToTime(EndString);
   
   RunningTime = TimeCurrent();
   
   if (RunningTime >= StartTime && RunningTime <= EndTime)
      {
         TakeData = true;
         BidPrice = MarketInfo("GBPUSD",MODE_BID);
         FlagOrder = true;
         
            if (TakeData == true)
               {
                  if (FlagFirst == true)
                     {
                        HighPrice = MarketInfo("GBPUSD",MODE_BID);
                        LowPrice = MarketInfo("GBPUSD",MODE_BID);
                        FlagFirst = false;
                     }
                  else
                     {
                        if (HighPrice < BidPrice) HighPrice = BidPrice;
                        if (LowPrice > BidPrice) LowPrice = BidPrice;
                        
                        Comment("HIGH : ",HighPrice,"\nLOW : ",LowPrice);
                     }
               }
      }
   else
      {
         if (FlagOrder == true)
            {
               Order();
               //x();
               FlagOrder = false;
               //Print("ORDER");
            }
         
         TakeData = false;
         FlagFirst = true;
      }
                                                
//----
   return(0);
  }
//+------------------------------------------------------------------+
void Order()
   {
                       
      MyAskPrice = HighPrice + (Point*2);
      MyBidPrice = LowPrice - (Point*2);
      TakeProfit = TakeProfit * Point;
                    
      StopLevel = MarketInfo("GBPUSD",MODE_STOPLEVEL);
                
      //+----------------------------------------------
      //| Check MyAskPrice and MyBidPrice
      //+----------------------------------------------
      DiffAsk = (MyAskPrice - Ask)/Point;
      DiffBid = (Bid - MyBidPrice)/Point;
         
      //+------------------------------------------
      //| If Diff < StopLevel then make Correction
      //+------------------------------------------
      if (DiffAsk < StopLevel) MyAskPrice = MyAskPrice + (StopLevel - DiffAsk)*Point;
      if (DiffBid < StopLevel) MyBidPrice = MyBidPrice - (StopLevel - DiffBid)*Point;
         
      
      //+-------------------------------------------------------------------------------------------
      //|BUY STOP
      //+-------------------------------------------------------------------------------------------
      BuyStop = OrderSend(Symbol(),OP_BUYSTOP,1,MyAskPrice,3,0,MyAskPrice+TakeProfit,"BUY STOP",123,0,Green);
      
      if (BuyStop > 0)
         {
            Print("OK BUY STOP. My Ask Price : ",MyAskPrice,"  .ASK : ",Ask);
         }
      else
         {
            Print("FAILED BUY STOP. My Ask Price : ",MyAskPrice,"  .ASK : ",Ask,"  .Error : ",GetLastError());
         }
                  
      
      //+-------------------------------------------------------------------------------------------
      //|SELL STOP
      //+-------------------------------------------------------------------------------------------
      SellStop = OrderSend(Symbol(),OP_SELLSTOP,1,MyBidPrice,3,0,MyBidPrice-TakeProfit,"SELL STOP",321,0,Red);
      
      if (SellStop > 0)
         {
            Print("OK SELL STOP. My Bid Price : ",MyBidPrice,"  .Bid : ",Bid);
         }
      else
         {
            Print("FAILED SELL STOP. My Bid Price : ",MyBidPrice,"  .Bid : ",Bid,"  .Error : ",GetLastError());
         }
   
   }
/*   
void x()
   {
      MyAskPrice = HighPrice + (Point*2);
      MyBidPrice = LowPrice - (Point*2);
      TakeProfit = TakeProfit * Point;
                    
      StopLevel = MarketInfo("GBPUSD",MODE_STOPLEVEL);
                
      DiffAsk = ((MyAskPrice) - Ask)/Point;
      DiffBid = (Bid - MyBidPrice)/Point;
      
      Print("MY ASK : ",MyAskPrice," .ASK : ",Ask," .DIFF ASK : ",DiffAsk);
      Print("MY BID : ",MyBidPrice," .BID : ",Bid," .DIFF BID : ",DiffBid);
         
      if (DiffAsk < StopLevel) MyAskPrice = MyAskPrice + (StopLevel - DiffAsk)*Point;
      if (DiffBid < StopLevel) MyBidPrice = MyBidPrice - (StopLevel - DiffBid)*Point;
      
      Print("MY NEW ASK : ",MyAskPrice," .ASK : ",Ask);
      Print("MY NEW BID : ",MyBidPrice," .BID : ",Bid);
      
    }
*/