Writing MultiCharts Status Output to a File  [SOLVED]

Questions about MultiCharts and user contributed studies.
roesm
Posts: 37
Joined: 30 Sep 2011
Has thanked: 10 times
Been thanked: 5 times

Writing MultiCharts Status Output to a File

Postby roesm » 11 Apr 2013

I am writing status information to a file using the print(file(...)) function. However, I can only append to the file and with a lot of info, the file gets huge. I only need the latest data. Is there a way to overwrite the file data or delete it rather than append to it? (I can't use the File Delete function as it does not work after the file is opened).

TIA
Mike

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Writing MultiCharts Status Output to a File

Postby Henry MultiСharts » 16 Apr 2013

Hello Mike,

That is possible to delete the file with FileDelete reserved word.

roesm
Posts: 37
Joined: 30 Sep 2011
Has thanked: 10 times
Been thanked: 5 times

Re: Writing MultiCharts Status Output to a File

Postby roesm » 16 Apr 2013

I'm glad it is possible, but I don't know how to do it.

For test, I tried this:

Code: Select all

vars:
OutputFile("C:\z1\T1.txt");

if LastBarOnChart and barstatus = 2 then begin
FileDelete(OutputFile);
print(file(OutputFile),o,h,l,c);
end;
I thought that perhaps the FileDelete function needed time to complete, so I tried:

Code: Select all

if LastBarOnChart and FracPortion(barnumber/2) = 0 and barstatus = 2 then
FileDelete(OutputFile);

if LastBarOnChart and FracPortion(barnumber/2) <> 0 and barstatus = 2 then
print(file(OutputFile),o,h,l,c);
This way, on each bar it alternates between writing and deleting. It still only appends. In either case, the delete only occurs once - when the program starts.

What am I doing wrong?

Thanks for your help,
Mike

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Writing MultiCharts Status Output to a File  [SOLVED]

Postby Henry MultiСharts » 17 Apr 2013

Hello Mike,

Print command does not let the file to be deleted on each calculation.
Instead of print please use FileAppend command.

roesm
Posts: 37
Joined: 30 Sep 2011
Has thanked: 10 times
Been thanked: 5 times

Re: Writing MultiCharts Status Output to a File

Postby roesm » 17 Apr 2013

That works. Thank you!

eg...

Code: Select all

vars:
OutputFile("C:\z1\T1.txt"),
OutString("");

if LastBarOnChart and barstatus = 2 then begin
FileDelete(OutputFile);
OutString = NumToStr(o,2) + " " + NumToStr(h,2) + " " + NumToStr(l,2) + " " + NumToStr(c,2);
FileAppend(OutputFile,OutString);
end;


Return to “MultiCharts”