Writing to file

This is a forum to discuss trading tools and approaches to timing the market.
Post Reply
TargetFilled
Posts: 10
Joined: Mon Sep 25, 2017 4:44 pm
Contact:

Writing to file

Post by TargetFilled » Thu Mar 01, 2018 5:13 pm

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,

User avatar
earik
Site Admin
Posts: 474
Joined: Mon Dec 01, 2014 12:41 pm
Contact:

Re: Writing to file

Post by earik » Fri Mar 02, 2018 3:05 am

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

TargetFilled
Posts: 10
Joined: Mon Sep 25, 2017 4:44 pm
Contact:

Re: Writing to file

Post by TargetFilled » Fri Mar 02, 2018 11:58 am

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.

User avatar
earik
Site Admin
Posts: 474
Joined: Mon Dec 01, 2014 12:41 pm
Contact:

Re: Writing to file

Post by earik » Thu Mar 08, 2018 6:55 pm

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

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests