Data in an ASCII or TXT or CSV file are strings, i.e. text. So if you wanted to add 11.1 and 11.0, the 4th element on a line, you would have to access the 4th string in each line, store that in a float var using numtostr() then sum them. But they would not = 100 but 22.1. Where are you getting 100? But if you wanted to find the gain you would subtract the sell price from the buy price. Or it it was a short then subtract the buy price from the sell price.
If you wanted to sum that column then you would just use a for loop and convert the string to float and sum them. The trick is getting to the 4 string from each line. Use StrExtract to get the 4th element and add that to a total. Then in your loop you can use total = total + numtostr(StrExtract(linetext, 4), 1.2); In this case total is just a float var and not an array. For loop processing use the link you provided that shows how to read a file and get each line to EndOfFile. Your example is harder, adding two lines of a file. You would need something additional to tell you what lines to add. Say the two lines you provided were in the middle of the file with 100 lines. You would need code to find those two specific lines. That is much harder than summing the lines. Barry --- In [email protected], Panos Boufardeas <[EMAIL PROTECTED]> wrote: > > Hi > I would like to know if there is any example how to add 2 numbers from > different lines in afl by reading ascii files? > > For example if the file is like this > YM, sell,-1,11.100 > YM,buy,1, 11.000 > How can I have the results =100 ? > > I was reading > this > <http://finance.groups.yahoo.com/group/amibroker/message/113223>http:/ /finance.groups.yahoo.com/group/amibroker/message/113223 > but I cannot manage. > > Thank you > Panos >
