• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 6:55pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 6:55pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

required to function call function 2 replies

EAs: Spread filter VS News filter 3 replies

please code news filter into EA 2 replies

stop loss function and edit time function for Breakout EA 1 reply

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe

News Function Filter

  • Post #1
  • Quote
  • First Post: Apr 28, 2007 5:41pm Apr 28, 2007 5:41pm
  •  Kurka Fund
  • Joined Mar 2007 | Status: Member | 437 Posts
I am still trying to get a working function that filters the news out of my EA. I tried using the FFCAL, but realizied that I do not want to rely on a website being up for my ea to work. so I then tried using a CSV file... But i am having a few problems. here is my code....

The goal here is to ...
1. Set DisableTrading = true and Newstime = true 30 min prior to the announcemet and keep them true until 30 min after the announcement.
2. Kill my open positions 10 min prior to the announcement.

PHP Code:

//External parameters ================================
extern string    S3                 = "==== NEWS SETTINGS ====";
extern bool    FilterNews     = true; //Set to false for testing 
extern int        MinsPrior        = 30;
extern int        MinsPost          = 30;
extern int     MinsKill       = 10;
extern   string   FileName        = "News.csv";   
extern   bool     Filter_High     = true;        
extern   bool     Filter_Medium   = true;       
extern   bool     Filter_Low      = false;      
extern   bool     Filter_USD      = true;         
extern   bool     Filter_CAD      = true;         
extern   bool     Filter_EUR      = true;         
extern   bool     Filter_GBP      = true;        
extern   bool     Filter_CHF      = true;        
extern   bool     Filter_JPY      = true;        
extern   bool     Filter_AUD      = true;       
extern   bool     Filter_NZD      = true;  

// Internal parameters ================================

bool NewsTime = false;
int  handle;
int  eCount;          
static 
datetime eTime[9999];         
static 
int      eImpact[9999];       
static 
string   eCurrency[9999];     
static 
string   eText1[9999];      

// The function =====================================

// ===================================== NEWS TIME =============================================================

void eNewsTime(){

    
int iHoursCache = 2;
    static 
datetime dtLastRead = 0;     // var to hold last file read time
    
if (dtLastRead + iHoursCache*60 < TimeCurrent()) {

   
handle = FileOpen(FileName, FILE_CSV|FILE_READ,';');          // Open NEWS.CSV
   
if(handle==0){Comment("File "+FileName+" not found.");}

   for(
eCount = 0; !FileIsEnding(handle); eCount++){           // Read from NEWS.CSV; one line per event

           
eTime[eCount]    = StrToTime(FileReadString(handle));     // Event date/time
           
eCurrency[eCount] = FileReadString(handle);                // Currency
           
eImpact[eCount] = StrToInteger(FileReadString(handle));  // Impact: 1=low; 2=medium; 3=High
           
eText1[eCount] = FileReadString(handle);                // Description
           
}
     
           

   }
}

// And the logic ===========================================

// in the start...

 // Update the news arrays
   
eNewsTime();
      if ((
eImpact[eCount] == 1 && Filter_Low == TRUE)||(eImpact[eCount] == 2 && Filter_Medium == TRUE)||(eImpact[eCount] == 3 && Filter_High == TRUE)){
      if ((
eCurrency[eCount] == "USD" && Filter_USD == true)||
         (
eCurrency[eCount] == "CAD" && Filter_CAD == true)||
         (
eCurrency[eCount] == "EUR" && Filter_EUR == true)||
         (
eCurrency[eCount] == "GBP" && Filter_GBP == true)||   
         (
eCurrency[eCount] == "CHF" && Filter_CHF == true)||
         (
eCurrency[eCount] == "JPY" && Filter_JPY == true)||
         (
eCurrency[eCount] == "AUD" && Filter_AUD == true)||
         (
eCurrency[eCount] == "NZD" && Filter_NZD == true)){ 
  
   
//The Skip News Function
      
if (TimeCurrent() >= eTime[eCount] - (MinsPrior*60)){
          
DisableTrading = true;
          
NewsTime = true;
          Print (
eText1[eCount]);
          }
      if (
TimeCurrent() <= eTime[eCount] + (MinsPost*60)){
         
DisableTrading = true;
         
NewsTime = true;
         }
      if (
TimeCurrent() >= eTime[eCount] - (MinsKill*60)){
         
DisableTrading = true;
         
NewsTime = true;
         
KillLongs();
         
KillShorts();
         }
      }
    } 
And this is what the News.csv file looks like

PHP Code:

"2007.04.12 05:00","EUR",3,"Q4 GDP q/q",0.90%,0.60%,
"2007.04.12 07:45","EUR",3,"ECB Monetary Policy Decision",3.75%,3.75%,
"2007.04.12 08:30","USD",3,"Weekly Jobless Claims","320.0k","321.0k",
"2007.04.13 05:00","EUR",3,"February Industrial Production y/y",4.20%,3.70%,
"2007.04.13 05:00","EUR",3,"February Industrial Production m/m",0.40%,-0.20%,
"2007.04.13 08:30","CAD",3,"February Trade Balance","C$6.0 bln ","C$6.35 bln",
"2007.04.13 08:30","USD",3,"March PPI y/y","n/f",2.50%,
"2007.04.13 08:30","USD",3,"March core PPI m/m",0.20%,0.40%,
"2007.04.13 08:30","USD",3,"March PPI m/m",0.70%,1.30%,
"2007.04.13 08:30","USD",3,"February Trade Deficit","$-60.0 bln","$-59.12 bln",
"2007.04.13 10:00","USD",3,"April University of Michigan Sentiment",87.5,88.4,
"2007.04.16 00:30","JPY",3,"February Industrial Production revised m/m",-0.20%,-0.20%,
"2007.04.16 00:30","JPY",3,"February Capacity Utilization","n/f",-2.90%,
"2007.04.16 02:00","EUR",3,"Germany March CPI final m/m",0.30%,0.40%,
"2007.04.16 02:00","EUR",3,"Germany March HICP final y/y",2.10%,1.90%,
"2007.04.16 02:00","EUR",3,"Germany March HICP final m/m",0.30%,0.50%,
"2007.04.16 02:00","EUR",3,"Germany March CPI final y/y",1.90%,1.60%,
"2007.04.16 04:30","GBP",3,"March core PPI y/y",2.70%,2.70%,
"2007.04.16 04:30","GBP",3,"March core PPI m/m",0.20%,0.50%,
"2007.04.16 05:00","EUR",3,"Eurozone March HICP final y/y",1.90%,1.80%,
"2007.04.16 05:00","EUR",3,"Eurozone March HICP final m/m",0.60%,0.30%,
"2007.04.16 08:30","USD",3,"March Retail Sales",0.60%,0.10%,
"2007.04.16 08:30","USD",3,"April NY Fed Manufacturing Survey",7.5,1.85,
"2007.04.16 08:30","USD",3,"March Retail Sales excl Autos",0.90%,-0.10%,
"2007.04.16 09:00","USD",3,"February Net Treasury Int'l Capital Flows (TICS)","$76.0 bln","$74.6 bln",
"2007.04.16 10:00","USD",3,"February Business Inventories",0.30%,0.20%,
"2007.04.16 14:00","USD",3,"April NAHB Survey (Housing)",35,36,
"2007.04.17 01:00","JPY",3,"March Confidence Index","n/f",48.4,
"2007.04.17 04:30","GBP",3,"March RPI-X y/y",3.70%,3.70%,
"2007.04.17 04:30","GBP",3,"March RPI y/y",4.60%,4.60%,
"2007.04.17 04:30","GBP",3,"March CPI y/y",2.80%,2.80%,
"2007.04.17 04:30","GBP",3,"March RPI m/m",0.40%,0.70%,
"2007.04.17 04:30","GBP",3,"March CPI m/m",0.30%,0.40%,
"2007.04.17 05:00","EUR",3,"Eurozone February Trade Balance","-5.0 bln euros","-7.8 bln euros",
"2007.04.17 05:00","EUR",3,"Germany April ZEW Survey Index",10,5.8,
"2007.04.17 05:00","EUR",3,"Germany April ZEW Survey Current Conditions",69,69.2,
"2007.04.17 08:30","CAD",3,"February Manufacturing Shipments",0.50%,-2.10%,
"2007.04.17 08:30","USD",3,"March Housing Starts","1.495 mln units","1.525 mln units",
"2007.04.17 08:30","USD",3,"March core CPI y/y",2.60%,2.70%,
"2007.04.17 08:30","USD",3,"March core CPI m/m",0.20%,0.20%,
"2007.04.17 08:30","USD",3,"March CPI y/y",2.80%,2.40%,
"2007.04.17 08:30","USD",3,"March CPI m/m ",0.60%,0.40%,
"2007.04.17 08:30","USD",3,"March Building Permits","1.51 mln units","1.532 mln units",
"2007.04.17 09:15","USD",3,"March Industrial Production",0.10%,1.00%,
"2007.04.17 09:15","USD",3,"March Capacity Utilization",81.90%,82.00%,
"2007.04.18 01:00","JPY",3,"February Leading Indicators","n/f",30,
"2007.04.18 01:00","JPY",3,"February Coincident Indicator","n/f",16.7,
"2007.04.18 04:30","GBP",3,"February ILO Unemployment Rate",5.50%,5.50%,
"2007.04.18 04:30","GBP",3,"March Claimant Count","-5.0k","-3.8k",
"2007.04.18 04:30","GBP",3,"April MPC Minutes",,,
"2007.04.18 04:30","GBP",3,"February Average Earnings 3-mth",4.30%,4.20%,
"2007.04.18 19:50","JPY",3,"February Tertiary Index",-0.40%,1.60%,
"2007.04.19 02:00","EUR",3,"Germany March PPI y/y",2.70%,2.80%,
"2007.04.19 02:00","EUR",3,"Germany March PPI m/m ",0.40%,0.30%,
"2007.04.19 07:00","CAD",3,"March core CPI y/y",2.30%,2.40%,
"2007.04.19 07:00","CAD",3,"March core CPI m/m",0.20%,0.50%,
"2007.04.19 07:00","CAD",3,"March CPI y/y",2.20%,2.00%,
"2007.04.19 07:00","CAD",3,"March CPI m/m ",0.70%,0.70%,
"2007.04.19 08:30","CAD",3,"February Wholesale Trade m/m",0.10%,-0.50%,
"2007.04.19 08:30","USD",3,"Weekly Jobless Claims","323k","342k",
"2007.04.19 10:00","USD",3,"March Leading Economic Indicators",0.10%,-0.50%,
"2007.04.19 12:00","USD",3,"April Philadelphia Fed Survey",2,0.2,
"2007.04.19 19:50","JPY",3,"February All-Industry Survey",-0.30%,0.70%,
"2007.04.20 04:30","GBP",3,"March Retail Sales m/m",0.50%,1.40%,
"2007.04.20 08:30","CAD",3,"February Retail Sales ex-autos m/m",0.20%,0.30%,
"2007.04.20 08:30","CAD",3,"February Retail Sales m/m",-0.10%,-0.20%,
"2007.04.24 04:00","EUR",3,"February Eurozone Current Account Balance","2.0 bln euros","-6.0 bln euros",
"2007.04.24 05:00","EUR",3,"February Industrial Orders m/m",1.10%,-0.20%,
"2007.04.24 05:00","EUR",3,"February Eurozone Industrial Orders y/y",7.80%,12.00%,
"2007.04.24 08:30","CAD",3,"March Leading Indicator",0.50%,0.70%,
"2007.04.24 09:00","CAD",3,"Bank of Canada Monetary Policy Decision",4.25%,4.25%,
"2007.04.24 10:00","USD",3,"April Consumer Confidence",105,107.2,
"2007.04.24 10:00","USD",3,"April Existing Home Sales","6.45 mln units","6.69 mln units",
"2007.04.24 19:50","JPY",3,"March Trade Balance","n/f","979.6 bln yen",
"2007.04.25 04:00","EUR",3,"April Germany IFO Index",108,107.7,
"2007.04.25 04:00","EUR",3,"April Germany IFO Current Conditions",112.6,112.4,
"2007.04.25 04:30","GBP",3,"Q1 GDP y/y",2.80%,3.00%,
"2007.04.25 04:30","GBP",3,"Q1 GDP q/q",0.60%,0.70%,
"2007.04.25 08:30","USD",3,"March Durable Goods Orders",2.50%,1.70%,
"2007.04.25 10:00","USD",3,"March New Home Sales","888k units","848k units",
"2007.04.26 08:30","USD",3,"Weekly Jobless Claims","330k","339k",
"2007.04.26 19:30","JPY",3,"March Industrial Production m/m",1.00%,0.70%,
"2007.04.26 19:30","JPY",3,"March Unemployment Rate ",4.00%,4.00%,
"2007.04.26 19:30","JPY",3,"April Manufacturing PMI","n/f",52.5,
"2007.04.26 19:30","JPY",3,"March Jobs-to-Applicants Ratio",1.05,1.05,
"2007.04.26 19:30","JPY",3,"March Household Spending",0.80%,1.30%,
"2007.04.26 19:30","JPY",3,"March CPI y/y",-0.20%,-0.10%,
"2007.04.26 19:50","JPY",3,"March Retail Sales",-0.60%,-0.20%,
"2007.04.27 01:00","JPY",3,"March Housing Starts ",-1.10%,-9.90%,
"2007.04.27 08:30","USD",3,"Q1 PCE",3.30%,-1.00%,
"2007.04.27 08:30","USD",3,"Q1 Employment Cost Index",0.90%,0.80%,
"2007.04.27 08:30","USD",3,"Q1 core PCE",2.10%,1.80%,
"2007.04.27 08:30","USD",3,"Q1 GDP advanced ",1.80%,2.50%,
"2007.04.27 10:00","USD",3,"April University of Michigan Survey",85.2,88.4, 
See attached...

Here is the Error that I keep getting

2007.04.28 14:05:43 2007.01.02 13:39 Kurka Trader - Ergodic v_02 wNews: invalid handle -1 in FileIsEnding

Waht is wrong with the code ? Thanks...
Keep it simple stoopid....
  • Post #2
  • Quote
  • Apr 28, 2007 6:06pm Apr 28, 2007 6:06pm
  •  Kurka Fund
  • Joined Mar 2007 | Status: Member | 437 Posts
OK i realized that I was using

handle = FileOpen(FileName, FILE_CSV|FILE_READ,';');

when my deliminator is ","

I changed it and still get the same thing...GRR

handle = FileOpen(FileName, FILE_CSV|FILE_READ,',');
Keep it simple stoopid....
 
 
  • Post #3
  • Quote
  • Last Post: Apr 29, 2007 4:27pm Apr 29, 2007 4:27pm
  •  hanover
  • Joined Sep 2006 | Status: ... | 8,081 Posts
Kurka, this is just a guess, but is the problem being caused by the comma at the end of each line in your news.csv file?

The code inside your FOR loop only allows for 4 items (time, currency, impact, text) per line, but the comma could be "creating" an (empty) 5th item at the end of each line.

Good luck
David
 
 
  • Platform Tech
  • /
  • News Function Filter
  • Reply to Thread
0 traders viewing now
Top of Page
Forex Factory Blog Updated: Alerting All Members
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2022