i want to open one position with buy () and close that one position ()

 
this is my code of crossover ema 
//CROSSOVER OF TWO EMA

#include <Trade\Trade.mqh>
CTrade trade;
void OnTick()
  {
    
  double WeeklyTrendArray[],DailyTrendArray[],MAONEARRAY[] ,EMATWOARRAY[];
    
    //Trend emas 
   int WeeklyTrend = iMA(_Symbol,PERIOD_W1,8,0,MODE_EMA,PRICE_CLOSE);
   int DailyTrend = iMA(_Symbol,PERIOD_D1,8,0,MODE_EMA,PRICE_CLOSE);
   
   //emas 
   int MAONE = iMA(_Symbol,_Period,9,0,MODE_SMA,PRICE_CLOSE);
   int TWOEMA = iMA(_Symbol,_Period,200,0,MODE_EMA,PRICE_CLOSE);
   
   ArraySetAsSeries(WeeklyTrendArray,true);
   ArraySetAsSeries(DailyTrendArray,true);
   ArraySetAsSeries(MAONEARRAY,true);
   ArraySetAsSeries(EMATWOARRAY,true);
   
   //ask__BID__PRICE
   
   double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
   double Balance= AccountInfoDouble(ACCOUNT_BALANCE);
   double Equity = AccountInfoDouble(ACCOUNT_EQUITY);
   

   
   //copybuffer for all 
  CopyBuffer(WeeklyTrend,0,0,3,WeeklyTrendArray);
  CopyBuffer(DailyTrend,0,0,3,DailyTrendArray);
  CopyBuffer(MAONE,0,0,3,MAONEARRAY);
  CopyBuffer(TWOEMA,0,0,3,EMATWOARRAY);
   
  
    
   
    
   if((MAONEARRAY[1]>EMATWOARRAY[1])&&(MAONEARRAY[2]<EMATWOARRAY[2]))
   {
      if(PositionsTotal()<=0)
      {
      trade.Buy(0.05,NULL,Ask,0,0.0,NULL);
      Comment("BUY");
      } 
      else {
      
        trade.PositionClose(Symbol());
     
      }
      
    }
   
   
   if((MAONEARRAY[1]<EMATWOARRAY[1])&&(MAONEARRAY[2]>EMATWOARRAY[2]))
   {  
      if(PositionsTotal()<=0)
      {
      trade.Sell(0.05,NULL,Bid,0,0.0,NULL);
      Comment("SELL");
      }
      else {
      trade.PositionClose(Symbol());
      
      }
   }
   
  } 
   
 
please let me know whts wrong with this ea
 

Please read the MQL5 Help!

Forum on trading, automated trading systems and testing trading strategies

How to start with MQL5

Vladimir Karputov, 2020.11.13 06:01

Receiving data from an indicator in an MQL5.

Scheme:

Getting data from indicators in an MQL5 Expert Advisor

An example for the iMA indicator:


Reason: