var MyFileObj = new File("My_Output.txt"); function ReportInitialization() { MyFileObj.writeln("Now initializing..."); } function ReportNewBarData() { MyFileObj.writeln("Here is new bar data..."); } function ReportEODSummary() { MyFileObj.writeln("Here is EOD summary..."); } function preMain() { MyFileObj.open("wt"); // One time only: if file exists, overwrite it ReportInitialization(); MyFileObj.flush(); MyFileObj.close(); } function main() { MyFileObj.open("at"); // Open existing file for writing = appending // ...other code... if (getBarState() == BARSTATE_NEWBAR) {ReportNewBarData()} if (MyTime = LastBarOfDay) {ReportEODSummary()} MyFileObj.flush(); MyFileObj.close(); }