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.

Strange strategy - drawings behavior
 Post subject: Strange strategy - drawings behavior Post rating: 0   New post Posted: Fri 29 Jul, 2016, 07:15 
User avatar

User rating: 2
Joined: Sat 05 May, 2012, 13:08
Posts: 33
Location: ItalyItaly
Hello support,

I notice there is a strange " flashening "on chart drawings sent by the strategy I'm building, The logic is under " onBar " method so the event should be executed once every 1 minute bar (in this case), while the logic is somehow repeated MANY times every new 1 minute bar causing that lines are drawn and then quickly re-drawn.

I tried many different ways to avoid this, but without success.

Is there something wrong / missing in the code itself?

Here's extracted part of code. It is repeated for 4 instruments, but the same behavior happens even with 1 single instrument:

if (period.equals(Period.ONE_MIN)){
        for (IChart chart : context.getCharts(SelectedInstrument2)) {
                 if (chart.getSelectedPeriod().equals(Period.FIVE_MINS) && SelectedInstrument2.equals(chart.getInstrument())){
                 
                 IPriceMarkerChartObject Line1 =
                                chart.getChartObjectFactory().createPriceMarker("H1L", price1);
                 IPriceMarkerChartObject Line2 =
                                chart.getChartObjectFactory().createPriceMarker("H1P", price2);
                 H1HighOpen.setColor(h1Color);

                        Line1 .setLineWidth(L1Width);
                        Line1 .setLineStyle(L1Style);
                        Line1 .setOpacity(0.6f);
                        Line1 .setText("L1");
                       
                        Line2 .setColor(L1Color);
                        Line2 .setLineWidth(L1Width);
                        Line2 .setLineStyle(L1Style);
                        Line2 .setOpacity(0.6f);
                        Line2 .setText("L1");

                        chart.add(Line1);
                        chart.add(Line2);

                 }
         }
}


Thank you


 
 Post subject: Re: Strange strategy - drawings behavior Post rating: 0   New post Posted: Tue 09 Aug, 2016, 16:39 
User avatar

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

IStrategy.onBar() method is called for every subscribed instrument, so you should add check of corresponding condition in your code.
Also, consider moving existing lines to new price instead of creating new lines.

if (instrument.equals(SelectedInstrument2) && period.equals(Period.ONE_MIN)) {
for (IChart chart : context.getCharts(SelectedInstrument2)) {
if (chart.getSelectedPeriod().equals(Period.FIVE_MINS)) {
IPriceMarkerChartObject Line1 = (IPriceMarkerChartObject) chart.get("H1L");
IPriceMarkerChartObject Line2 = (IPriceMarkerChartObject) chart.get("H1P");
if (Line1 == null) {
Line1 = chart.getChartObjectFactory().createPriceMarker("H1L", price1);
...
chart.add(Line1);
} else {
Line1.setPrice(0, price1);
}
if (Line2 == null) {
Line2 = chart.getChartObjectFactory().createPriceMarker("H1P", price2);
...
chart.add(Line2);
} else {
Line2.setPrice(0, price2);
}
}
}
}

Kind regards, Support Team.


 
 Post subject: Re: Strange strategy - drawings behavior Post rating: 0   New post Posted: Tue 09 Aug, 2016, 22:20 
User avatar

User rating: 2
Joined: Sat 05 May, 2012, 13:08
Posts: 33
Location: ItalyItaly
API Support wrote:
Hello.

IStrategy.onBar() method is called for every subscribed instrument, so you should add check of corresponding condition in your code.
Also, consider moving existing lines to new price instead of creating new lines.

if (instrument.equals(SelectedInstrument2) && period.equals(Period.ONE_MIN)) {
for (IChart chart : context.getCharts(SelectedInstrument2)) {
if (chart.getSelectedPeriod().equals(Period.FIVE_MINS)) {
IPriceMarkerChartObject Line1 = (IPriceMarkerChartObject) chart.get("H1L");
IPriceMarkerChartObject Line2 = (IPriceMarkerChartObject) chart.get("H1P");
if (Line1 == null) {
Line1 = chart.getChartObjectFactory().createPriceMarker("H1L", price1);
...
chart.add(Line1);
} else {
Line1.setPrice(0, price1);
}
if (Line2 == null) {
Line2 = chart.getChartObjectFactory().createPriceMarker("H1P", price2);
...
chart.add(Line2);
} else {
Line2.setPrice(0, price2);
}
}
}
}

Kind regards, Support Team.



Thank you!!
It was a problem related with the instrument check indeed: the code was going in a kind of loop on all instruments, causing that kind of "flashening".

I didn't think at all about moving the lines to the new price, that will surely make it even more stable.

Thank you again for yor help, appreciated!

Regards


 

Jump to:  

  © 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