Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Submit JForex API bug reports in this forum only.
    Submit Converter issues in Converter Issues.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Strange IChartObject.move() behaviour
 Post subject: Strange IChartObject.move() behaviour Post rating: 0   New post Posted: Wed 06 Apr, 2016, 11:49 

User rating: 1
Joined: Tue 24 Apr, 2012, 13:41
Posts: 39
Hello,

Why the move() usage causes object escape? Just after initialization it looks OK, but with every single tick - and move() usage - the line moves further and further from the place I have expected...

See Attached code below.

Regards,
Fxer

package jforex;

import java.awt.Color;
import java.util.UUID;

import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IChart;
import com.dukascopy.api.IChartObject;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.Period;
import com.dukascopy.api.drawings.IShortLineChartObject;

public class ChObjTst implements IStrategy {
    private Instrument instrument = Instrument.EURUSD;

    private Marker markerLong = null;

    private class Marker {
        IContext context;
        IHistory history;
        Instrument instrument = Instrument.EURUSD;

        double price;
        String objectKey;

        Marker(IContext context) throws JFException {
            this.context = context;
            this.history = context.getHistory();
            price = history.getLastTick(instrument).getBid();
            objectKey = UUID.randomUUID().toString();
        }

        private void drawInit(IChart chart, ITick tick) throws JFException {
            IShortLineChartObject line = chart.getChartObjectFactory().createShortLine(
                    objectKey,
                    history.getTimeForNBarsBack( chart.getSelectedPeriod(), tick.getTime(), 20 ),
                    price,
                    history.getTimeForNBarsForward( chart.getSelectedPeriod(), tick.getTime(), 10 ),
                    price );
            line.setColor(Color.RED);
            chart.add(line);
        }

        void drawInit(ITick tick) throws JFException {
            for (IChart chart : context.getCharts(instrument)) {
                drawInit(chart, tick);
            }
        }

        void drawUpdate(ITick tick) throws JFException {
            price = tick.getBid();
            for (IChart chart : context.getCharts(instrument)) {
                IChartObject object = chart.get(objectKey);
                if (object != null) {
                    object.move(
                            history.getTimeForNBarsBack( chart.getSelectedPeriod(), tick.getTime(), 20 ),
                            price);
                }
            }
        }

        void undraw(IChart chart) {
            IChartObject object = chart.get(objectKey);
            if (object == null) return;
            chart.remove(object);
        }

        void undraw() {
            for (IChart chart : context.getCharts(instrument)) {
                undraw(chart);
            }
        }
    }

    @Override
    public void onStart(IContext context) throws JFException {
        IHistory history = context.getHistory();
        markerLong = new Marker(context);
        markerLong.drawInit(history.getLastTick(instrument));
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        if(instrument != this.instrument) return;
        markerLong.drawUpdate(tick);
    }

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

    @Override
    public void onMessage(IMessage message) throws JFException {}

    @Override
    public void onAccount(IAccount account) throws JFException {}

    @Override
    public void onStop() throws JFException {
        markerLong.undraw();
    }
}


 
 Post subject: Re: Strange IChartObject.move() behaviour Post rating: 0   New post Posted: Fri 08 Apr, 2016, 07:50 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello,

Thank you for reporting this. This issue was resolved and it will be available in next release.

Please stay tuned.

Good luck and have a nice day


 

Jump to:  

  © 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