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.

Programmatically changing a chart instrument
 Post subject: Programmatically changing a chart instrument Post rating: 0   New post Posted: Wed 04 Mar, 2015, 05:18 
User avatar

User rating: 0
Joined: Fri 10 Oct, 2014, 00:35
Posts: 58
Location: New Zealand, Auckland
Hi

I am trying to implement simplified chart linking by writing a strategy program that changes the chart instrument to the desired instrument when the mouse is clicked on a chart. However, I cannot get my program to change the chart instrument and I would appreciate any advice.

I have attached a simple program to illustrate the problem.

The program remembers the instrument of the active chart when the user makes a selection - the desired instrument.
When the user selects another chart and clicks on the chart, my program attempts to change the instrument of the newly active chart. This does not work.

I can change the feed descriptor, but the visible chart does not change and activeChart.getInstrument() does not change. I can't find a way of getting the chart to recognise the descriptor change.

I'm stuck and would like any help possible.

Cheers
Tony

This is the mouse listener method:
    @Override
    public void mouseClicked( IChartPanelMouseEvent e ) {
       
        IChart activeChart = context.getLastActiveChart();
        Instrument activeInstrument = activeChart.getInstrument();
       
        // chart changed?
        if( !activeChart.equals( prevActiveChart ) ) {
            printDebug( "mouseClicked(): Chart changed." );
            printDebug( "mouseClicked(): prevActiveChart = " + prevActiveChart.toString() + ": " + prevActiveChart.getInstrument().toString() + ", " + prevActiveChart.getSelectedPeriod().toString() );
            printDebug( "mouseClicked(): activeChart = " + activeChart.toString() + ": " + activeInstrument.toString() + ", " + activeChart.getSelectedPeriod().toString() );
           
            printDebug( "mouseClicked(): desiredInstrument = " + desiredInstrument.toString() + ", activeInstrument = " + activeInstrument.toString() );
            if( !activeInstrument.equals( desiredInstrument ) ) {
                // change the chart instrument
                IFeedDescriptor feed = activeChart.getFeedDescriptor();
                printDebug( "mouseClicked(): Current feed descriptor = " + feed.toString() + ", activeInstrument = " + activeInstrument.toString() );
                feed.setInstrument( desiredInstrument );
//                activeChart.setInstrument( desiredInstrument );    // deprecated
                printDebug( "mouseClicked(): After setting, feed descriptor = " + feed.toString() + ", activeInstrument = " + activeInstrument.toString() );
                //activeChart.repaint();    // ??? necessary?
            }
            prevActiveChart = activeChart;
        }
        // deisred instrument changed, i.e. instrument changed but not chart
        else if ( !activeInstrument.equals( desiredInstrument ) ) {
            printDebug( "mouseClicked(): Instrument changed." );
            printDebug( "mouseClicked(): desiredInstrument was " + desiredInstrument.toString() + ", desiredInstrument becomes " + activeInstrument.toString() );
            desiredInstrument = activeInstrument;
        }
        else {
            printDebug( "mouseClicked(): No change." );
        }
       
        // print current state
        openCharts = context.getCharts();
        for( IChart c : openCharts ) {
            printDebug( "mouseClicked(): " + c.toString() + ": " + c.getInstrument() + " " + c.getSelectedPeriod().toString() );
        }
     }


Attachments:
TestInstrumentChange.java [4.79 KiB]
Downloaded 68 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Programmatically changing a chart instrument Post rating: 0   New post Posted: Mon 30 Mar, 2015, 18:44 
User avatar

User rating: 0
Joined: Fri 17 Jan, 2014, 18:13
Posts: 72
Location: NetherlandsNetherlands
Same question here.

How can i change the chart's instrument within a strategy?

However i found more or less the answer: it can't.

https://www.dukascopy.com/swiss/english ... ent#p77716


 
 Post subject: Re: Programmatically changing a chart instrument Post rating: 0   New post Posted: Thu 09 Apr, 2015, 07:51 
User avatar

User rating: 0
Joined: Fri 10 Oct, 2014, 00:35
Posts: 58
Location: New Zealand, Auckland
Thanks for finding this "answer". I thought I remembered reading something like that but couldn't find it again.

Cheers
Tony


 

Jump to:  

cron
  © 1998-2024 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