Download MetaTrader 5
To add comments, please log in or register
Do you want to become a well-known developer? Execute the orders of traders in the Freelance service!
Ivaylo
30
Ivaylo 2011.08.09 14: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)
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2011.08.09 15: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; ?

Ivaylo
30
Ivaylo 2011.08.09 15: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.
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2011.08.09 16:10  
You had better start learning then if you want to have your own EA.
Ivaylo
30
Ivaylo 2011.08.09 17: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.
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2011.08.09 17: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.
Ivaylo
30
Ivaylo 2011.08.09 17: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.
Mustafa Magdy
1
Mustafa Magdy 2016.08.10 10:35  
Can you please attach FFCal that work with iCustom calls ?
Keith Watford
Moderator
7990
Keith Watford 2016.08.10 10: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.

/
To add comments, please log in or register