- TimeCurrent to a string is "yyyy.mm.dd hh:mi" and you can't use a colon in filenames.
- Don't even try to use any price or server related functions in
OnInit as there may be no connection/chart yet:
- Terminal starts.
- indicators/EAs are loaded.
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called; Now TickValue, TimeCurrent and prices are now valid.
The report (and fileOpen command) are executed at OnTimer() event.
When run from a script, TimeCurrent returns a value like 1509638400 (unix time). It works fine and there is no need to convert it to a string.
I am not sure why it is behaving differently in an EA and how can I append the datetime to the file name.
I tried:
string t=TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS);
t=StringReplace(t,":","");
But it does not seem to work.
Hannan Nussbaum:
I am not sure why it is behaving differently in an EA and how can I append the datetime to the file name.
string t=TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS);t=StringReplace(t,":","");
But it does not seem to work.
- Your script doesn't have #property strict, your EA does.
- "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't
start, won't go in gear, no electrical, missing the key, flat tires -
meaningless. There are no mind readers here and our crystal balls are cracked.
Use the debugger or print out your variables, and find out why.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
When using the following code in a script, it works fine:
CurrentFileName = StringConcatenate(ReportsDir,"\\",title," ",TimeCurrent(),".html");
h = FileOpen(CurrentFileName,FILE_WRITE);
However, using the same code in an expert advisor result in an error opening the file.
When removing the TimeCurrent(), it works fine.
Any suggestions?