From d1080165aab3d99943f74008baf6afe65d05a7ee Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@maiol.ru> Date: Mon, 23 Oct 2017 07:29:42 +0200 Subject: [PATCH] Indicators --- nbproject/private/private.xml | 1 + nbproject/project.properties | 2 +- src/chart/MasterChart.java | 6 ++++- src/chart/painter/LineChartPainter.java | 8 ++++--- src/sesim/Indicator.java | 30 ++++++++++++++++++++++++- 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index f963935..e13b67c 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -39,6 +39,7 @@ file:/home/tube/NetBeansProjects/SeSim/src/traders/RandomTraderB.java file:/home/tube/NetBeansProjects/SeSim/src/sesim/Logger.java file:/home/tube/NetBeansProjects/SeSim/src/gui/EditPreferencesDialog.java + file:/home/tube/NetBeansProjects/SeSim/src/sesim/Indicator.java file:/home/tube/NetBeansProjects/SeSim/src/sesim/AutoTraderBase.java file:/home/tube/NetBeansProjects/SeSim/src/gui/Statistics.java file:/home/tube/NetBeansProjects/SeSim/src/gui/EditStrategies.java diff --git a/nbproject/project.properties b/nbproject/project.properties index 548c146..3e060d8 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,4 +1,4 @@ -#Mon, 16 Oct 2017 20:12:31 +0200 +#Sun, 22 Oct 2017 07:44:50 +0200 annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= diff --git a/src/chart/MasterChart.java b/src/chart/MasterChart.java index ad26ec9..b8df72f 100644 --- a/src/chart/MasterChart.java +++ b/src/chart/MasterChart.java @@ -29,6 +29,7 @@ import chart.painter.CandleStickChartPainter; import chart.painter.ChartPainter; import chart.painter.XLegendPainter; import chart.painter.ChartCrossPainter; +import chart.painter.LineChartPainter; import chart.painter.YLegendPainter; import gui.Globals; import sesim.Exchange.QuoteReceiver; @@ -63,7 +64,10 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver, Ch this.xLegend.setChartDef(chartDef); this.yLegend.setChartDef(chartDef); - ChartPainter p = new CandleStickChartPainter(); + ChartPainter p = new LineChartPainter(); + p.setDataProvider(this); + chart.addChartPainter(p); + this.xScrollBar.setMaximum(0); p = new XLegendPainter(); diff --git a/src/chart/painter/LineChartPainter.java b/src/chart/painter/LineChartPainter.java index 7552b04..c2aabad 100644 --- a/src/chart/painter/LineChartPainter.java +++ b/src/chart/painter/LineChartPainter.java @@ -35,7 +35,9 @@ import sesim.OHLCDataItem; */ public class LineChartPainter extends OHLCChartPainter{ - + protected float getVal(OHLCDataItem i){ + return i.getAverage(); + } @Override void drawItem(Graphics2D g, int prevx, int x, OHLCDataItem prev, OHLCDataItem i) { @@ -43,8 +45,8 @@ public class LineChartPainter extends OHLCChartPainter{ if (prev == null) { prev = i; } - int y1 = (int) getY(prev.close); - int y2 = (int) getY(i.close); + int y1 = (int) getY(getVal(prev)); + int y2 = (int) getY(getVal(i)); Color cur = g.getColor(); g.setColor(Color.RED); diff --git a/src/sesim/Indicator.java b/src/sesim/Indicator.java index 4b2fdfc..7309872 100644 --- a/src/sesim/Indicator.java +++ b/src/sesim/Indicator.java @@ -30,13 +30,41 @@ package sesim; * @author 7u83 <7u83@mail.ru> */ public class Indicator { - OHLCData parent; + private OHLCData parent; OHLCData indicator; + Indicator(OHLCData parent){ + this.parent=parent; + } + + int len=10; + + float getAt(int pos){ + int start = pos -len; + if(start<0) + start=0; + float sum=0; + for (int i=start; i