[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: How to add numbers from ASCII?



PureBytes Links

Trading Reference Links

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 amibroker@xxxxxxxxxxxxxxx, Panos Boufardeas <panosbouf@xxx> 
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
>



------------------------------------

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/