Coding a news filter into EA

 

Hello guys.

I need help in coding my EA, so it can avoid news. I tried ti do it myself and what happens, is that the EA opens trades (inside news time), and closes them immediately.

Here is the code:


Externs:

extern bool AvoidNews=true;
extern int MinimumImpact=1;
extern int MinsBeforeNews=30;
extern int MinsAfterNews=30;

Avoid news function:

//|-------Avoid news

   bool ContinueTrading=true;
   if(AvoidNews)
   {
      static int PrevMinute=-1;  
   
      int MinSinceNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,1,0);
      int MinToNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,1,1);
         
      int ImpactSinceNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,2,0);
      int ImpactToNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,2,1);

      if(Minute()!=PrevMinute)
      {
          PrevMinute=Minute();
          if((MinToNews<=MinsBeforeNews &&  ImpactToNews>=MinimumImpact) || (MinSinceNews<=MinsAfterNews && ImpactSinceNews>=MinimumImpact))ContinueTrading=false;
      }
   }

Close all trades when we are in the news range:

//|---------close trades

   if(ContinueTrading==false)
   {
   int total = OrdersTotal();
  for(int q=total-1;q>=0;q--)
  {
    OrderSelect(q, SELECT_BY_POS);
    int type   = OrderType();

    bool result = false;
    
    switch(type)
    {
      //Close opened long positions
      case OP_BUY       : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
                          break;
      
      //Close opened short positions
      case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
                          break;

      //Close pending orders
      case OP_BUYLIMIT  :
      case OP_BUYSTOP   :
      case OP_SELLLIMIT :
      case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );
    }
    
    if(result == false)
    {
      Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
      Sleep(3000);
    }  
  }
  
  return(0);
}

In entry conditions:

 if(SignalBUY=="true"&&NewBarBuy()&&ContinueTrading)
 

After this happens . . . .

  
 if((MinToNews<=MinsBeforeNews &&  ImpactToNews>=MinimumImpact) || (MinSinceNews<=MinsAfterNews && ImpactSinceNews>=MinimumImpact))ContinueTrading=false;

. . . and ContinueTrading=true; how does it get set to ContinueTrading=false; ?

 
RaptorUK:

After this happens . . . .

. . . and ContinueTrading=true; how does it get set to ContinueTrading=false; ?


I have no coding skills. This code was copied, but I can`t add it as it should be. Please correct it, i`m trying to do it for weeks.
 
You had better start learning then if you want to have your own EA.
 
RaptorUK:
You had better start learning then if you want to have your own EA.

I learned a lot of things, but still can`t realize what`s wrong here. The EA is not mine, it`s free, I just want to modify it.
 
ivoes:

I learned a lot of things, but still can`t realize what`s wrong here. The EA is not mine, it`s free, I just want to modify it.
Post the whole EA code then, maybe someone will help.
 
RaptorUK:
Post the whole EA code then, maybe someone will help.

Here it is with and without my code for news. It says it`s too long to be posted like code.
 
Can you please attach FFCal that work with iCustom calls ?
 
mustafamagdy:
Can you please attach FFCal that work with iCustom calls ?

As far as I know, FFcal doesn't use buffers, but I haven't checked.

If no buffers, an iCustom call is useless.

Reason: