interface with the methods to draw on charts
There are 31 types of drawings located in the IChart.Type enumeration which
can be created, modified and removed through the IChart interface.
Before putting a drawing on a chart, be sure you use the correct chart by using
the following code snippet:
if (instrument != currencyPairYouWantToDrawOn) { IChart chart = context.getChart(instrument); if (chart != null) { // use chart object to create and manipulate drawings } }
If you want to access previous ticks/bars please use the following methods:
public List<ITick> getTicks(Instrument instrument, long from, long to) throws JFException; public List<IBar> getBars(Instrument instrument, Period period, OfferSide side, long from, long to) throws JFException;
So, to obtain ticks for a EUR/USD chart in the time period of 60 seconds from "now" you should use the following code:
List<ITick> ticks = history.getTicks(Instrument.EURUSD, tick.getTime() - 60 * 1000L, tick.getTime());
Don't forget to check the returned value:
if (ticks != null && !ticks.isEmpty) { // code which uses history ticks }
Drawing type | Drawing description | How it looks on the chart window |
---|---|---|
VLINE | A vertical line from the left to the
right side of the chart window. Code example:double price1 = (tick.getAsk() + tick.getBid()) / 2; chart.draw("vLine", IChart.Type.VLINE, tick.getTime(), price1); |
|
HLINE | A horizontal line from the top to the
bottom side of the chart window. Code example:double price1 = (tick.getAsk() + tick.getBid()) / 2; chart.draw("hLine", IChart.Type.HLINE, tick.getTime(), price1); |
|
POLY_LINE | a line which consists of many short lines connected together |
|
SHORT_LINE | A short line. Code example:List<ITick> ticks = history.getTicks(Instrument.EURUSD, tick.getTime() - 60 * 1000L, tick.getTime()); if (ticks != null && !ticks.isEmpty()) { ITick firstTick = ticks.get(0); ITick lastTick = ticks.get(ticks.size() - 1); chart.draw("shortLine", IChart.Type.SHORT_LINE, firstTick.getTime(), firstTick.getAsk(), lastTick.getTime(), lastTick.getAsk() ); } |
|
LONG_LINE | A line which traverses the whole chart
window. Code example:List<ITick> ticks = history.getTicks(Instrument.EURUSD, tick.getTime() - 60 * 1000L, tick.getTime()); if (ticks != null && !ticks.isEmpty()) { ITick firstTick = ticks.get(0); ITick lastTick = ticks.get(ticks.size() - 1); chart.draw("longLine", IChart.Type.LONG_LINE, firstTick.getTime(), firstTick.getAsk(), lastTick.getTime(), lastTick.getAsk() ); } |
|
TREND | (not yet implemented) | no picture available |
TRENDBYANGLE | (not yet implemented) | no picture available |
FIBOCHANNEL | (not yet implemented) | no picture available |
REGRESSION | (not yet implemented) | no picture available |
CHANNEL | Two parallel lines which indicate a trend.
Code example:List<ITick> ticks = history.getTicks(Instrument.EURUSD, tick.getTime() - 60 * 1000L, tick.getTime()); if (ticks != null && !ticks.isEmpty()) { ITick firstTick = ticks.get(0); ITick lastTick = ticks.get(ticks.size() - 1); chart.draw("channelLine", IChart.Type.CHANNEL, firstTick.getTime(), firstTick.getAsk(), lastTick.getTime(), lastTick.getAsk(), lastTick.getTime(), lastTick.getBid() ); } |
|
GANNLINE | (not yet implemented) | no picture available |
GANNFAN | (not yet implemented) | no picture available |
GANNGRID | (not yet implemented) | no picture available |
STDDEVCHANNEL | (not yet implemented) | no picture available |
FIBO |
|
|
FIBOTIMES |
|
|
FIBOFAN |
|
|
FIBOARC |
|
|
EXPANSION | (not yet implemented) | no picture available |
RECTANGLE | Code example:double askBidDiff = Math.abs(tick.getAsk() - tick.getBid()); chart.draw("rectangle1", IChart.Type.RECTANGLE, tick.getTime(), tick.getAsk(), tick.getTime() - 60 * 1000L, tick.getAsk() + askBidDiff * 4); |
|
TRIANGLE | Code example:ITick firstTick = ticks.get(0);
ITick lastTick = ticks.get(ticks.size() - 1);
ITick middleTick = ticks.get(ticks.size() / 2);
chart.draw("triangle1", IChart.Type.TRIANGLE,
firstTick.getTime(), firstTick.getAsk(),
lastTick.getTime(), lastTick.getAsk(),
middleTick.getTime(), middleTick.getAsk()
);
|
|
ELLIPSE |
|
|
PITCHFORK | (not yet implemented) | no picture available |
CYCLES | (not yet implemented) | no picture available |
PERCENT |
|
|
TEXT |
|
|
LABEL | (not yet implemented) | no picture available |
SIGNAL_UP |
|
|
SIGNAL_DOWN |
|
A drawing can either be in a locked or unlocked state. Unlocked drawings can
be modified through mouse manipulations and unlocked drawings cannot. The state
of a drawing is set at the creation time by either calling the draw (...) or
drawUnlocked(...) method and therefore cannot be changed.
Depending on the type of drawing you should use different parameter sets:
String key, IChart.Type type, long time1, double price1 String key, IChart.Type type, long time1, double price1, long time2, double price2 String key, IChart.Type type, long time1, double price1, long time2, double price2, long time3, double price3
The first parameter (key) is a unique identifier which is used to access the
drawing later from the IChart. It can contain any characters and numbers.
The second parameter (type) defines the type of drawing, e.g. IChart.Type.VLINE,
IChart.Type.HLINE.
The next parameter (time1, price1,) defines and coordinates which are necessary
to display the drawing. For example to set a vertical line you should only define
a price but to set a triangle you should define all the three 'edges' (time-price
pairs). If you the amount of coordinates doesn't suffice to display a drawing
then a null reference is returned, so don't forget to check the returned reference!
To delete a drawing simple call:
remove(String key)
To delete all drawings call:
removeAll()
After a drawing has been removed it cannot be modified and its unique key can
be used with another drawing.
To move a drawing use either the method from the IChart interface:
public void move(IChartObject objectToMove, long newTime, double newPrice);
or the method from the IChartObject itself:
public void move(long time, double price);
IChartObjects attributes are accessed by using the following constants from the IChartObject interface:
public enum ATTR_LONG { TIME1, // Datetime value to set/get first coordinate time part. TIME2, // Datetime value to set/get second coordinate time part. TIME3 // Datetime value to set/get third coordinate time part. } public enum ATTR_DOUBLE { PRICE1, // Double value to set/get first coordinate price part. PRICE2, // Double value to set/get second coordinate price part. PRICE3, // Double value to set/get third coordinate price part. SCALE, // Double value to set/get scale object property. ANGLE, // Double value to set/get angle object property in degrees. DEVIATION, // Double value to set/get deviation property for Standard deviation objects. FIBO_LEVEL1, // Fibonacci object level index 1 to set/get. FIBO_LEVEL2, // Fibonacci object level index 2 to set/get. FIBO_LEVEL3, // Fibonacci object level index 3 to set/get. FIBO_LEVEL4, // Fibonacci object level index 4 to set/get. FIBO_LEVEL5, // Fibonacci object level index 5 to set/get. FIBO_LEVEL6, // Fibonacci object level index 6 to set/get. FIBO_LEVEL7, // Fibonacci object level index 7 to set/get. FIBO_LEVEL8, // Fibonacci object level index 8 to set/get. FIBO_LEVEL9, // Fibonacci object level index 9 to set/get. FIBO_LEVEL10, // Fibonacci object level index 10 to set/get. FIBO_LEVEL11, // Fibonacci object level index 11 to set/get. FIBO_LEVEL12, // Fibonacci object level index 12 to set/get. FIBO_LEVEL13, // Fibonacci object level index 13 to set/get. FIBO_LEVEL14, // Fibonacci object level index 14 to set/get. FIBO_LEVEL15, // Fibonacci object level index 15 to set/get. FIBO_LEVEL16, // Fibonacci object level index 16 to set/get. FIBO_LEVEL17, // Fibonacci object level index 17 to set/get. FIBO_LEVEL18, // Fibonacci object level index 18 to set/get. FIBO_LEVEL19, // Fibonacci object level index 19 to set/get. FIBO_LEVEL20, // Fibonacci object level index 20 to set/get. FIBO_LEVEL21, // Fibonacci object level index 21 to set/get. FIBO_LEVEL22, // Fibonacci object level index 22 to set/get. FIBO_LEVEL23, // Fibonacci object level index 23 to set/get. FIBO_LEVEL24, // Fibonacci object level index 24 to set/get. FIBO_LEVEL25, // Fibonacci object level index 25 to set/get. FIBO_LEVEL26, // Fibonacci object level index 26 to set/get. FIBO_LEVEL27, // Fibonacci object level index 27 to set/get. FIBO_LEVEL28, // Fibonacci object level index 28 to set/get. FIBO_LEVEL29, // Fibonacci object level index 29 to set/get. FIBO_LEVEL30, // Fibonacci object level index 30 to set/get. FIBO_LEVEL31, // Fibonacci object level index 31 to set/get. FIBO_LEVEL32, // Fibonacci object level index 32 to set/get. } public enum ATTR_INT { STYLE, // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object line style. WIDTH, // Integer value to set/get object line width. Can be from 1 to 5. FONTSIZE, // Integer value to set/get font size for text objects. LEVELSTYLE, // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants to set/get object level line style. FIBOLEVELS, // Integer value to set/get Fibonacci object level count. Can be from 0 to 32. LEVELWIDTH, // Integer value to set/get object level line width. Can be from 1 to 5. ARROWCODE, // Integer value or arrow enumeration to set/get arrow code object property. TIMEFRAMES, // Value can be one or combination (bitwise addition) of object visibility constants to set/get timeframe object property. CORNER, // Integer value to set/get anchor corner property for label objects. Must be from 0-3. XDISTANCE, // Integer value to set/get anchor X distance object property in pixels. YDISTANCE, // Integer value is to set/get anchor Y distance object property in pixels. } public enum ATTR_COLOR { LEVELCOLOR, // Color value to set/get object level line color. COLOR // Color value to set/get object color. } public enum ATTR_BOOLEAN { BACK, // Boolean value to set/get background drawing flag for object. RAY, // Boolean value to set/get ray flag of object. ELLIPSE // Boolean value to set/get ellipse flag for fibo arcs. }
To set/get an attribute use one of the following methods:
public void setAttrLong(ATTR_LONG field, long value); public void setAttrDouble(ATTR_DOUBLE field, double value); public void setAttrInt(ATTR_INT field, int value); public void setAttrBoolean(ATTR_BOOLEAN field, boolean value); public void setAttrColor(ATTR_COLOR field, Color value); public long getAttrLong(ATTR_LONG field); public double getAttrDouble(ATTR_DOUBLE field); public int getAttrInt(ATTR_INT field); public boolean getAttrBoolean(ATTR_BOOLEAN field); public Color getAttrColor(ATTR_COLOR field);