Imroved Indicator interface, draws two indicators now
This commit is contained in:
parent
ff0e8bc4b9
commit
f6eab6b6a2
@ -1,4 +1,4 @@
|
|||||||
#Sat, 25 Nov 2017 01:27:15 +0100
|
#Sat, 25 Nov 2017 09:25:34 +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=
|
||||||
|
@ -41,8 +41,7 @@ import sesim.OHLCData;
|
|||||||
import sesim.OHLCDataItem;
|
import sesim.OHLCDataItem;
|
||||||
import sesim.Quote;
|
import sesim.Quote;
|
||||||
import indicators.SMAIndicator;
|
import indicators.SMAIndicator;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -52,10 +51,15 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
|
|||||||
|
|
||||||
private ChartDef chartDef;
|
private ChartDef chartDef;
|
||||||
|
|
||||||
SMAIndicator sma;
|
SMAIndicator sma1, sma2;
|
||||||
|
|
||||||
class MyOHLCData extends OHLCData {
|
class MyOHLCData extends OHLCData {
|
||||||
|
|
||||||
|
SMAIndicator sma;
|
||||||
|
|
||||||
|
MyOHLCData(SMAIndicator sma) {
|
||||||
|
this.sma = sma;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
@ -126,13 +130,30 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
|
|||||||
chart.setXSCrollBar(xScrollBar);
|
chart.setXSCrollBar(xScrollBar);
|
||||||
chart.addChartPainter(new ChartCrossPainter());
|
chart.addChartPainter(new ChartCrossPainter());
|
||||||
|
|
||||||
sma = new indicators.SMAIndicator(mydata);
|
sma1 = new indicators.SMAIndicator();
|
||||||
MyOHLCData mysma = new MyOHLCData();
|
sma1.setParent(mydata);
|
||||||
|
|
||||||
|
JSONObject co;
|
||||||
|
co = new JSONObject("{\"len\": 60}");
|
||||||
|
sma1.putConfig(co);
|
||||||
|
MyOHLCData mysma1;
|
||||||
|
mysma1 = new MyOHLCData(sma1);
|
||||||
p = new LineChartPainter();
|
p = new LineChartPainter();
|
||||||
p.setOHLCData(mysma);
|
p.setOHLCData(mysma1);
|
||||||
//p.setDataProvider(new SMA(get()));
|
|
||||||
chart.addChartPainter(p);
|
chart.addChartPainter(p);
|
||||||
|
|
||||||
|
sma2 = new indicators.SMAIndicator();
|
||||||
|
sma2.setParent(mydata);
|
||||||
|
co = new JSONObject("{\"len\": 20}");
|
||||||
|
sma2.putConfig(co);
|
||||||
|
MyOHLCData mysma2;
|
||||||
|
mysma2 = new MyOHLCData(sma2);
|
||||||
|
p = new LineChartPainter();
|
||||||
|
p.setOHLCData(mysma2);
|
||||||
|
chart.addChartPainter(p);
|
||||||
|
|
||||||
|
|
||||||
ChartPainter yp = new YLegendPainter(chart);
|
ChartPainter yp = new YLegendPainter(chart);
|
||||||
// yp.setDataProvider(this);
|
// yp.setDataProvider(this);
|
||||||
yp.setOHLCData(mydata);
|
yp.setOHLCData(mydata);
|
||||||
@ -276,9 +297,14 @@ public class MasterChart extends javax.swing.JPanel implements QuoteReceiver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void UpdateQuote(Quote q) {
|
public void UpdateQuote(Quote q) {
|
||||||
if (sma != null) {
|
if (sma1 != null) {
|
||||||
sma.update();
|
sma1.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sma2 != null) {
|
||||||
|
sma2.update();
|
||||||
|
}
|
||||||
|
|
||||||
int s = mydata.size();
|
int s = mydata.size();
|
||||||
this.xScrollBar.setMaximum(s);
|
this.xScrollBar.setMaximum(s);
|
||||||
repaint();
|
repaint();
|
||||||
|
@ -138,6 +138,7 @@ public class Globals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static AutoTraderLoader tloader;
|
static AutoTraderLoader tloader;
|
||||||
|
static IndicatorLoader iloader;
|
||||||
|
|
||||||
static void initGlobals() {
|
static void initGlobals() {
|
||||||
ArrayList default_pathlist = new ArrayList<>();
|
ArrayList default_pathlist = new ArrayList<>();
|
||||||
@ -149,10 +150,13 @@ public class Globals {
|
|||||||
default_pathlist.add(default_path);
|
default_pathlist.add(default_path);
|
||||||
tloader = new AutoTraderLoader(default_pathlist);
|
tloader = new AutoTraderLoader(default_pathlist);
|
||||||
|
|
||||||
|
iloader = new IndicatorLoader(default_pathlist);
|
||||||
|
|
||||||
SeSimClassLoader<Indicator> il = new SeSimClassLoader<>(Indicator.class);
|
iloader.getNames();
|
||||||
il.setDefaultPathList(default_pathlist);
|
|
||||||
ArrayList<Class<Indicator>>ires = il.getInstalledClasses();
|
// SeSimClassLoader<Indicator> il = new SeSimClassLoader<>(Indicator.class);
|
||||||
|
// il.setDefaultPathList(default_pathlist);
|
||||||
|
// ArrayList<Class<Indicator>> ires = il.getInstalledClasses();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017, tube
|
* Copyright (c) 2017, 7u83
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -26,13 +26,14 @@
|
|||||||
package indicators;
|
package indicators;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import sesim.ConfigurableInterface;
|
||||||
import sesim.Indicator;
|
import sesim.Indicator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author tube
|
* @author tube
|
||||||
*/
|
*/
|
||||||
public abstract class BaseIndicator implements Indicator{
|
public abstract class BaseIndicator implements Indicator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package indicators;
|
package indicators;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
import sesim.OHLCData;
|
import sesim.OHLCData;
|
||||||
import sesim.OHLCDataItem;
|
import sesim.OHLCDataItem;
|
||||||
|
|
||||||
@ -38,16 +39,31 @@ public class SMAIndicator extends BaseIndicator {
|
|||||||
|
|
||||||
OHLCData indicator;
|
OHLCData indicator;
|
||||||
|
|
||||||
public SMAIndicator(OHLCData parent) {
|
public SMAIndicator() {
|
||||||
this.parent = parent;
|
|
||||||
indicator = new OHLCData();
|
indicator = new OHLCData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParent(OHLCData parent){
|
public void setParent(OHLCData parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String LEN = "len";
|
||||||
|
int len = 60;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void putConfig(JSONObject cfg) {
|
||||||
|
|
||||||
|
len = cfg.getInt(LEN);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = 20;
|
@Override
|
||||||
|
public JSONObject getConfig() {
|
||||||
|
JSONObject r;
|
||||||
|
r = new JSONObject();
|
||||||
|
r.put(LEN, len);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
private float getAt(int pos) {
|
private float getAt(int pos) {
|
||||||
if (parent.size() == 0) {
|
if (parent.size() == 0) {
|
||||||
@ -68,7 +84,6 @@ public class SMAIndicator extends BaseIndicator {
|
|||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
|
|
||||||
|
|
||||||
if (parent.size() == 0) {
|
if (parent.size() == 0) {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -31,7 +31,7 @@ import org.json.JSONObject;
|
|||||||
*
|
*
|
||||||
* @author tube
|
* @author tube
|
||||||
*/
|
*/
|
||||||
public interface ConfigurableInterface {
|
public abstract interface ConfigurableInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current configuration as JSON object.
|
* Get current configuration as JSON object.
|
||||||
|
@ -32,15 +32,31 @@ import java.util.ArrayList;
|
|||||||
* @author 7u83 <7u83@mail.ru>
|
* @author 7u83 <7u83@mail.ru>
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public class IndicatorLoader<T> extends SeSimClassLoader {
|
public class IndicatorLoader extends SeSimClassLoader<Indicator> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param class_type
|
* @param class_type
|
||||||
*/
|
*/
|
||||||
public IndicatorLoader(Class class_type) {
|
public IndicatorLoader(ArrayList<String> path_list) {
|
||||||
super(class_type);
|
super(Indicator.class, path_list);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getNames() {
|
||||||
|
ArrayList<Class<Indicator>> indicators;
|
||||||
|
indicators = this.getInstalledClasses();
|
||||||
|
for (Class<Indicator> ic : indicators) {
|
||||||
|
Indicator i = (Indicator) this.newInstance(ic);
|
||||||
|
|
||||||
|
String name = i.getName();
|
||||||
|
System.out.printf("Name of Indicator: %s", name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ArrayList<String>();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user