Pic
Announcement
Collapse
No announcement yet.
Reading From an external File Problem
Collapse
X
-
I have a program (not Esignal) that calculates the HIGH and LOW of a fib and put it into two text files.
Esignal is reading and plotting it correctly but it’s not letting me do any calculation with the numbers pulled (trying to get vLMid)
I have a feeling it’s bringing it as a STRING and that’s part of the problem.
Picture Below
Thank you
Ketoma
PS: I created two files because I did not know how to make Esignal read from one text file for HIGH and LOW.Attached FilesLast edited by ketoma21; 05-24-2006, 12:25 AM.
-
Ketoma
vHLine and vLLine are in fact strings. You can verify that by using the typeof() operator eg
debugPrintln(typeof(vHLine)+" "+typeof(vLLine));
To convert a string to a number multiply it by 1 eg
var vLMid = ((vHLine*1) + (vLLine*1)) / 2;
Once you implement this change you will see the vLMid line draw correctly
Alex
Comment
-
Ketoma:
You can store and read the two values from the same file by using a separator.
So in your file you could write the two values (i.e., low and high) with a comma separator, as follows:
15.0,38.36
Then to read the two values you would use "readln" just as you already have but then you would use the "split" method to separate the line into the two values, as follows:
F = new File("Fibs.txt");
F.open("rt");
tmp = F.readln();
tmp1 = tmp.split(","); //split at the comma
if ( tmp1 != null ) {
vLLine = tmp1[0]/1;
vHLine = tmp1[1]/1;
}
F.close();
Chris
Comment
-
Thank you very much Alexis and ckryza both fixes work great
but now I'm faced with a new problem
I've allot of charts and they all will use this EFS (different stock)
and they over write each other creating problems.
do I have to creat the same EFS for each chart using this EFS?
(that would be a pain).
Or
is there a way I can make my Esignal read from the same file
for Example:
AAPL,70.90,60.40
mrvl,53.80,50.50
sndk,60.60,58.58
etc.....
Or
another easier way?
Thank you
Ketoma
Comment
-
The latter option is probably the best.... create a file where the fib data for each security is on a separate line and make sure that the first item on each line is the symbol (i.e., just like in your example below). Then use the File routines to read through the file (using readln and the split method discussed before) until you reach the line where the first item (i.e., symbol) matches the symbol you are charting. At that point you just retrieve the remaining values from that line of text and you are all set. As long as you keep all items on a line separated by a comma, the split method will do most of the work for you.
Chris
Comment
-
Yes, here is an example:
PHP Code://retrieve the symbol of the chart we are running in
sSymbol = getSymbol();
f = new File( sFileName );
if ( f.exists() ) {
f.open( "rt" );
//walk through the file, line by line
while(!f.eof()) {
line = f.readln();
if ( line != null ) {
sTmp = line.split( "," );
if ( sTmp != null ) {
if ( sTmp[0].toUpperCase() == sSymbol ) {
//here we have found the line that contains
//the values for the symbol we are currently using
//so this is where you would add your custom code
//to pull out those values and do something with them
}
}
}
}
f.close();
}
Comment
Comment