EA for color MA (BUY when MA Chane to green and Sell When MA change to Red) - page 2

 
ENEZA PETER MKIRAMWENI:

is possible to make it to take single trade per condition

void OnTick()
  {
   static datetime preTime=0;
   datetime curTime=iTime(_Symbol,_Period,0);
   if(preTime==curTime)
      return;
   
   if(!MAColored(MaBuffer))
      return;
      
   double bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
   double ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK); 
   
   int total=PositionsTotal();
   int OrdersBuy=0, OrdersSell=0;
   for(int i=0; i<total; i++)
     {
      //--- parámetros de la orden
      ulong  position_ticket=PositionGetTicket(i);// ticket de la posición
      string position_symbol=PositionGetString(POSITION_SYMBOL); // símbolo
      ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);  // tipo de posición
       if(type==POSITION_TYPE_BUY)
        {
         OrdersBuy++;
        }
       if(type==POSITION_TYPE_SELL)
        {
         OrdersSell++;
        }
     }
   
   if(TYPE_ORDERS==2 || TYPE_ORDERS==1){
   if(MaBuffer[1]==1 && MaBuffer[2]==0  && OrdersSell==0 ){
   Comment("Entro sell",MaBuffer[0]," ",MaBuffer[1]," ",MaBuffer[2]);
   trade.Sell(VOLUME,Symbol(),ask,ask+StopLoss,bid-TakeProfit,"");
   preTime=curTime;}}
   
   if(TYPE_ORDERS==2 || TYPE_ORDERS==0){
   if(MaBuffer[1]==0 && MaBuffer[2]==1  && OrdersBuy==0){
   Comment("Entro buy",MaBuffer[0]," ",MaBuffer[1]," ",MaBuffer[2]);
   trade.Buy(VOLUME,Symbol(),bid,bid-StopLoss,ask+TakeProfit,"");
   preTime=curTime;}}
//---
   //Comment(BufferKalman[1]);
  }
 
Ernst Van Der Merwe:

I tried to compile a get this error


 
ENEZA PETER MKIRAMWENI:

I tried to compile a get this error


The function at the bottom ( MAColored() ) is probably missing.

Files:
 
Ernst Van Der Merwe:

The function at the bottom ( MAColored() ) is probably missing.

thank you

 
Ernst Van Der Merwe:

The function at the bottom ( MAColored() ) is probably missing.

is it possible make it to take trade immediate after color change

Reason: