|
From: Thies <tg...@us...> - 2007-10-17 18:29:54
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail/indicator/tracker In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv18190/src/java/net/sf/tail/indicator/tracker Modified Files: ParabolicSarIndicator.java Log Message: Nova forma de calcular o parabolic sar Index: ParabolicSarIndicator.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/indicator/tracker/ParabolicSarIndicator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ParabolicSarIndicator.java 26 Sep 2007 19:24:06 -0000 1.2 --- ParabolicSarIndicator.java 17 Oct 2007 18:29:56 -0000 1.3 *************** *** 3,6 **** --- 3,10 ---- import net.sf.tail.TimeSeries; import net.sf.tail.indicator.cache.CachedIndicator; + import net.sf.tail.indicator.helper.HighestValueIndicator; + import net.sf.tail.indicator.helper.LowestValueIndicator; + import net.sf.tail.indicator.simple.MaxPriceIndicator; + import net.sf.tail.indicator.simple.MinPriceIndicator; public class ParabolicSarIndicator extends CachedIndicator<Double> { *************** *** 11,18 **** private double extremePoint; ! ! public ParabolicSarIndicator(TimeSeries series) { ! this.acceleration = 0.02; this.series = series; } --- 15,31 ---- private double extremePoint; ! ! private final HighestValueIndicator highestValueIndicator; ! ! private final LowestValueIndicator lowestValueIndicator; ! ! private Boolean isDownTrade; ! ! public ParabolicSarIndicator(TimeSeries series, int timeFrame) { ! this.acceleration = 0.02d; this.series = series; + this.highestValueIndicator = new HighestValueIndicator(new MaxPriceIndicator(series), timeFrame); + this.lowestValueIndicator = new LowestValueIndicator(new MinPriceIndicator(series), timeFrame); + isDownTrade = null; } *************** *** 20,79 **** protected Double calculate(int index) { ! if (index <= 1) { extremePoint = series.getTick(index).getClosePrice(); return extremePoint; } ! double sar; ! ! // trend switch ! if (series.getTick(index - 2).getClosePrice() > series.getTick(index - 1).getClosePrice() && series.getTick( ! index - 1).getClosePrice() < series.getTick(index).getClosePrice()) ! { ! sar = extremePoint; ! extremePoint = series.getTick(index).getMaxPrice(); ! acceleration = 0.02; ! } ! // trend switch ! else if((series.getTick(index - 2).getClosePrice() < series.getTick(index - 1).getClosePrice() && series ! .getTick(index - 1).getClosePrice() > series.getTick(index).getClosePrice())) { ! ! sar = extremePoint; ! extremePoint = series.getTick(index).getMinPrice(); ! acceleration = 0.02; ! ! } //DownTrend ! else if (series.getTick(index - 1).getClosePrice() >= series.getTick(index).getClosePrice()) { ! if (extremePoint > series.getTick(index).getClosePrice()) { ! acceleration = acceleration >= 0.19 ? 0.2 : acceleration + 0.02d; ! extremePoint = series.getTick(index).getMinPrice(); } ! sar = acceleration * (extremePoint - getValue(index - 1)) + getValue(index - 1); ! if (sar <= series.getTick(index - 1).getMaxPrice()) ! sar = series.getTick(index - 1).getMaxPrice(); ! else if (sar <= series.getTick(index - 2).getMaxPrice()) ! sar = series.getTick(index - 2).getMaxPrice(); ! if (sar <= series.getTick(index).getMaxPrice()) { ! sar = series.getTick(index).getMinPrice(); } } //UpTrend else { ! if (extremePoint < series.getTick(index).getMaxPrice()) { ! acceleration = acceleration >= 0.19 ? 0.2 : acceleration + 0.02; ! extremePoint = series.getTick(index).getMaxPrice(); } ! sar = acceleration * (extremePoint - getValue(index - 1)) + getValue(index - 1); ! if (sar >= series.getTick(index - 1).getMinPrice()) ! sar = series.getTick(index - 1).getMinPrice(); ! else if (sar >= series.getTick(index - 2).getMinPrice()) ! sar = series.getTick(index - 2).getMinPrice(); ! if (sar >= series.getTick(index).getMinPrice()) { ! sar = series.getTick(index).getMaxPrice(); } } ! return sar; } --- 33,75 ---- protected Double calculate(int index) { ! if (index == 0) { extremePoint = series.getTick(index).getClosePrice(); return extremePoint; } ! //DownTrend ! if (series.getTick(index - 1).getClosePrice() >= series.getTick(index).getClosePrice()) { ! double actualLowest = lowestValueIndicator.getValue(index); ! ! if(isDownTrade == null || !isDownTrade) { ! isDownTrade = true; ! acceleration = 0.02d; ! extremePoint = actualLowest; } ! else if(actualLowest != extremePoint) { ! if(actualLowest < extremePoint) ! acceleration = acceleration >= 0.2d? 0.2d : acceleration + 0.02d; ! extremePoint = actualLowest; } + } //UpTrend else { ! double actualHighest = highestValueIndicator.getValue(index); ! if(isDownTrade == null || isDownTrade) { ! isDownTrade = false; ! acceleration = 0.02d; ! extremePoint = actualHighest; } ! else if(actualHighest != extremePoint){ ! if(actualHighest > extremePoint) ! acceleration = acceleration >= 0.2d? 0.2d : acceleration + 0.02d; ! extremePoint = actualHighest; ! } } ! return getValue(index - 1) + acceleration * (extremePoint - getValue(index - 1)); } |