Stopping multiple entry

 
Please can somebody help me go through this code and find out why its having multiple entry, if a sell condition is true it keeps entering multiple sells, the same with buy

//+------------------------------------------------------------------+
//|                                                      testing.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

bool buytrue = true;
bool selltrue = true;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
 // closeallmarket();
 // /*
   double SH1 = iCustom(NULL,0,"Heiken Ashi",0,0);
   double BH1 = iCustom(NULL,0,"Heiken Ashi",1,0);
   double SH2 = iCustom(NULL,0,"Heiken Ashi",2,0);
   double BH2 = iCustom(NULL,0,"Heiken Ashi",3,0);
 double mm = iMA(NULL,0,14,0,MODE_EMA,PRICE_CLOSE,0);
  if (Ichibelowprice()==true && HeikenasniBuy()==true && checkichcloud()==true && buytrue==true) {  
  
  openBuyTrade();
  buytrue=false;
  selltrue=true;
  }
 if(HeikenashiSell()== true) {
  closeBuyTrade();
  selltrue=true;
  buytrue=true;
  }
   
  if(Ichiaboveprice()== true && HeikenashiSell()==true &&  checkichcloud()==true && selltrue==true) { 
 
  openSellTrade();
  selltrue=false;
  buytrue=true;
  } 
 if(HeikenasniBuy()== true) 
  {
   closeSellTrade();
   buytrue = false;
  selltrue = false;
  }

  //*/
  }
//+------------------------------------------------------------------+



void openBuyTrade() {
OrderSend(Symbol(),OP_BUY,0.01,Ask,3,NULL,NULL);
}

void openSellTrade() {
OrderSend(Symbol(),OP_SELL,0.01,Bid,3,NULL,NULL);
}

void closeBuyTrade() {
double closePrice = 0;
for (int i=0; i<OrdersTotal(); i++) {
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol() == Symbol()) {
closePrice = NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),Digits);
OrderClose(OrderTicket(),OrderLots(),closePrice,3);
}
}
}

void closeSellTrade() {
double closePrice = 0;
for (int i=0; i<OrdersTotal(); i++) {
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol() == Symbol()) {
closePrice = NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),Digits);
OrderClose(OrderTicket(),OrderLots(),closePrice,3);
}
}
}


void closeallmarket() {
for(int i=0; i<OrdersTotal(); i++)
 {
  
  double ClosePrice = 0;
          
 OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
  RefreshRates();
         if(OrderType()==OP_BUY) ClosePrice=NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),Digits);
         if(OrderType()==OP_SELL) ClosePrice=NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),Digits);
         
OrderClose(OrderTicket(),OrderLots(),ClosePrice,5,Blue);
  
 }
}


bool checkichcloud()  
{
   double chikou=iIchimoku(NULL,0,9,26,52,MODE_CHIKOUSPAN,0);
   double senkoua=iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANA,0);
   double senkoub=iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANB,0);
   
   if(Bid<senkoua && Bid>senkoub)
   return(false);
   else
   return(true);
}


bool HeikenasniBuy() {
   double SH1 = iCustom(NULL,0,"Heiken Ashi",0,0);
   double BH1 = iCustom(NULL,0,"Heiken Ashi",1,0);
   double SH2 = iCustom(NULL,0,"Heiken Ashi",2,0);
   double BH2 = iCustom(NULL,0,"Heiken Ashi",3,0);
  
  if(SH1<BH1 && SH2<BH2)
      return(true);
      else
      return(false);
}
bool HeikenashiSell() {
   double SH1 = iCustom(NULL,0,"Heiken Ashi",0,0);
   double BH1 = iCustom(NULL,0,"Heiken Ashi",1,0);
   double SH2 = iCustom(NULL,0,"Heiken Ashi",2,0);
   double BH2 = iCustom(NULL,0,"Heiken Ashi",3,0);
   
 if(SH1>BH1 && SH2>BH2)
 return(true);
 else
 return(false);
}

bool Ichibelowprice() {
double ich=iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANA,0);
if(ich < Bid)
return(true);
else
return(false);
}

bool Ichiaboveprice() {
double ich=iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANA,0);
if(ich > Bid)
return(true);
else
return(false);
}
 
pekele4u: why its having multiple entry,
  1. You are looking at a signal. Act on a change of signal.
              MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum #1
  2. Don't look at the forming bar, you will get multiple changes as price changes.
 
William Roeder:
  1. You are looking at a signal. Act on a change of signal.
              MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum #1
  2. Don't look at the forming bar, you will get multiple changes as price changes.

Please explain i don't understand