|
From: Viorel G. <vio...@gm...> - 2010-11-17 10:29:29
|
On 17.11.2010 12:17, cha...@li... wrote: > Send Chartsy-devel mailing list submissions to > cha...@li... > > To subscribe or unsubscribe via the World Wide Web, visit > https://lists.sourceforge.net/lists/listinfo/chartsy-devel > or, via email, send a message with subject or body 'help' to > cha...@li... > > You can reach the person managing the list at > cha...@li... > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Chartsy-devel digest..." > > > Today's Topics: > > 1. Developing a new chart (Viorel Gheba) > 2. Re: Developing a new chart (Alex Lourie) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Wed, 17 Nov 2010 11:24:09 +0200 > From: Viorel Gheba<vio...@gm...> > Subject: [Chartsy-devel] Developing a new chart > To: cha...@li... > Message-ID:<4CE...@gm...> > Content-Type: text/plain; charset="iso-8859-1" > > Hi Alex > > I tried to make a chart as you described. > This is the code that i used: > > > package org.chartsy.testmodule; > > import java.awt.Color; > import java.awt.Graphics2D; > import java.awt.Rectangle; > import org.chartsy.ema.EMA; > import org.chartsy.ema.OverlayProperties; > import org.chartsy.macd.IndicatorProperties; > import org.chartsy.macd.MACD; > import org.chartsy.main.ChartFrame; > import org.chartsy.main.ChartProperties; > import org.chartsy.main.chart.Chart; > import org.chartsy.main.data.ChartData; > import org.chartsy.main.data.Dataset; > import org.chartsy.main.utils.CoordCalc; > import org.chartsy.main.utils.Range; > import org.chartsy.main.utils.SerialVersion; > import org.chartsy.main.utils.StrokeGenerator; > > /** > * > * @author Viorel > */ > public class TestChart extends Chart > { > > private static final long serialVersionUID = SerialVersion.APPVERSION; > private EMA ema; > private MACD macd; > > private Dataset mainDataset; > > public TestChart() > { > ema = new EMA(); > OverlayProperties emaProps = > ema.getNode().getLookup().lookup(OverlayProperties.class); > emaProps.setPeriod(13); > macd = new MACD(); > IndicatorProperties macdProps = > macd.getNode().getLookup().lookup(IndicatorProperties.class); > macdProps.setFast(12); > macdProps.setSlow(26); > macdProps.setSmooth(9); > } > > private void setDataset(Dataset dataset) > { > if (mainDataset == null) > { > mainDataset = dataset; > calculateDatasets(); > } > else if (!mainDataset.equals(dataset)) > { > mainDataset = dataset; > calculateDatasets(); > } > } > > private void calculateDatasets() > { > ema.setDataset(mainDataset); > ema.calculate(); > macd.setDataset(mainDataset); > macd.calculate(); > } > > @Override public String getName() > { > return "Test Chart"; > } > > @Override public void paint(Graphics2D g, ChartFrame cf) > { > setDataset(cf.getChartData().getDataset()); > > ChartData cd = cf.getChartData(); > ChartProperties cp = cf.getChartProperties(); > Rectangle rect = cf.getSplitPanel().getChartPanel().getBounds(); > rect.grow(-2, -2); > Range range = cf.getSplitPanel().getChartPanel().getRange(); > > Dataset dataset = cd.getVisible(); > Dataset emaDataset = ema.visibleDataset(cf, EMA.EMA); > Dataset macdDataset = macd.visibleDataset(cf, MACD.HISTOGRAM); > > if (dataset != null&& emaDataset != null&& macdDataset != null) > { > g.setStroke(StrokeGenerator.getStroke(3)); > > int count = emaDataset.getItemsCount(); > for (int i = 0; i< count; i++) > { > double open = dataset.getOpenAt(i); > double close = dataset.getCloseAt(i); > double high = dataset.getHighAt(i); > double low = dataset.getLowAt(i); > > double x = cd.getX(i, rect); > double yOpen = cd.getY(open, rect, range); > double yClose = cd.getY(close, rect, range); > double yHigh = cd.getY(high, rect, range); > double yLow = cd.getY(low, rect, range); > > double candleWidth = cp.getBarWidth(); > > if (emaDataset.getDataItem(i) != null > && macdDataset.getDataItem(i) != null) > { > if (emaDataset.getCloseAt(i)> close&& > macdDataset.getCloseAt(i)> 0) > g.setColor(Color.GREEN); > else if (emaDataset.getCloseAt(i)< close&& > macdDataset.getCloseAt(i)< 0) > g.setColor(Color.RED); > else > g.setColor(Color.BLUE); > } > else > { > g.setColor(Color.BLUE); > } > > g.draw(CoordCalc.line(x, yLow, x, yHigh)); > g.draw(CoordCalc.line(x, yOpen, x - candleWidth/2, yOpen)); > g.draw(CoordCalc.line(x, yClose, x + candleWidth/2, > yClose)); > } > } > } > > } > > You ca see that I copied the OHLC code. > Note: > - Make sure that EMA and MACD packages are included in your project > libraries. > - Make EMA and MACD public packages. > > For more questions, please contact us. > Best regards, > Viorel > -------------- next part -------------- > An HTML attachment was scrubbed... > > ------------------------------ > > Message: 2 > Date: Wed, 17 Nov 2010 12:17:07 +0200 > From: Alex Lourie<dj...@gm...> > Subject: Re: [Chartsy-devel] Developing a new chart > To: cha...@li... > Message-ID: > <AAN...@ma...> > Content-Type: text/plain; charset="iso-8859-1" > > Hi Viorel! > > Thank you so much for the help. I've tried to do this on my own and came up > with something similar. > > I now only have 2 questions: > > 1. I think that the more correct code would be: > > if (emaDataset.getDataItem(i) != null&& emaDataset.getDataItem(i-1) != null > && macdDataset.getDataItem(i) != null&& > macdDataset.getDataItem(i-1) != null) > { > if (emaDataset.getCloseAt(i) >> emaDataset.getCloseAt(i-1) > && macdDataset.getCloseAt(i) >> macdDataset.getCloseAt(i-1) ) > g.setColor(Color.GREEN); > else if (emaDataset.getCloseAt(i) > < emaDataset.getCloseAt(i-1) > && macdDataset.getCloseAt(i) > < macdDataset.getCloseAt(i-1)) > g.setColor(Color.RED); > else > g.setColor(Color.BLUE); > } > > 2. Should it just compile? I had a problem at home with compiling this > module for some reason... > > > On Wed, Nov 17, 2010 at 11:24 AM, Viorel Gheba<vio...@gm...> wrote: > >> Hi Alex >> >> I tried to make a chart as you described. >> This is the code that i used: >> >> >> package org.chartsy.testmodule; >> >> import java.awt.Color; >> import java.awt.Graphics2D; >> import java.awt.Rectangle; >> import org.chartsy.ema.EMA; >> import org.chartsy.ema.OverlayProperties; >> import org.chartsy.macd.IndicatorProperties; >> import org.chartsy.macd.MACD; >> import org.chartsy.main.ChartFrame; >> import org.chartsy.main.ChartProperties; >> import org.chartsy.main.chart.Chart; >> import org.chartsy.main.data.ChartData; >> import org.chartsy.main.data.Dataset; >> import org.chartsy.main.utils.CoordCalc; >> import org.chartsy.main.utils.Range; >> import org.chartsy.main.utils.SerialVersion; >> import org.chartsy.main.utils.StrokeGenerator; >> >> /** >> * >> * @author Viorel >> */ >> public class TestChart extends Chart >> { >> >> private static final long serialVersionUID = SerialVersion.APPVERSION; >> private EMA ema; >> private MACD macd; >> >> private Dataset mainDataset; >> >> public TestChart() >> { >> ema = new EMA(); >> OverlayProperties emaProps = >> ema.getNode().getLookup().lookup(OverlayProperties.class); >> emaProps.setPeriod(13); >> macd = new MACD(); >> IndicatorProperties macdProps = >> macd.getNode().getLookup().lookup(IndicatorProperties.class); >> macdProps.setFast(12); >> macdProps.setSlow(26); >> macdProps.setSmooth(9); >> } >> >> private void setDataset(Dataset dataset) >> { >> if (mainDataset == null) >> { >> mainDataset = dataset; >> calculateDatasets(); >> } >> else if (!mainDataset.equals(dataset)) >> { >> mainDataset = dataset; >> calculateDatasets(); >> } >> } >> >> private void calculateDatasets() >> { >> ema.setDataset(mainDataset); >> ema.calculate(); >> macd.setDataset(mainDataset); >> macd.calculate(); >> } >> >> @Override public String getName() >> { >> return "Test Chart"; >> } >> >> @Override public void paint(Graphics2D g, ChartFrame cf) >> { >> setDataset(cf.getChartData().getDataset()); >> >> ChartData cd = cf.getChartData(); >> ChartProperties cp = cf.getChartProperties(); >> Rectangle rect = cf.getSplitPanel().getChartPanel().getBounds(); >> rect.grow(-2, -2); >> Range range = cf.getSplitPanel().getChartPanel().getRange(); >> >> Dataset dataset = cd.getVisible(); >> Dataset emaDataset = ema.visibleDataset(cf, EMA.EMA); >> Dataset macdDataset = macd.visibleDataset(cf, MACD.HISTOGRAM); >> >> if (dataset != null&& emaDataset != null&& macdDataset != null) >> { >> g.setStroke(StrokeGenerator.getStroke(3)); >> >> int count = emaDataset.getItemsCount(); >> for (int i = 0; i< count; i++) >> { >> double open = dataset.getOpenAt(i); >> double close = dataset.getCloseAt(i); >> double high = dataset.getHighAt(i); >> double low = dataset.getLowAt(i); >> >> double x = cd.getX(i, rect); >> double yOpen = cd.getY(open, rect, range); >> double yClose = cd.getY(close, rect, range); >> double yHigh = cd.getY(high, rect, range); >> double yLow = cd.getY(low, rect, range); >> >> double candleWidth = cp.getBarWidth(); >> >> if (emaDataset.getDataItem(i) != null >> && macdDataset.getDataItem(i) != null) >> { >> if (emaDataset.getCloseAt(i)> close&& >> macdDataset.getCloseAt(i)> 0) >> g.setColor(Color.GREEN); >> else if (emaDataset.getCloseAt(i)< close&& >> macdDataset.getCloseAt(i)< 0) >> g.setColor(Color.RED); >> else >> g.setColor(Color.BLUE); >> } >> else >> { >> g.setColor(Color.BLUE); >> } >> >> g.draw(CoordCalc.line(x, yLow, x, yHigh)); >> g.draw(CoordCalc.line(x, yOpen, x - candleWidth/2, yOpen)); >> g.draw(CoordCalc.line(x, yClose, x + candleWidth/2, >> yClose)); >> } >> } >> } >> >> } >> >> You ca see that I copied the OHLC code. >> Note: >> - Make sure that EMA and MACD packages are included in your project >> libraries. >> - Make EMA and MACD public packages. >> >> For more questions, please contact us. >> Best regards, >> Viorel >> >> >> ------------------------------------------------------------------------------ >> Beautiful is writing same markup. Internet Explorer 9 supports >> standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2& L3. >> Spend less time writing and rewriting code and more time creating great >> experiences on the web. Be a part of the beta today >> http://p.sf.net/sfu/msIE9-sfdev2dev >> _______________________________________________ >> Chartsy-devel mailing list >> Cha...@li... >> https://lists.sourceforge.net/lists/listinfo/chartsy-devel >> >> > Hi Alex, 1. My code was an example :). Make the changes that you need to implement the new chart. 2. Can you please send me the error text? Best regards, Viorel |