EA Buy orders being executed

 

In my code I've tried Limit Orders as well as Market Orders. The Sells are working perfectly but for some reason the Buy Orders/Executions are not fully coming through. The Buy Order does not generate an error according to the Journal, but I do not see the Buy Order in the Trade Terminal.
I have not been able to find anything out of the ordinary myself, I'd love some outside insight.


My full code: 

// Global Functions and variables
#include <trade/trade.mqh>


class CFairValueGap : public CObject {
public:
    int direction;
    datetime time;
    double high;
    double low;

    void draw(datetime timeStart, datetime timeEnd){
      // FVG Rectangle Object
      string objFvg = "FVG";
      if(ObjectFind(0,objFvg) < 0){
         ObjectCreate(0,objFvg,OBJ_RECTANGLE,0,timeEnd,low,timeStart,high);
         ObjectSetInteger(0,objFvg,OBJPROP_FILL,true);
         ObjectSetInteger(0,objFvg,OBJPROP_COLOR, clrLightYellow);
         ObjectCreate(0,objFvg + " Midpoint", OBJ_TREND,0,timeStart,(((high-low)/2)+low),timeEnd,(((high-low)/2)+low));
         ObjectSetInteger(0,objFvg + " Midpoint",OBJPROP_STYLE,STYLE_DASH);
         ObjectSetInteger(0,objFvg + " Midpoint",OBJPROP_COLOR,clrBlack);
         
         
         };
      };
};      



// User Inputs
input group "Money Management"
input double Lots = 0.1;
input double RiskPercent = 0.5;
input double RiskReward = 2;

input group "Trade Settings"
ENUM_TIMEFRAMES Timeframe =  Period();
input int MinFVGPoints = 10;

input group "Time Settings"
input int offsetEST = 0;


// Pointers
CTrade trade;
CFairValueGap* fvg;


double calcLots(double slDist){
   double risk = AccountInfoDouble(ACCOUNT_BALANCE) * RiskPercent / 100;
   
   double ticksize = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
   double tickvalue = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE);
     
   if(ticksize == 0) return -1;
   
   double moneyPerLot = slDist / ticksize * tickvalue;
   
   if(moneyPerLot == 0) return -1;
   
   double lots = NormalizeDouble(risk / moneyPerLot,2);
   return lots;
};

double calcTPsell(double entry, double sl){

   double tp = ((entry - sl) * RiskReward) + entry;

   return tp;
};

double calcTPbuy(double entry, double sl){

   double tp = ((sl - entry) * RiskReward) - entry;

   return tp;
};


void CloseAllOrders(){
   for(int i=OrdersTotal()-1; i>=0; i--){
      int ticket=OrderGetTicket(i);
      
      trade.OrderDelete(ticket);
   }
};

void CloseAllPositions(){
   for(int i=PositionsTotal()-1; i>=0; i--){
      int ticket=PositionGetTicket(i);
      
      trade.PositionClose(ticket);
   }
};

// End of Global Functions/Classes


int OnInit()
  {

   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
   delete fvg;
   ObjectsDeleteAll(0,"FVG");
   
  }

void OnTick()
  {
  static int lastDay = 0;
  
   // Session Time Variables
   int sessionClose = 16 + offsetEST;
   int sessionStart = 3 + offsetEST;
   int sessionEnd = 4 + offsetEST;
   
  
   // In Trade Session Hours
   MqlDateTime structTime;
   TimeCurrent(structTime);
   structTime.min = 0;
   structTime.sec = 0;
   
   structTime.hour = sessionClose;
   datetime timeClose = StructToTime(structTime);
   
   structTime.hour = sessionStart;
   datetime timeStart = StructToTime(structTime);
   
   structTime.hour = sessionEnd;
   datetime timeEnd = StructToTime(structTime);
   
   // In Trade Session Check
   Print(TimeCurrent());
   Print(timeStart); Print(timeEnd);
   if(TimeCurrent() >= timeStart && TimeCurrent() < timeEnd){
   Print("In Session");
      if(lastDay != structTime.day_of_year){
         delete fvg;
   
         if(OrdersTotal() == 0 && PositionsTotal() == 0){
            // Check for FVG
            if(ObjectFind(0,"FVG") != 0){
               Print("Checking for FVG");
               for(int i=0; i < 3; i++){
                  // Check for BISI
                  if(iLow(_Symbol,Timeframe,i) - iHigh(_Symbol,Timeframe,i+2) > MinFVGPoints * _Point) {
                     fvg = new CFairValueGap();
                     fvg.direction = 1;
                     fvg.time = iTime(_Symbol,Timeframe,i+1);
                     fvg.high = iLow(_Symbol,Timeframe,i);
                     fvg.low = iHigh(_Symbol,Timeframe,i+2);
                     fvg.draw(timeStart,timeEnd);
                     lastDay = structTime.day_of_year;
                       
                     if(iLow(_Symbol,Timeframe,iLowest(_Symbol,Timeframe,MODE_LOW,i+1)) <= fvg.low){
                        delete fvg;
                        ObjectsDeleteAll(0);
                        break;
                     }
                     
                  }
                  // Check for SIBI
                  if(iLow(_Symbol,Timeframe,i+2) - iHigh(_Symbol,Timeframe,i) > MinFVGPoints * _Point){ // FVG Down
                     fvg = new CFairValueGap();
                     fvg.direction = -1;
                     fvg.time = iTime(_Symbol,Timeframe,i+1);
                     fvg.high = iLow(_Symbol,Timeframe,i+2);
                     fvg.low = iHigh(_Symbol,Timeframe,i);
                     fvg.draw(timeStart,timeEnd);
                     lastDay = structTime.day_of_year;   
                     if(iHigh(_Symbol,Timeframe,iHighest(_Symbol,Timeframe,MODE_HIGH,i+1)) >= fvg.high){
                        delete fvg;
                        ObjectsDeleteAll(0);
                        break;
                     }
                     
                        
                  }
               } // End of For Loop
            }
            
            if(ObjectFind(0,"FVG") == 0){
            Print("FVG Found... Checking for Trade");
            // Check for Trade
               double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
               double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
               if(CheckPointer(fvg) != POINTER_INVALID && fvg.direction > 0 /* && ask < fvg.high */){
                  double entry = fvg.high;
                  double sl = iLow(_Symbol,Timeframe,iLowest(_Symbol,Timeframe,MODE_LOW,5,iBarShift(_Symbol,Timeframe,fvg.time)));
                  double tp = calcTPbuy(entry,sl);
                  double lots = Lots;
                  if(Lots == 0) lots = calcLots(sl - entry);
                  Print("Sending Order");
                  Print(entry, sl, tp, lots);
                  trade.BuyLimit(lots,entry,_Symbol,sl,tp);
                  // trade.Buy(lots,_Symbol,entry,sl,tp);
               } // End of CheckPointer
   
   
               if(CheckPointer(fvg) != POINTER_INVALID && fvg.direction < 0 /* && bid < fvg.low */){
                  double entry = fvg.low;
                  double sl = iHigh(_Symbol,Timeframe,iHighest(_Symbol,Timeframe,MODE_HIGH,5,iBarShift(_Symbol,Timeframe,fvg.time)));
                  double tp = calcTPsell(entry,sl);
                  double lots = Lots;
                  if(Lots == 0) lots = calcLots(sl - entry);
                  Print("Sending Order");
                  Print(entry, sl, tp, lots);
                  trade.SellLimit(lots,entry,_Symbol,sl,tp);
                  // trade.Sell(lots,_Symbol,entry,sl,tp);              
               } // End of CheckPointer
               
               // Close Orders if FVG == Invalid
               if(CheckPointer(fvg) == POINTER_INVALID){
                  Print("FVG Invalid");
                  delete fvg;
                  ObjectsDeleteAll(0);
                  CloseAllOrders();
               }
               
            } // End Check for Trade
      }
      }
      
      else{
         // Print Orders and Positions
         if(PositionsTotal() == 0){
            Print("Order in...");
         }
         else if(OrdersTotal() == 0){
            Print("In Position...");
         };
         
      };
   
   
   
   } // End of If (Session Check)
   
   else{
      Print("Out of Session");
      delete fvg;
      ObjectsDeleteAll(0);
      Print("Closing Pending Orders");
      CloseAllOrders();
   
   if(TimeCurrent() >= timeClose && TimeCurrent() < timeStart){
      delete fvg;
      ObjectsDeleteAll(0);
      Print("Closing Open Positions");
      CloseAllPositions();
   }
   };



} // End of Code