Chart Widget

The ICustomWidgetChartObject chart object can be used as a container for user's own JPanel and its contents. Note: The feature is available with JForex-API 2.7.11.


Consider a strategy which creates a chart widget with two buttons - one which draws prices lines and the other one which makes BUY market orders.

Chart Widget

package chart;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.Callable;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.drawings.ICustomWidgetChartObject;

public class WidgetTest implements IStrategy {

    public void onStart(final IContext context) throws JFException {
        final Instrument instrument = Instrument.EURUSD;
        final IChart chart = context.getChart(instrument);
        if (chart == null) {
                context.getConsole().getErr().println("No chart opened!");
        ICustomWidgetChartObject obj = chart.getChartObjectFactory().createChartWidget();
        obj.setText("Price marker adder");

        obj.setFillOpacity(0.1f); //use 0f for transparent chart widget

        JPanel panel = obj.getContentPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
        final JLabel label = new JLabel(chart.getAll().size() + " chart objects on chart");
        JButton button = new JButton("Add price marker on last Ask");
        button.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                try {
                            "PriceMarker" + System.currentTimeMillis(), 
                    label.setText(chart.getAll().size() + " chart objects on chart");
                } catch (JFException e1) {

        JButton buttonBuy = new JButton("Buy 0.1M");
        buttonBuy.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                context.executeTask(new Callable<IOrder>() {
                    public IOrder call() throws Exception {
                        return context.getEngine().submitOrder("order" + System.currentTimeMillis(), instrument, OrderCommand.BUY, 0.1);

        panel.add(Box.createRigidArea(new Dimension(0,10)));
        panel.add(Box.createRigidArea(new Dimension(0,5)));
        panel.add(Box.createRigidArea(new Dimension(0,5)));
        panel.setSize(new Dimension(250, 100));
        panel.setMinimumSize(new Dimension(250, 100));
        panel.setMaximumSize(new Dimension(350, 120));


    public void onTick(Instrument instrument, ITick tick) throws JFException {}
    public void onMessage(IMessage message) throws JFException {}
    public void onAccount(IAccount account) throws JFException {}
    public void onStop() throws JFException { }
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}

The information on this web site is provided only as general information, which may be incomplete or outdated. Click here for full disclaimer.