Dukascopy
 
 
Wiki JStore Search Login

JFOREX-3611 Problem IChart.remove after new version
 Post subject: JFOREX-3611 Problem IChart.remove after new version Post rating: 0   New post Posted: Thu 15 Mar, 2012, 16:08 
User avatar

User rating: 5
Joined: Fri 02 Sep, 2011, 10:08
Posts: 157
Location: FranceFrance
Hello, it's me again !

I'm on fire since JForex live app has been updated today !
My strategies dealing with charts + chartobjects working nicely since more
than a year have now some issues with the new version of JForex.

I have some issues with interacting between a swing interface and chartObjects.
Please see the portion of my code, part of a complete trade management strategy.

It creates a new tab with a checkbox and 3 price markers on the chart.
If you unselect the checkbox the 3 price markers should disappear.

The program does only the first stance, so just one line is removed.

All worked fine with the previous versions of JForex.
Maybe it is a focus issue... because in onStop() I'm calling the same method
and the 3 lines are being removed just fine...

Thanks for the fast response because it's my most valuable live trading tool.


                printOut.print("chart.removeBefore");
                chart.remove("MyEntryLine");
                // The program does not go after this stance.
                printOut.print("chart.removeAfter");
                chart.remove("MyStopLine");
                chart.remove("MyFirstTargetLine");





package jforex.strategies;

import com.dukascopy.api.drawings.IHorizontalLineChartObject;
import com.dukascopy.api.drawings.ILongLineChartObject;
import com.dukascopy.api.drawings.IOrderLineChartObject;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.Currency;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.JSpinner.*;
import java.text.*;


import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IOrder.State;

public class RiskManagerEnableBtnTest implements IStrategy {

    //   @Configurable("Selected instrument : ")
    public Instrument currentInstrument = Instrument.EURUSD;
    //  @Configurable("Option panel 02 visible : ")
    public boolean options02Visible = true;
    //  @Configurable("Option panel 03 visible : ")
    public boolean options03Visible = true;
    //  @Configurable("Entry margin : ")
    public double entryMargin = 0;
    //  @Configurable("Stop margin : ")
    public double stopMargin = 1;

    private PrintOut printOut;
    private int enablePrint = 1;
    private IContext context;
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IIndicators indicators;
    private IAccount account;
    private IAccount equity;
    private IChart chart;
    private IUserInterface userInterface;
    private JPanel myTab;
    private MyPanel myPanel;
    private String orderDirection = "Buy";

    private boolean firstTargetSelected = true;

    private DrawLines myLines;
    private Locale myLocale;
    private boolean calculation = true;
    private int autoUpdateEntry = 0;
    /* private EquityFieldListener;
    private EntryFieldListener; */


    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.userInterface = context.getUserInterface();
        this.indicators = context.getIndicators();
        this.context = context;
        this.account = context.getAccount();

        printOut = new PrintOut();
        myLocale = new Locale("en", "US");

        userInterface.removeBottomTab("Manager " + currentInstrument.toString());
        myTab = userInterface.getBottomTab("Manager " + currentInstrument.toString());

        try {
            SwingUtilities.invokeAndWait(new Runnable() {

                @Override
                public void run() {
                    myPanel = new MyPanel();
                    myTab.setLayout(new BorderLayout());
                    myTab.add(myPanel, BorderLayout.WEST);
                }
            });
        } catch (Exception e) {
            printOut.print(e.getMessage());
        }
        myLines = new DrawLines();
    }

    public void onAccount(IAccount account) throws JFException {

    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {

        userInterface.removeBottomTab("Manager " + currentInstrument.toString());
        myLines.showLines(false);

    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }


    class MyPanel extends JPanel {

        private JPanel panel_01;
        private JCheckBox checkBoxFirstTarget;

        MyPanel() {

            // second panel
            panel_01 = new JPanel();
            panel_01.setLayout(new GridLayout(4, 5, 5, 5));
            this.add(panel_01);
            panel_01.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Order options"));

            checkBoxFirstTarget = new JCheckBox("Draw lines");
            checkBoxFirstTarget.setSelected(true);
            panel_01.add(checkBoxFirstTarget);


            ActionListener checkBoxListener = new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    Object myCheckBox = e.getSource();

                    if (myCheckBox == checkBoxFirstTarget) {
                        if (checkBoxFirstTarget.isSelected()) {
                            firstTargetSelected = true;
                        } else {
                            firstTargetSelected = false;
                        }
                        myLines.showLines(firstTargetSelected);
                    }
                }
            };
            checkBoxFirstTarget.addActionListener(checkBoxListener);
        }
    }

    private class DrawLines {

        IHorizontalLineChartObject entryLine;
        IHorizontalLineChartObject stopLine;
        IHorizontalLineChartObject firstTargetLine;

        DrawLines() {
            chart = context.getChart(currentInstrument);
            showLines(firstTargetSelected);

        }

        private void showLines(boolean _firstTargetSelected) {

            if (_firstTargetSelected) {
                printOut.print("chart.showLines");
                double currentPrice = 0;
                try {
                    currentPrice = history.getLastTick(currentInstrument).getBid();
                } catch (JFException ex) {
                    printOut.print(ex);
                }

                entryLine = chart.getChartObjectFactory().createPriceMarker("MyEntryLine", currentPrice + 0.002);
                entryLine.setText(orderDirection, SwingConstants.LEFT);
                entryLine.setLineStyle(1);
                chart.addToMainChart(entryLine);

                stopLine = chart.getChartObjectFactory().createPriceMarker("MyStopLine", currentPrice - 0.005);
                stopLine.setText("Stop", SwingConstants.LEFT);
                stopLine.setColor(Color.DARK_GRAY);
                stopLine.setLineStyle(1);
                chart.addToMainChart(stopLine);

                firstTargetLine = chart.getChartObjectFactory().createPriceMarker("MyFirstTargetLine", currentPrice + 0.008);
                firstTargetLine.setText("1st Target", SwingConstants.LEFT);
                firstTargetLine.setColor(Color.DARK_GRAY);
                firstTargetLine.setLineStyle(1);
                chart.addToMainChart(firstTargetLine);

                entryLine.setChartObjectListener(new ChartListener());
                stopLine.setChartObjectListener(new ChartListener());
                firstTargetLine.setChartObjectListener(new ChartListener());

            } else {

                printOut.print("chart.removeBefore");
                chart.remove("MyEntryLine");
                // The program does not go after this stance.
                printOut.print("chart.removeAfter");
                chart.remove("MyStopLine");
                chart.remove("MyFirstTargetLine");
               
                chart.repaint();
            }
        }
    }

    public class ChartListener implements ChartObjectListener {

        public void attrChanged(ChartObjectEvent e) {
            //printOut.print("**** OBJECT attrChanged ! : "+e.getSource());
        }

        public void deleted(ChartObjectEvent e) {
            //printOut.print("**** OBJECT deleted ! : "+e.getSource());
        }

        public void deselected(ChartObjectEvent e) {
            //printOut.print("**** OBJECT deselected ! : "+e.getSource());
        }

        public void highlighted(ChartObjectEvent e) {
            //printOut.print("**** OBJECT highlighted ! : "+e.getSource());
        }

        public void highlightingRemoved(ChartObjectEvent e) {
            // printOut.print("**** OBJECT highlightingRemoved ! : "+e.getSource());
        }

        public void moved(ChartObjectEvent e) {
            //
        }

        public void selected(ChartObjectEvent e) {
        }
    }

    class PrintOut {

        private void print(Object message) {
            if (enablePrint == 1) {
                console.getOut().println(message);
            }
        }
    }
}


 
 Post subject: Re: JFOREX-3611 Problem IChart.remove after new version Post rating: 0   New post Posted: Fri 16 Mar, 2012, 09:40 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The issue has been registered. As a temporary workaround consider adding @RequiresFullAccess.


 
 Post subject: Re: JFOREX-3611 Problem IChart.remove after new version Post rating: 0   New post Posted: Fri 16 Mar, 2012, 14:37 
User avatar

User rating: 5
Joined: Fri 02 Sep, 2011, 10:08
Posts: 157
Location: FranceFrance
Hi,

@RequiresFullAccess works,

thanks a lot.


 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com