Coding a news filter into EA

Back to topics list To post a new topic, please log in or register
avatar
8
ivoes 2011.08.09 16:24
 

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)
 
avatar
14167
RaptorUK 2011.08.09 17:21 #
 

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; ?

 
avatar
8
ivoes 2011.08.09 17:29 #
 
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.
 
avatar
14167
RaptorUK 2011.08.09 18:10 #
 
You had better start learning then if you want to have your own EA.
avatar
8
ivoes 2011.08.09 19:00 #
 
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.
 
avatar
14167
RaptorUK 2011.08.09 19:12 #
 
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.
avatar
8
ivoes 2011.08.09 19:21 #
 
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.
avatar
1
mustafamagdy 2016.08.10 12:35 #
 
Can you please attach FFCal that work with iCustom calls ?
avatar
Moderator
3406
GumRai 2016.08.10 12:44 #
 
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.

Back to topics list  

To add comments, please log in or register