Avoiding trade during news time!!

 

Is there anyone to help me?!!
Considering to these codes,I’d like to avoid trading during news events, and I’ve tried to read from file like that attached here,on the other hand, I’ve made a simple example for trade rule but I don’t know why my cycle ( For()….. )that I used here didn’t work correctly.
Further information is,I’ve tried to test my problem and I’ve been noticed that its loop not work correctly,I mean it reads file but when it should do something it does not work truly .?!?
Do u have any advice for me or u have another program to do that?!!
Thank you so much in advance my mate.

*Plz rename the file "ForexTSD_2008-01-07.txt' TO "ForexTSD_2008-01-07.csv" after downloading.*

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link "Erfan_Foroutan@hotmail.com"


#include <stdlib.mqh>

extern double LotSize=0.1;
extern int TakeProfit=15;
extern int StopLoss=15;

extern int shift=1;

//---- input parameters
extern string ExpertName = "Test";


string sDate[1000]; // Date
string sTime[1000]; // Time
string sSymbol[1000]; // Currency
string sDescription[1000]; // Description
string sRating[1000]; // Rating
string sActual[1000]; // Actual value
string sForecast[1000]; // Forecast value
string sPrevious[1000]; // Previous value
string sImpact[1000];
datetime dt[1000];

int NewsNum;
int TimeZone;
extern int TimeGap=1;

string fName="ForexTSD_2008-01-07.csv";

bool result=false;
int c,i;
int z;

int p[100];
int t;
datetime DN;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//---
ReadCalendar(fName);

//-------------------------------------
return(0);
}
//+-----------------------------------------------------------------------------------------------------------------------
//|Read FILE
//+-----------------------------
void ReadCalendar(string fName)
{
int i, handle;
bool rates=false;

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



if(handle<1)
{
Print("File not found ", GetLastError());
return(false);
}

else
if(handle>=1)
{
i=0;
NewsNum=0;
while(FileIsEnding(handle)== false)
{
sDate[i]=FileReadString(handle); // Date
sTime[i]=FileReadString(handle); // Time
sSymbol[i]=FileReadString(handle); // Currency
sDescription[i]=FileReadString(handle); // Description
sRating[i]=FileReadString(handle); // Rating
sActual[i]=FileReadString(handle);
sForecast[i]=FileReadString(handle);
sPrevious[i]=FileReadString(handle);

dt[i] = StrToTime(sDate[i]+" "+sTime[i])+TimeZone*3600;

i++;

}
FileClose(handle);
}

NewsNum=i;
}
//----------------------------------------------------------------------------------------

//+------------------------------------------------------------------

//| expert deinitialization function


//+------------------------------------------------------------------

int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------

//| expert start function

//+------------------------------------------------------------------

int start()
{
//------------------------------------------------------------------------------------
//| check for first of Candle
//------------------------------------------------------------------------------------
if (Volume[0]>1)
return;
//------------------------------------------------------------------------------------
//int X=count_sys();

datetime After_news,Befor_news,Time_Current,sOpenTime,Dresult;
result=false;
for(i=0;i<=NewsNum;i++)

{
sOpenTime=dt[i];
if ("EUR" == sSymbol[i] || "USD" == sSymbol[i])
{
//sOpenTime=dt[1];
Befor_news=sOpenTime - (TimeGap*1800); // Gape time between News like 30 Minute befor news
After_news=sOpenTime + (TimeGap*1800); // Gape time between News like 30 Minute after news

if ( TimeCurrent() <= Befor_news || TimeCurrent() >= After_news )
{
result=true;
break;
}

//else result=false;
}
}

//----------------------------------------------------------------------------------------
//|check for trade rules
//----------------------------------------------------------------------------------
Comment("\nNumebr of News for Symbol is ",count_sys(),"\nTime to open is ",result);
//Comment("the MA value on ",shift," candle before,is ",myMA,"\nthe RSI value is ",myRSI,"\nTime and Symbol is ",sDate[1],sSymbol[1],"\nCount-Sys is ",count_sys(),"\ntest for p[i] ",c,"\ndt[i] is ",DT(),"\n info is ",info,"\nDresult is ",Dresult,"\nTime to open is ",result);

if( (Close[shift]>Open[shift])&& result )
BuyPosition();

if( (Close[shift]<Open[shift])&& result )
SellPosition();

return(0);
}
//---------------------------------------------------------------------------------------
//|count News events for these symbols
//----------------------------------------------------------------------------------------
int count_sys()
{
int C=0;
int i=0;

for (int z=0; z<=NewsNum;z++)
{

if ("EUR" == sSymbol[z] || "USD" == sSymbol[z])
{
C++;
}
}
return(C);
}
//------------------------------------------------------------------------------------
//+----------------------------------------------------------------

void BuyPosition()
{
if(OrdersTotal()>0)
return;
OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"MY Buy Position",16384,0,Green);
}
//-----------------------------------------------------------------
void SellPosition()
{
if(OrdersTotal()>0)
return;
OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"MY Sell Position",16384,0,Red);
}

Files:
 

Hello, could you share the source of that file?

Thanks!

 

hi Dude,

everything is sharing!!! what do u want to share?!! the source of Mq4 is on the content and the database of News, for instance,is attached here.

but you must change file extention and solve my problem;-).

Regards,

Reason: