Problem with orders not appearing



I'm fairly new to coding and I've run into a problem that I don't know how to fix. I'm trying to make a EA that trades using the Bollinger Bands indicator to then maybe use in a more sophisticated EA later. However during my testing I've noticed that it is not placing any orders. Although it says in the trading history that a total of 4562 orders have been filled, when looking at the operations it says that all of these orders are still pending?

Here the current code:

#include <Trade/Trade.mqh>
CTrade trade;

input int BandPeriod                         =  20;
input double BandDeviation                   =  2.0;
ENUM_APPLIED_PRICE BandAppliedPrice          =  PRICE_CLOSE;

input double TPDeviation   =  1.0;
input double SLDeviation   =  1.0;

int OnInit() {


void OnDeinit(const int reason){ 


void OnTick() {

   if(!IsNewBar())   return;                                //! = not
   double close1  =  iClose(Symbol(),Period(),1);
   double high1   =  iHigh(Symbol(),Period(),1);
   double low1    =  iLow(Symbol(),Period(),1);
   double close2  =  iClose(Symbol(),Period(),2);
   double upperArr[2];
   double lowerArr[2];

   double upper1 =  upperArr[0];
   double lower1 =  lowerArr[0];
   double upper2 =  upperArr[1];
   double lower2 =  lowerArr[1];
   if (close2>upper2 && close1<upper1) {
   else if (close2<lower2 && close1>lower1) {

bool IsNewBar() {

   datetime currentTime       =  iTime(Symbol(),Period(),0);
   static datetime prevTime   =  currentTime;
   if (prevTime<currentTime) {
      prevTime = currentTime;

Maybe someone with more knowledge about this can help me out and please excuse if it's something very trivial.