How to output milliseconds using FileAppend  [SOLVED]

Questions about MultiCharts and user contributed studies.
User avatar
Filly
Posts: 19
Joined: 17 Apr 2010
Has thanked: 3 times

How to output milliseconds using FileAppend

Postby Filly » 19 Jan 2015

I'm trying to output custom futures tick data into a separate .txt files so that I can import the data back into QM as a continuous contract. The purpose is to function as a workaround for the inability of MultiCharts to use the Bar Magnifier for Custom Futures.

Here is the indicator code that I'm using:

Code: Select all

Inputs:
Directory("C:\Users\name\Trading\Futures\ContContracts"),
WriteOk(true),
PriceDecimals(2),
BeginDate(0);

Vars:
FileName(Directory + "\" + GetSymbolName + ".txt"),
S("");

if WriteOk then
if CurrentBar = 1 then begin
FileDelete(FileName);
S = "Date,Time,Close,";
FileAppend(FileName, S + NewLine);
end;

if Date >= BeginDate then begin
S = Text(ELDateToString(Date),",",
Formattime("HH:mm:ss.MMM", DateTime),",",
NumToStr(Close, PriceDecimals));
FileAppend(FileName, S + NewLine);
end;

Plot1(0, "Save Ticks");
The output looks like this:
  • 02/16/2014,18:50:44.MMM,3662.75
    02/16/2014,18:51:02.MMM,3663.00
    02/16/2014,18:51:37.MMM,3663.75
    02/16/2014,18:51:39.MMM,3663.50
    02/16/2014,18:52:01.MMM,3663.75
    02/16/2014,18:52:02.MMM,3663.75
1) How can I get milliseconds where the "MMM" are?

2) The FileDelete command isn't working. If I run the indicator an additional time, the output is appended to the end of the existing file. I'd like the old file to be deleted first, then a new file created. Any ideas?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: How to output milliseconds using FileAppend

Postby TJ » 19 Jan 2015

You can go directly to QuoteManager and export the data from there.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: How to output milliseconds using FileAppend

Postby TJ » 19 Jan 2015

If you want the adjusted price, then you do it this way:

Load a one-tick chart on your screen, then

FILE > Export Data


It is not perfect, it is tedious, and you might need to do some data massaging afterwards,
but at least you get your MMM.

User avatar
Filly
Posts: 19
Joined: 17 Apr 2010
Has thanked: 3 times

Re: How to output milliseconds using FileAppend  [SOLVED]

Postby Filly » 19 Jan 2015

TJ, That's what I needed to know. It is easier and the FileAppend command is incredibly slow.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: How to output milliseconds using FileAppend

Postby TJ » 20 Jan 2015

You can load up to 100 million bars on a chart (ie 100m ticks in this case). You will have to guesstimate the beginning and ending time of sessions to load.


ps. You can load more than 100m bars on the chart, but you will need to edit the registry, which is not something I would recommend people to do.

User avatar
Filly
Posts: 19
Joined: 17 Apr 2010
Has thanked: 3 times

Re: How to output milliseconds using FileAppend

Postby Filly » 20 Jan 2015

The content of TJ's posts would be very helpful if added to the Custom Futures section of the Wiki help page re: Bar Magnifier not working. It would have saved me a bunch of work.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: How to output milliseconds using FileAppend

Postby JoshM » 20 Jan 2015

1) How can I get milliseconds where the "MMM" are?
Milliseconds cannot be exported with `FormatTime()`, it seems. But the `MillisecondsFromDateTime()` keyword can be used for that:

Code: Select all

once (LastBarOnChart_s) begin

Print("Time now: ",
FormatTime("HH:mm:ss", ComputerDateTime),
".", NumToStr(MillisecondsFromDateTime(ComputerDateTime), 0));

end;
Gives as output:

Code: Select all

Time now: 11:32:59.719
I know this topic is already solved with manually exporting, but as a feature request: perhaps MultiCharts Support can update `FormatTime()` to also accept the `.fff` parameter to output DateTime values with milliseconds?

That would work much easier and more intuitive than the workaround posted above.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: How to output milliseconds using FileAppend

Postby JoshM » 31 Jan 2015

(...) as a feature request: perhaps MultiCharts Support can update `FormatTime()` to also accept the `.fff` parameter to output DateTime values with milliseconds?

That would work much easier and more intuitive than the workaround posted above.
I've made a feature request for this idea here:

MC-1847 - Allow FormatTime() to output milliseconds

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

Re: How to output milliseconds using FileAppend

Postby Henry MultiСharts » 04 Feb 2015

I know this topic is already solved with manually exporting, but as a feature request: perhaps MultiCharts Support can update `FormatTime()` to also accept the `.fff` parameter to output DateTime values with milliseconds?
That would work much easier and more intuitive than the workaround posted above.
It was not added for backward code compatibility.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: How to output milliseconds using FileAppend

Postby TJ » 04 Feb 2015

Proposal for a new keyword:

FormatTime_ms()

orion
Posts: 250
Joined: 01 Oct 2014
Has thanked: 65 times
Been thanked: 104 times

Re: How to output milliseconds using FileAppend

Postby orion » 04 Feb 2015

Proposal for a new keyword: FormatTime_ms()
TJ, printing the millisecond is easily done especially if one does not care about performance. It may be worth first looking at improving the performance of existing string-based keywords.

Here is how the performance works out. Assume string-based keywords cost 20 times that of non-string keywords as per benchmarks. Assume that string-based keywords are 10% of the code. Lets normalize cost to that of non-string keywords. Out of every 100 keywords, 90% are non-string keywords and they cost 90 * 1 = 90 units and 10% string-based keywords cost 10 * 20 = 200 units for a total cost of 290 units. If string-based keyword performance could be improved by even 5X then the total cost would be 90 + 10 * 4 = 130 which is more than a doubling of performance.

Meecc
Posts: 50
Joined: 23 Jun 2011
Has thanked: 22 times
Been thanked: 7 times

Re: How to output milliseconds using FileAppend

Postby Meecc » 04 Feb 2015

Adding to TJ's post#3 above

File menu \ Export Data \

Tick on check box Export milliseconds


Return to “MultiCharts”