Page 1 of 1
Writing to file
Posted: Thu Mar 01, 2018 5:13 pm
by TargetFilled
I would like to write values of ActionZone to a file and took a stab at the following script:
ref = ActionZones(&s1, &r1, &s2, &r2);
if (ref == true) {
file_write("C:\Users\AZ\BDPM.txt",open);
file_write("C:\Users\AZ\BDPM.txt",s1);
file_write("C:\Users\AZ\BDPM.txt",s2);
file_write("C:\Users\AZ\BDPM.txt",r1);
file_write("C:\Users\AZ\BDPM.txt",r2);
}
Obviously, it wrote values for each bar with update. Is there a way to stop writing to the file after the first bar of the day is printed?
thanks,
Re: Writing to file
Posted: Fri Mar 02, 2018 3:05 am
by earik
Hi,
Yeah, just change the "if" block to only trigger when you are on the first bar of the day. Do it like this...
Code: Select all
ref = ActionZones(&s1, &r1, &s2, &r2);
if ((ref == true) and (day!=day[1])) {
file_write("C:\Users\AZ\BDPM.txt",open);
file_write("C:\Users\AZ\BDPM.txt",s1);
file_write("C:\Users\AZ\BDPM.txt",s2);
file_write("C:\Users\AZ\BDPM.txt",r1);
file_write("C:\Users\AZ\BDPM.txt",r2);
}
Regards,
Earik
Re: Writing to file
Posted: Fri Mar 02, 2018 11:58 am
by TargetFilled
Thanks Earik; while the solution fixes printing to the file for every bar, it prints for every day on the chart. I was thinking while loop for recent day, but couldn't make it work; would appericiate if you can provide another pointer as well.
Re: Writing to file
Posted: Thu Mar 08, 2018 6:55 pm
by earik
So you only want it to print if the day is today? You can use the currentday/currentmonth/currentday keywords to check for that. Do it like this:
Code: Select all
ref = ActionZones(&s1, &r1, &s2, &r2);
if ((ref == true) and (day!=day[1])) {
#build a timestamp for today
today_timestamp = currentyear*10000 + currentmonth*100 + currentday;
#build a timestamp for the day on the chart
chart_timestamp = year*10000 + month*100 + day;
#only write to the file if its the current day
if (today_timestamp == chart_timestamp) {
file_write("C:\Users\AZ\BDPM.txt",open);
file_write("C:\Users\AZ\BDPM.txt",s1);
file_write("C:\Users\AZ\BDPM.txt",s2);
file_write("C:\Users\AZ\BDPM.txt",r1);
file_write("C:\Users\AZ\BDPM.txt",r2);
}
}
Hope that helps!
Earik