Better SMA, still buggy

This commit is contained in:
7u83 2017-11-18 16:04:55 +01:00
parent 35a6bf4e45
commit 394c9caf31
3 changed files with 31 additions and 12 deletions

View File

@ -1,4 +1,4 @@
#Sat, 18 Nov 2017 09:05:33 +0100 #Sat, 18 Nov 2017 16:01:27 +0100
annotation.processing.enabled=true annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false annotation.processing.enabled.in.editor=false
annotation.processing.processors.list= annotation.processing.processors.list=

View File

@ -32,6 +32,7 @@ import chart.painter.ChartCrossPainter;
import chart.painter.LineChartPainter; import chart.painter.LineChartPainter;
import chart.painter.YLegendPainter; import chart.painter.YLegendPainter;
import gui.Globals; import gui.Globals;
import java.util.ArrayList;
import sesim.Exchange.QuoteReceiver; import sesim.Exchange.QuoteReceiver;
import sesim.Indicator; import sesim.Indicator;
import sesim.MinMax; import sesim.MinMax;
@ -48,6 +49,22 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
private ChartDef chartDef; private ChartDef chartDef;
SMAIndicator sma;
class MyOHLCData extends OHLCData {
@Override
public OHLCDataItem get(int n) {
return sma.getData().get(n);
}
@Override
public MinMax getMinMax(int first, int last) {
return mydata.getMinMax(first, last);
}
}
/** /**
* Creates new form MasterChart * Creates new form MasterChart
*/ */
@ -70,7 +87,7 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
// this.yLegend.addChartPainter(p); // this.yLegend.addChartPainter(p);
//this.yLegend.addChartPainter(pc); //this.yLegend.addChartPainter(pc);
} }
OHLCData data; OHLCData mydata;
public void reset() { public void reset() {
this.chart.deleteAllChartPinters(); this.chart.deleteAllChartPinters();
@ -82,33 +99,33 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
this.yLegend.setChartDef(chartDef); this.yLegend.setChartDef(chartDef);
ChartPainter p; ChartPainter p;
data = Globals.se.getOHLCdata(60000 * 10); mydata = Globals.se.getOHLCdata(60000 * 60);
this.xScrollBar.setMaximum(0); this.xScrollBar.setMaximum(0);
p = new XLegendPainter(); p = new XLegendPainter();
p.setOHLCData(data); p.setOHLCData(mydata);
xLegend.addChartPainter(p); xLegend.addChartPainter(p);
xLegend.setXSCrollBar(xScrollBar); xLegend.setXSCrollBar(xScrollBar);
ChartPainter pc = new CandleStickChartPainter(); ChartPainter pc = new CandleStickChartPainter();
//pc.setDataProvider(this); //pc.setDataProvider(this);
pc.setOHLCData(data); pc.setOHLCData(mydata);
chart.addChartPainter(pc); chart.addChartPainter(pc);
chart.setXSCrollBar(xScrollBar); chart.setXSCrollBar(xScrollBar);
chart.addChartPainter(new ChartCrossPainter()); chart.addChartPainter(new ChartCrossPainter());
// SMAIndicator sma = new sesim.SMAIndicator(get()); sma = new sesim.SMAIndicator(mydata);
p = new LineChartPainter(); p = new LineChartPainter();
p.setOHLCData(data); p.setOHLCData(sma.getData());
//p.setDataProvider(new SMA(get())); //p.setDataProvider(new SMA(get()));
chart.addChartPainter(p); chart.addChartPainter(p);
ChartPainter yp = new YLegendPainter(chart); ChartPainter yp = new YLegendPainter(chart);
// yp.setDataProvider(this); // yp.setDataProvider(this);
yp.setOHLCData(data); yp.setOHLCData(mydata);
this.yLegend.addChartPainter(yp); this.yLegend.addChartPainter(yp);
@ -249,10 +266,12 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
@Override @Override
public void UpdateQuote(Quote q) { public void UpdateQuote(Quote q) {
int s = data.size(); if (sma != null) {
sma.update();
}
int s = mydata.size();
this.xScrollBar.setMaximum(s); this.xScrollBar.setMaximum(s);
repaint(); repaint();
} }
} }

View File

@ -42,7 +42,7 @@ public class SMAIndicator implements Indicator {
indicator = new OHLCData(); indicator = new OHLCData();
} }
int len = 38; int len = 0;
float getAt(int pos) { float getAt(int pos) {
if (parent.size() == 0) { if (parent.size() == 0) {
@ -66,7 +66,7 @@ public class SMAIndicator implements Indicator {
return sum / (pos - start + 1); return sum / (pos - start + 1);
} }
void update() { public void update() {
//parent = Globals.se.getOHLCdata(60000 * 10); //parent = Globals.se.getOHLCdata(60000 * 10);
System.out.printf("Data %d\n", parent.size()); System.out.printf("Data %d\n", parent.size());