/** * * This is a http://en.wikipedia.org/wiki/MACD * http://investexcel.net/how-to-calculate-macd-in-excel/ * * @author Freeman Lo * @version 0.0.1 Build 1 April 1, 2014. * Limitations - * * */ import java.util.ArrayList; public class ProcessEMA26 { ArrayList sArrList = new ArrayList (); ArrayList ema26 = new ArrayList (); public ProcessEMA26 (ArrayList sArrList) { this.sArrList = sArrList; } private ArrayList getCloseValues() { ArrayList temp = new ArrayList (); String [] words = new String[6]; int a=0; while ( a < this.sArrList.size() ) { String line = this.sArrList.get(a); words = line.split(","); for (int x = 0; x < words.length; x++) { if ( x == 4 ) { temp.add(words[4]); } } a+=1; } return temp; } public double getAverage() { ArrayList closeValues = getCloseValues(); double avgValue = 0.00; for ( int item = 0; item < 26; item++ ) { avgValue += Double.parseDouble(closeValues.get(item)); } avgValue = avgValue / 26.00; return avgValue; } public ArrayList computeEMAValues() { ArrayList closeValues = getCloseValues(); double avgvalue = 0.00; double result = 0.00; avgvalue = getAverage(); this.ema26.add(avgvalue); for ( int item = 0; item < closeValues.size()-26; item++ ) { // starts with 0, so 12 is actually 13th place // Formular to compute EMA26 result = (( Double.parseDouble(closeValues.get(item+26))* (2.00 / (26.00+1.00))) + (this.ema26.get(item)) * ((1.00 - (2.00 / (26.00+1.00) )))); this.ema26.add(result); } return ema26; } }