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
Reading a txt file in power language? [SOLVED]
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2228 times
Re: Reading a txt file in power language?
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
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2958 times
Re: Reading a txt file in power language?
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:
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
Re: Reading a txt file in power language?
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!
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!
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2958 times
Re: Reading a txt file in power language?
Hello eegroup,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!
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.
Re: Reading a txt file in power language?
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
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
Re: Reading a txt file in power language?
eegroup,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
Do you have an exemple on how to use IOData to open a text file.
Martin
Re: Reading a txt file in power language?
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
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
Re: Reading a txt file in power language?
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.
I guess you can edit the CPP and change const int BUF_SIZE = 255; to mitigate the issue.