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 create multiple IChartObjectFactory objects in strategy?
 Post subject: How to create multiple IChartObjectFactory objects in strategy? Post rating: 0   New post Posted: Sun 21 Oct, 2012, 20:53 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Dear Support,

How can I create multiple ITextChartObject objects in a strategy?
I am using this wikipage as example: https://www.dukascopy.com/wiki/#Chart_object_catalog/Text

I want to place a new text object whenever a condition is fulfilled in my strategy`s onBar() function. However not a new text object being created every time, but the first one is being moved.

public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException
{
    ....
    ITextChartObject text = factory.createText("textKey", prevBar.getTime(), prevBar.getLow());
    text.setText("Hello world");
    chart.addToMainChart(text);
    ....
}


text is again, and again, newly declared (and defined) in the onBar function as a ITextChartObject variable. I would say a new ITextChartObject variable is being created, so I would suspect that this way multiple variables are being created. This is not the case.
If text would be a pointer to a ITextChartObject variable, I could imagine why it is always the same object on the bar, but not this way.

I know that manually, on a chart multiple chart objects can be placed, so I guess there must be a way to do this programatically.

Please advice.

Thanks and regards.


 
The Best Answer  Post subject: Re: How to create multiple IChartObjectFactory objects in strategy? Post rating: 0   New post Posted: Sun 21 Oct, 2012, 22:24 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi tcsabina:

Well, it's just a suposition, not tested, but i think you must declare different name key to create different objects key, that means you have to change the "TextKey" value. Don't know how Ichart reacts using the same "text" variable, but only testing we can see, there is a chance you have to change this too.

I hope that helps

Best regards

JL


 
 Post subject: Re: How to create multiple IChartObjectFactory objects in strategy? Post rating: 0   New post Posted: Mon 22 Oct, 2012, 07:18 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You need to specify a unique key for each chart object, otherwise it gets overwritten, see:
https://www.dukascopy.com/wiki/#Create_and_manage_chart_objects/key_usage


 
 Post subject: Re: How to create multiple IChartObjectFactory objects in strategy? Post rating: 0   New post Posted: Thu 25 Oct, 2012, 21:37 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Thank for the replies.

I was able to manage it with the unique key.
For someone who might look for a similar solution:
I used a global variable in the key part, and increased it every time an chart object was created:
factory.createText("textKey" + count++, bar.getTime(), bar.getLow());


 

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