I would like to count when certain conditions in a .csv file are true, for example: these data are from .csv file:
Date,Open,High,Low,Close,Volume,Adj Close2014-07-21,358.10,361.71,356.72,359.76,2278400,359.762014-07-18,354.40,359.68,352.08,358.66,3407400,358.662014-07-17,353.44,356.96,351.38,352.45,3636000,352.452014-07-16,355.62,359.32,353.00,355.90,3503600,355.90
From these data you can draw candlestick chart, I would like to check if first date open price is less than second date open price and also check if first date close price is more than second date close price and 3rd date open price is more than close price. if all these 3 conditions are true then +1 in .txt file. Let me give you a small example: Take first 2 lines:
2014-07-21,358.10,361.71,356.72,359.76,2278400,359.76 2014-07-18,354.40,359.68,352.08,358.66,3407400,358.66
Compare 358.10<354.40 && 359.76>358.66 Now take the next day
2014-07-17,353.44,356.96,351.38,352.45,3636000,352.45
so overall: 358.10<354.40 && 359.76>358.66 && (353.44<352.45) if this condition is true add 1 to the file. Now restart the process take 2nd and 3rd lines: Note first time take 1st and 2nd lines then in second check take 2nd and 3rd line then 4th time check 3rd and 4th line etc… like this:
2014-07-18,354.40,359.68,352.08,358.66,3407400,358.66 <–this time 2nd line 2014-07-17,353.44,356.96,351.38,352.45,3636000,352.45 <–and 3rd line
This is what I have done but not sure if its right:
str = urlread('http://ichart.yahoo.com/table.csv?s=AMZN&a=0&b=1&c=2008&d=0&e=31&n=2014&g=d&ignore=.csv');i = 0; [dates,o,h,l,c] = dataread('string',str,'%s%f%f%f%f%*f%*f','delimiter',',','headerlines',1); dates = datenum(dates); numElems = length(dates); for k=numElems:-1:2 if o(k)<o(k-1) && c(k)>c(k-1) i = i+1;save('output.txt', 'i', '-ASCII'); end end
In a nutshell if you understand candlesticks chart this is what I am looking for:
If these pattern is detected then check if next day is positive if yes record that into file.
Best Answer