My EA is not back testing and showing no error

I created this CCI and EMA EA and i compiled it and there was no error only for me to backtest it and it seems its not backtesting at the same time its not giving me any error in the journal. The EA buys when CCI is above level 0 and price is above EMA. please help guys.

//±-----------------------------------------------------------------+

//| Mega Trend EA.mq4 |

//| Copyright 2019,objemmanuel Software Corp. |

//| |

//±-----------------------------------------------------------------+

#property version “1.00”

#property strict

int _Sell;

int _Buy;

string symbol=_Symbol;

extern int MovingPeriod=50;

extern int MovingShift =0;

extern int CciPeriod=14;

extern double LotSize=0.01;

extern bool AutoLotSizing=false;

extern double RiskPercent=0;

extern int TakeProfit=0;

extern int StopLoss=0;

extern bool UseTrailingStop=false;

extern int WhenToTrail=40;

extern int TrailAmount=20;

extern bool UsePartialClose=false;

extern int WhenPartialClose=40;

extern int PartialFacor=2;

extern int MagicNumber=22222;

double BSL=0,SSL=0,BTP=0,STP=0;

double pips=0;

//±-----------------------------------------------------------------+

//| Expert initialization function |

//±-----------------------------------------------------------------+

int OnInit()

{

//—

double ticksize=MarketInfo(symbol,MODE_TICKSIZE);

if(ticksize==0.00001 || ticksize==0.001)

  pips=ticksize*10;

else pips=ticksize;

return(0);

//—

return(INIT_SUCCEEDED);

}

//±-----------------------------------------------------------------+

//| Expert deinitialization function |

//±-----------------------------------------------------------------+

void OnDeinit(const int reason)

{

//—

}

//±-----------------------------------------------------------------+

//| Expert tick function |

//±-----------------------------------------------------------------+

void OnTick()

{

int signal = CheckForTrade();

if(IsNewCandle())CheckForTrade();

if (!CheckFilters(signal) && isUseFilters) return;

if(UseTrailingStop)AdjustTrail();

if(UsePartialClose)PartialClose();

}

//±-----------------------------------------------------------------+

bool IsNewCandle()

{

static int BarsOnChart=0;

if(Bars==BarsOnChart)

  return (false);

BarsOnChart=Bars;

return(true);

}

//±-----------------------------------------------------------------+

int CalculateCurrentOrders(int direction)

{

if(StopLoss!=0){

  BSL=NormalizeDouble(Ask-StopLoss*pips,Digits);

  SSL=NormalizeDouble(Bid+StopLoss*pips,Digits);

     }

if(StopLoss!=0 && AutoLotSizing){

  double pips_to_bsl=StopLoss*pips;

  double Equity=AccountEquity();

  double RiskedAmount=Equity*RiskPercent*0.01;

  LotSize=(RiskedAmount/(pips_to_bsl/pips))/10;

    }

if(TakeProfit!=0){

  BTP=NormalizeDouble(Ask+TakeProfit*pips,Digits);

  STP=NormalizeDouble(Bid-TakeProfit*pips,Digits);

   }

if(direction==_Buy && OpenOrdersThisPairBuy(symbol)==0 && OpenOrdersThisPairSell(symbol)==0)

 int BuyTicket=OrderSend(symbol,OP_BUY,LotSize,Ask,3,BSL,BTP,NULL,MagicNumber,0,clrGreen);

if(direction==_Sell && OpenOrdersThisPairBuy(symbol)==0 && OpenOrdersThisPairSell(symbol)==0)

   int SellTicket=OrderSend(symbol,OP_SELL,LotSize,Bid,3,SSL,STP,NULL,MagicNumber,0,clrRed); 

for(int b=OrdersTotal()-1;b>=0;b–)

{

if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))

  if(OrderMagicNumber()==MagicNumber && OrderSymbol()==symbol)

    {

     

     double lots= OrderLots();

     int ticket = OrderTicket();

        if(OrderType()==OP_BUY && direction==_Sell)

{

           if(OrderClose(ticket,lots,Bid,3,clrRed))

              return _Sell;

              

          }

        else if(OrderType()==OP_SELL && direction==_Buy)

           if(OrderClose(ticket,lots,Ask,3,clrRed))

              return _Buy;

              

    }

 }

 return 0;

}

//±------------------------------------------------------------------+

int OpenOrdersThisPairBuy(string SYMBOL)

{

int total=0;

for(int i=OrdersTotal()-1; i>=0; i–)

 {

  if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))Print("error Selecting order ",GetLastError());

  if(OrderType()==0 && OrderMagicNumber()==MagicNumber && OrderSymbol()==SYMBOL)

   total++;

 }

return (total);

}

//±------------------------------------------------------------------+

int OpenOrdersThisPairSell(string SYMBOL)

{

int total=0;

for(int i=OrdersTotal()-1; i>=0; i–)

 {

  if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))Print("error Selecting order ",GetLastError());

  if(OrderType()==1 && OrderMagicNumber()==MagicNumber && OrderSymbol()==SYMBOL)

  total++;

 }

return (total);

}

//±------------------------------------------------------------------+

void AdjustTrail()

{

  for(int b=OrdersTotal()-1;b>=0;b--)

    {

     if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))

       if(OrderMagicNumber()==MagicNumber)

             if(OrderSymbol()==symbol)

                   if(OrderType()==OP_BUY)

                       if(Bid-OrderOpenPrice()>WhenToTrail*pips) 

                          if(OrderStopLoss()<Bid-TrailAmount*pips || OrderStopLoss()==0)

                             if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(TrailAmount*pips),OrderTakeProfit(),0,CLR_NONE))

                               Print("error modifying buy order ",GetLastError());



     }

  for(int s=OrdersTotal()-1;s>=0;s--)

    {

     if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES))

        if(OrderMagicNumber()== MagicNumber)

           if(OrderSymbol()==symbol)

              if(OrderType()==OP_SELL)

                   if(OrderOpenPrice()-Ask>WhenToTrail*pips)

                          if(OrderStopLoss()>Ask+TrailAmount*pips || OrderStopLoss()==0)

                             if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(TrailAmount*pips),OrderTakeProfit(),0,CLR_NONE))

                                Print("error modifying sell order ",GetLastError());

     }

}

//±------------------------------------------------------------------+

int CheckForTrade(){

double x1,x2;

x1 = iCCI(Symbol(),_Period,14,PRICE_TYPICAL,0);

x2 = iCCI(Symbol(),_Period,14,PRICE_TYPICAL,1);

if(x2>0 && x2!=EMPTY_VALUE)

           return _Buy;

if(x1<0 && x2!=EMPTY_VALUE)

          return _Sell;

return 0;         

}

extern bool isUseFilters = true;

int CheckFilters (int signal) { //true - you can trade

double ma;

if(signal==_Buy) {

ma= iMA(NULL,0,MovingPeriod,MovingShift,MODE_EMA,PRICE_TYPICAL,0); }

if(signal==_Sell) {

ma= iMA(NULL,0,MovingPeriod,MovingShift,MODE_EMA,PRICE_TYPICAL,0); }

return true;

}

//±-----------------------------------------------------------------+

void PartialClose()

{

for(int b=OrdersTotal()-1;b>=0;b--){

  if(!OrderSelect(b,SELECT_BY_POS,MODE_TRADES))printf("unable to select an order");

     int type=OrderType();

     double lots= OrderLots();

     int ticket = OrderTicket();

     if(OrderMagicNumber()==MagicNumber && OrderSymbol()==symbol && lots!=0.01)

       {

        if(type==OP_BUY) 

         if(Bid-OrderOpenPrice()>(TotalCloseTrades(0,OrderOpenPrice())+1)*WhenPartialClose*pips)

          {

                if(!OrderClose(ticket,lots/PartialFacor,Bid,3,clrRed))

                   printf("failure to close the order ");

          }

if(type==OP_SELL)

        if(OrderOpenPrice()-Ask>(TotalCloseTrades(1,OrderOpenPrice())+1)*WhenPartialClose*pips)

               if(!OrderClose(ticket,lots/PartialFacor,Ask,3,clrRed))

                  printf("failure to close the order ");      

       }

    }

 for(int b=OrdersTotal()-1;b>=0;b--){

  if(!OrderSelect(b,SELECT_BY_POS,MODE_TRADES))printf("unable to select an order"); 

     int type=OrderType();

     double lots= OrderLots();

     int ticket = OrderTicket();

     if(OrderMagicNumber()==MagicNumber && OrderSymbol()==symbol && lots==0.01)

       {

        if(type==OP_BUY) 

         if(Bid-OrderOpenPrice()>(TotalCloseTrades(0,OrderOpenPrice())+1)*WhenPartialClose*pips)

          {

               if(!OrderClose(ticket,lots,Bid,3,clrRed))

                  printf("failure to close the order ");

          }

       if(type==OP_SELL)

        if(OrderOpenPrice()-Ask>(TotalCloseTrades(1,OrderOpenPrice())+1)*WhenPartialClose*pips)

               if(!OrderClose(ticket,lots,Ask,3,clrRed))

                  printf("failure to close the order ");      

       }

    }

}

//±------------------------------------------------------------------+

int TotalCloseTrades(int Order,double OpenPrice){

int Total=0;

for(int i=OrdersHistoryTotal()-1;i>=0;i--)

   {

    if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))

     if(OrderType()==Order && OrderSymbol()==symbol && OrderOpenPrice()==OpenPrice && OrderMagicNumber()==MagicNumber)

             Total++;             

              }

  return(Total);   

}

//±------------------------------------------------------------------+

This is the code thanks guys

hi Johnsamy,

few issues…
signals… Int(CheckForTrade) you are trying to return _Buy &_Sell but they always have 0 value.

Logic… Your logic is basically done in the OnTick() function. There is no logic to to open a trade. you need logic like if signal =0 buy … if signal =1 sell.

Maybe try to find a good template to start with where you can just adjust/add indicators to make your ea?

Have fun!