Reading a txt file in power language?  [SOLVED]

Questions about MultiCharts and user contributed studies.
photon
Posts: 1
Joined: 31 May 2016
Has thanked: 2 times

Reading a txt file in power language?  [SOLVED]

Postby photon » 31 May 2016

Hi folks,

I'm new to the forum.

Is there a way to read a file in a power language signal?

The idea is to use external software to write into a text file, and then multicharts reads the file every tick and and uses the information to adjust target/stops on orders. File is constantly written by external software, and so multicharts signal would need to keep reading it.

Thanks

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

Re: Reading a txt file in power language?

Postby TJ » 31 May 2016

Hi folks,

I'm new to the forum.

Is there a way to read a file in a power language signal?

The idea is to use external software to write into a text file, and then multicharts reads the file every tick and and uses the information to adjust target/stops on orders. File is constantly written by external software, and so multicharts signal would need to keep reading it.

Thanks

You can use the third party addon ELCollections. It is free.

viewtopic.php?f=5&t=6901

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

Re: Reading a txt file in power language?

Postby Henry MultiСharts » 02 Jun 2016

Hello photon,

Reading from a file in PowerLanguage requires an external dll.
You can check the ELCollection add-on available for free on the forum or see the source code of the EconomicEvents study available in the User Contributed section that already has this implemented:
viewtopic.php?t=2483
viewtopic.php?f=5&t=9951

There is also a sample Dll our developer has created for this goal:
https://goo.gl/8BDYyo

Using the functions InData, OutData, RFile, SFile, ADDStringFile, DelFile, DirCreate this library can write to file, read from file, add a line to file, delete file, create folder.

Here is the code sample for reading from the file:

Code: Select all

DefineDLLFunc: "C:\Users\root\Desktop\IOData\Release\IOData.dll", int, "RFile", lpstr;
DefineDLLFunc: "C:\Users\root\Desktop\IOData\Release\IOData.dll", lpstr, "InData", int;
var: idx(0), LinesCount(0);
once cleardebug;

if(LastBarOnChart_s) then begin
Print("What's in the file ?");
LinesCount = RFile("c:\\Temp\\11\\TS_Orders_Clean.txt");

for idx = 0 to LinesCount - 1 begin
print(InData(idx));
end;
end

eegroup
Posts: 78
Joined: 04 Aug 2008
Has thanked: 11 times
Been thanked: 9 times

Re: Reading a txt file in power language?

Postby eegroup » 11 Jul 2016

Without digging through the IOData source code, is there any documentation available for the IOData DLL function calls, like OutData, SFile, ADDStringFile, DelFile, DirCreate this library, where we can write to file, read from file, add a line to file, delete file, create folder? I have successfully used the RFile and InData function calls, as documented here, and it works perfectly. I would like to use some of the other functions as well.

I double checked the content of the Zip file and it does not seem to be located there.

BTW, this is a GREAT addition to the MultiCharts functionality. Nice job!

Thanks!

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

Re: Reading a txt file in power language?

Postby Henry MultiСharts » 12 Jul 2016

Without digging through the IOData source code, is there any documentation available for the IOData DLL function calls, like OutData, SFile, ADDStringFile, DelFile, DirCreate this library, where we can write to file, read from file, add a line to file, delete file, create folder? I have successfully used the RFile and InData function calls, as documented here, and it works perfectly. I would like to use some of the other functions as well.

I double checked the content of the Zip file and it does not seem to be located there.

BTW, this is a GREAT addition to the MultiCharts functionality. Nice job!

Thanks!
Hello eegroup,

We do not have a detailed help guide for this dll at the moment. I believe these functions are pretty straightforward and should be easy to use. Let me know in case you have any specific questions.

eegroup
Posts: 78
Joined: 04 Aug 2008
Has thanked: 11 times
Been thanked: 9 times

Re: Reading a txt file in power language?

Postby eegroup » 12 Jul 2016

Hi Henry,

Yes, the names of the function calls are very straightforward, like:

RFile - Open a Read File
InData - Read a File
SFile - Define a Sending File
OutData - Send Data to an Output File
ADDStringFile - Add to a String File(?)
DelFile - Delete a File
DirCreate - Create a new directory

The issue becomes, what are the calling parameter formats for each of the functions?

Not a big deal, Henry, but we kind of need that for those functions.

The reason that I initially asked for those first was that if the documetation was available, that would save having to dig through the OIData coding to locate that information. Since it is now not available, I will do that and post back here what I discover after checking the coding, for others who might find this DLL to be helpful.

I realize that I could use the ELCollections for our specific need, but I like the IOData DLL better, it is more specific and addresses exactly what we need at the present time.

Many thanks for your response,
eegroup

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Reading a txt file in power language?

Postby arjfca » 01 Sep 2016

Hi Henry,

Yes, the names of the function calls are very straightforward, like:

RFile - Open a Read File
InData - Read a File
SFile - Define a Sending File
OutData - Send Data to an Output File
ADDStringFile - Add to a String File(?)
DelFile - Delete a File
DirCreate - Create a new directory

The issue becomes, what are the calling parameter formats for each of the functions?

Not a big deal, Henry, but we kind of need that for those functions.

The reason that I initially asked for those first was that if the documetation was available, that would save having to dig through the OIData coding to locate that information. Since it is now not available, I will do that and post back here what I discover after checking the coding, for others who might find this DLL to be helpful.

I realize that I could use the ELCollections for our specific need, but I like the IOData DLL better, it is more specific and addresses exactly what we need at the present time.

Many thanks for your response,
eegroup
eegroup,

Do you have an exemple on how to use IOData to open a text file.

Martin

User avatar
c0ntango
Posts: 70
Joined: 13 Sep 2018
Has thanked: 3 times
Been thanked: 16 times
Contact:

Re: Reading a txt file in power language?

Postby c0ntango » 29 Jul 2019

Hey everyone,

I seem to have a problem with IOData.dll - RFile(filename) keeps returning 0 in case of a file that has thousands of lines. At first I thought it could be an encoding issue, but it's not. It works with other files but I haven't found the common denominator. Did anyone see this issue before?

The files it can't seem to read properly have been written with FileAppend() and I've copied, renamed, saved in 10 different encodings, etc., to experiment, but it just keeps returning 0 for number of lines... and with the exact same code and different files, the number of lines are returned correctly.

It's so weird. Any ideas?

Thank you,

-Ben

User avatar
c0ntango
Posts: 70
Joined: 13 Sep 2018
Has thanked: 3 times
Been thanked: 16 times
Contact:

Re: Reading a txt file in power language?

Postby c0ntango » 29 Jul 2019

OK so: it seems that if IOData.DLL finds a line that is more than 254 characters long in the file, it will not look at that line or any other files below that line.

I guess you can edit the CPP and change const int BUF_SIZE = 255; to mitigate the issue.


Return to “MultiCharts”