Page 1 of 2 12 LastLast
Results 1 to 10 of 17
 6 Attachment(s)    

Thread: Add a news filter

  1. #1
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default Add a news filter

    Here is a code for the news filter.

    Extern parameters :


    Code:
    extern string S8="---------------- News Filter";
    
    extern bool UseNewsFilter=false;//|---------------use news filter
    extern int StartNewsFilter=0;//|------------------start news filter
    extern int EndNewsFilter=24;//|-------------------end news filter
    extern int MinsUntilNews=30;//|-------------------minutes until news
    extern int MinsAfterNews=30;//|-------------------minutes after news
    extern string News1="3=High; 2=Medium; 1=Low";//|-news impact information
    extern int NewsImpact=3;//|-----------------------news impact
    extern bool CloseProfitableTrades=true;//|--------close profitable trades before the news
    extern bool CloseAllTrades=true;//|---------------close all the trades before the news
    extern bool ShowAlerts=true;//|-------------------show alerts
    Conditions :

    Code:
    &&(Hour()>StartNewsFilter&&Hour()<EndNewsFilter&&UseNewsFilter==false||(UseNewsFilter&&NewsFilterCheck()))
    Functions :

    Code:
    //|---------close profitable trades before news
    
    void CloseProfitableTradesBeforeNews()
    {
       for(int cc=0;cc<OrdersTotal();cc++)
       { 
          if(OrderType()==OP_BUY || OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
          {
             if(OrderProfit()>=0)bool ticket=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),10,CLR_NONE);
               return;
          }
       }
    }
    
    //|---------close existing trades
    
    bool CloseExistingTrades(int type)
    {
       if(OrdersTotal()==0)return(true);
       for(int cc=0;cc<OrdersTotal();cc++)
       {
          OrderSelect(cc,SELECT_BY_POS);
          if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType()==type)
          {
             bool result=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,CLR_NONE);
             if(!result)
             {
                int err=GetLastError();
                if(ShowAlerts)Alert(OrderTicket()," ",Symbol()," OrderClose failed with error(",err,"). ");
                Print(OrderTicket()," ",Symbol()," OrderClose failed with error(",err,"). ");
                return(false);
             }
             else 
             {
                if(ShowAlerts)Alert(OrderTicket()," ",Symbol()," OrderClose");
                Print(OrderTicket()," ",Symbol(), "OrderClose");            
                return(true);
             }
          }
       }
       return(true);
    }
    
    //|---------news impact
    
    string Num2Impact(int impact)
    {
       if(impact==3)return("HIGH IMPACT");
       if(impact==2)return("MED IMPACT");
       if(impact==1)return("LOW IMPACT");
       else return("");
    }
    
    //|---------news filter check
    
    bool NewsFilterCheck()
    {
       if(!IsTesting())
       {
          int  minutesUntilNextEvent=iCustom(NULL,0,"FFCal",true,true,false,true,true,1,1);
          int  minutesSincePrecEvent=iCustom(NULL,0,"FFCal",true,true,false,true,true,1,0);
          int impactOfPrecEvent=iCustom(NULL,0,"FFCal",true,true,false,true,true,2,0);
          datetime dTime=minutesUntilNextEvent*60;
          string sTime=TimeToStr(dTime,TIME_MINUTES);
          string sText;
          bool TradeAllowed=true;
          
          if(minutesUntilNextEvent>MinsUntilNews&&(impactOfPrecEvent<NewsImpact||(impactOfPrecEvent>=NewsImpact&&minutesSincePrecEvent>MinsAfterNews)))
          {
             sText=StringConcatenate("No News within the next ",sTime);
          }
          else
          {
             int impactOfNextEvent=iCustom(NULL,0,"FFCal",true,true,false,true,true,2,1);
             string sImpact=Num2Impact(impactOfNextEvent);
             if(StringLen(sImpact)>0)sImpact="["+sImpact+"] ";
             sText=sImpact+"News in "+sTime;
             if(impactOfNextEvent>=NewsImpact)
             {
                TradeAllowed=false;
                if(CloseProfitableTrades && OrdersTotal()>0)CloseProfitableTradesBeforeNews();
                if(CloseAllTrades && OrdersTotal()>0){CloseExistingTrades(OP_BUY);CloseExistingTrades(OP_SELL);}
             }
          }
          return(TradeAllowed);
       }
    }
    Put FFCal.mq4 in the indicators folder.
    Put WebGet.dll in the libraries folder.

    If you have a better code, don't hesitate to post.
    Attached Files Attached Files

  2. #2

    Default FFCal to trigger new position

    Hi Funyoo,

    How can I use FFCal to trigger new position 30 mins before high impact news? Thanks in advance.

    Regards,
    Jdk
    Last edited by jidonk; 06-18-2009 at 07:45.

  3. #3
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default

    Quote Originally Posted by jidonk View Post
    Hi Funyoo,

    How can I use FFCal to trigger new position 30 mins before high impact news? Thanks in advance.

    Regards,
    Jdk
    Hello jidonk and everybody,

    Here is an easier way to do

    After the extern parameters, add :

    Code:
    extern bool AvoidNews=true;
    extern int MinimumImpact=1;
    extern int MinsBeforeNews=30;
    extern int MinsAfterNews=30;
    At the beginning of the start body, add :

    Code:
       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;
          }
       }
    In each entry conditions, add :

    Code:
    && ContinueTrading
    Finally copy the two attached files in the indicators folder.
    Attached Files Attached Files

  4. #4

    Default

    Hi Funyoo,

    Thanks for the reply.
    I'm not trying to avoid the news. Instead, I want to use FFCal news time to open a new buy/sell position. For example if there is a high impact news at 10:00, the EA should trigger a new buy/sell at 09:30. (The time on FFCal will be my only condition to open new position).

    Again, thank a lot.

    Regards,
    Jdk

  5. #5

    Default

    Funyoo,

    Can you help me with this?

    Thanks & Regards
    Jdk

    Quote Originally Posted by jidonk View Post
    Hi Funyoo,

    Thanks for the reply.
    I'm not trying to avoid the news. Instead, I want to use FFCal news time to open a new buy/sell position. For example if there is a high impact news at 10:00, the EA should trigger a new buy/sell at 09:30. (The time on FFCal will be my only condition to open new position).

    Again, thank a lot.

    Regards,
    Jdk

  6. #6
    Junior Member
    Join Date
    Jan 2009
    Posts
    28

    Default FFCAL Update

    FYI, for anyone who is using News Avoidance in your EA. You will need to update the web adress within the code to make it work.

    Here is the link to the post from Twee.
    Forex Factory - View Single Post - FF Calendar Indicator for MT
    -David T-
    Skype: verbtheory
    Trades and insights:
    http://manualforextrader.com
    Verbtheory's Day Break System v1.0
    -----------------------------------------------
    "Only when the tide goes out do you discover who's been swimming naked." - Warren Buffett

  7. #7

    Default

    Question, so with this code will not trade 30 mins. before and 30 mins. after news, right?

    TIA

    Quote Originally Posted by funyoo View Post
    Hello jidonk and everybody,

    Here is an easier way to do

    After the extern parameters, add :

    Code:
    extern bool AvoidNews=true;
    extern int MinimumImpact=1;
    extern int MinsBeforeNews=30;
    extern int MinsAfterNews=30;
    At the beginning of the start body, add :

    Code:
       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;
          }
       }
    In each entry conditions, add :

    Code:
    && ContinueTrading
    Finally copy the two attached files in the indicators folder.

  8. #8
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default

    Quote Originally Posted by altoronto View Post
    Question, so with this code will not trade 30 mins. before and 30 mins. after news, right?

    TIA
    Hi altoronto,

    That's correct.

  9. #9
    Junior Member
    Join Date
    Jan 2009
    Posts
    18

    Default

    thank you for this code

  10. #10

    Default

    Hello funyoo :

    You add the "new" news filter to the Donchian Scalper. In any way Iīve achieved to make the filter news to work. Not in forward not in backtest. Itīs simply doing nothing. May you check it ?
    Regards

Similar Threads

  1. News filter without any indicator
    By fxtester in forum MQL programming
    Replies: 5
    Last Post: 07-24-2015, 03:43
  2. New news filter with ffcal
    By fxtester in forum MQL programming
    Replies: 1
    Last Post: 08-20-2014, 14:10
  3. (REQ) News Filter
    By YOAV3211 in forum MQL programming
    Replies: 0
    Last Post: 03-16-2013, 18:42
  4. TSD News filter code
    By dave_rimmer in forum MQL programming
    Replies: 0
    Last Post: 01-29-2011, 20:44

Tags for this Thread

add, backtest, coding, copy, date, donchian, high, high impact, indicator, indicators, low, mq4, news, scalper, thank you, time

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •