Dukascopy
 
 
Wiki JStore Search Login

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

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

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

How to recognize selected object
 Post subject: How to recognize selected object Post rating: 0   New post Posted: Wed 05 Nov, 2014, 15:05 

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

I want to convert particular channel to trend line. In order to do this I planned (1) to select the channel, (2) run strategy that (2a) deletes the channel and (2b) creates trend line with particular parameters and finally (3) stop the strategy. Sometimes it is not easy confirm that there is selected the right object (for example time frame change might be necessary), thus I would rather prefer select the object before run the code than listen to chart object selection. I do not know how to recognize object that had been selected before strategy was run. Would you suggest me something?

Regards,
Fxer


 
 Post subject: Re: How to recognize selected object Post rating: 0   New post Posted: Fri 07 Nov, 2014, 10:13 
User avatar

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

Unfortunately there is no functionality that allows you to get chart objects selected before strategy run.

Maybe something like that can solve the problem:
1. Run strategy
2. Strategy adds listener to all object on all charts
3. Needed object is manually selected and gets processed by listener as needed

Here is example:

public class SelectedObjectExample extends ChartObjectAdapter implements IStrategy {

    private IContext context;
    private IConsole console;

    public void onStart(IContext context) throws JFException {
        this.context = context;
        this.console = context.getConsole();

        for (IChart chart : context.getCharts()) {
            for (IChartObject chartObject : chart.getAll()) {
                chartObject.setChartObjectListener(this);
            }
        }               
    }
   
    @Override
    public void selected(ChartObjectEvent e) {
        IChartObject object = (IChartObject) e.getSource();
        console.getOut().println(object);
    }

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

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

    @Override
    public void onStop() throws JFException {
    }

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

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


 

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