EA open only one order per chart

 

Hello


I created a 5 and 13 SMA EA but i cannot add the trailing stop on it. The second challenge i want to make this EA to function different charts at the same time.


#include<Trade\Trade.mqh>

CTrade trade;

void OnTick()
{

    double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);  
    double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
    
    double AskSl = Ask - 100 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);
    double AskTp = Ask + 100 * SymbolInfoDouble(_Symbol,SYMBOL_POINT); 
    
    double BidSl = Bid + 100 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);
    double BidTp = Bid - 100 * SymbolInfoDouble(_Symbol,SYMBOL_POINT); 
    

   static int handleSlowMa=iMA(_Symbol,PERIOD_CURRENT,13,0,MODE_SMA,PRICE_CLOSE);
   double slowMaArray[];
   CopyBuffer(handleSlowMa,0,1,2,slowMaArray);
   ArraySetAsSeries(slowMaArray,true);
   
   static int handleFastMa=iMA(_Symbol,PERIOD_CURRENT,5,0,MODE_SMA,PRICE_CLOSE);
   double fastMaArray[];
   CopyBuffer(handleFastMa,0,1,2,fastMaArray);
   ArraySetAsSeries(fastMaArray,true);

 if (fastMaArray[0]>slowMaArray[0] && fastMaArray[1]<slowMaArray[1] && PositionsTotal()<1 )
   trade.Buy(0.01,_Symbol,Ask,AskSl,AskTp,"BUY");


 if (fastMaArray[0]<slowMaArray[0] && fastMaArray[1]>slowMaArray[1] && PositionsTotal()<1 )
   trade.Sell(0.01,_Symbol,Bid,BidSl,BidTp,"SELL");

}