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.

Lines question
 Post subject: Lines question Post rating: 0   New post Posted: Mon 09 Sep, 2013, 13:49 
User avatar

User rating: 1
Joined: Fri 08 Jun, 2012, 12:15
Posts: 14
Location: Russian FederationRussian Federation
Hi,

1 . I have plotted say 100 vertical lines on chart, they have a unique key each.

How can I replace label or remove particular vertical line knowing its key? Lines differ only by key, the name of object the same.

2. How can I make @Configurable strategy option for line style type/thickness?

3. OnBar method seems to check parameters every 10 seconds, how to make this period say 60 seconds? My Period is actually set to ONE_MINUTE, but it checks every 10 sec.


 
 Post subject: Re: Lines question Post rating: 0   New post Posted: Mon 09 Sep, 2013, 13:57 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
dns_di wrote:
1 . I have plotted say 100 vertical lines on chart, they have a unique key each.

How can I replace label or remove particular vertical line knowing its key? Lines differ only by key, the name of object the same.
See https://www.dukascopy.com/wiki/#Create_and_manage_chart_objects/Retrieve
dns_di wrote:
2. How can I make @Configurable strategy option for line style type/thickness?
DrawingStyle is an enum, so you can use it directly as a @Configurable and the thickness will simply be an int paramter. For full reference see:
https://www.dukascopy.com/wiki/#Strategy_parameters
dns_di wrote:
3. OnBar method seems to check parameters every 10 seconds, how to make this period say 60 seconds? My Period is actually set to ONE_MINUTE, but it checks every 10 sec.
See the bullet about the onBar: https://www.dukascopy.com/wiki/#Strategy_API/IStrategy_interface
See bar filtering here: https://www.dukascopy.com/wiki/#Filter_Ticks_Bars


 
 Post subject: Re: Lines question Post rating: 0   New post Posted: Mon 09 Sep, 2013, 17:13 
User avatar

User rating: 1
Joined: Fri 08 Jun, 2012, 12:15
Posts: 14
Location: Russian FederationRussian Federation
dns_di wrote:
2. How can I make @Configurable strategy option for line style type/thickness?
DrawingStyle is an enum, so you can use it directly as a @Configurable and the thickness will simply be an int paramter. For full reference see:
https://www.dukascopy.com/wiki/#Strategy_parameters

1 . I know that I can use int as parameter, but I want to be able to chose from the list the way lines look and their thinkness, like I can do in jforex platform when I click on the line's parameteres. So, is it doable?

2 . I have following code
 
private Period period; // declaration before onStart()

onStart(){
this.period = Period.ONE_MINUTE; // this one used to opend 1 min chart
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {   
period = Period.TWENTY_SECS; // this one to change back to 20 sec for onBar()
if (!instrument.equals(Instrument.EURUSD) || !period.equals(Period.TWENTY_SECS)){
return;   
}
else{
code....
}


Why strategy checks parameteres every 10 seconds , wehreas it should check every 20 sec?


 
 Post subject: Re: Lines question Post rating: 1   New post Posted: Mon 09 Sep, 2013, 21:18 
User avatar

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

1: create a custom enumeration with the same values as the ones present on the the enum you want to use, or use the enumeration directly:

@Configurable("xpto")
OutputParameterInfo.DrawingStyle mydws = OutputParameterInfo.DrawingStyle.DASHDOT_LINE;

2: Why you have this ???

period = Period.TWENTY_SECS; // this one to change back to 20 sec for onBar() ???

this way the returned period on the onStart() function will be always equal to 20 secs independently of the
value passed on the parameter everytime the function is called at any basic period because you assign it to 20 secs.

Trade well

JL


 
 Post subject: Re: Lines question Post rating: 1   New post Posted: Tue 10 Sep, 2013, 09:52 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
About the line thickness as parameter:
I don't think so it is possible, at least not with the current implementation (to add bitmaps to a dropdown list).

About onBar():
You are mixing things a bit. Let me try to clarify.
See the following strategy where I described within the code what part is executed in the onBar() function. I hope this makes it clear for you.

package jforex;

import java.util.*;
import com.dukascopy.api.*;
import com.dukascopy.api.IIndicators.AppliedPrice;

public class Strategy1 implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;

    @Configurable("Instrument")
    public Instrument selectedInstrument = Instrument.EURUSD;
    @Configurable("Period")
    public Period selectedPeriod = Period.ONE_MIN;
           
    public void onStart(IContext context) throws JFException
    {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        {
            // this part is executed for every period (1sec, 10sec, 1min, 5min, 10min, etc...) for every subscribed instrument
        }
        if ( (instrument.equals(selectedInstrument)) && (period.equals(selectedPeriod))) {
            // this part is executed only every given period (selectedPeriod) and for the given instrument (selectedInstrument)
        }
        if (instrument.equals(selectedInstrument)) {
            // this part is executed every 1sec, 10sec, 1min, 5min, 10min, etc... for EURUSD only
        }
        if (period.equals(selectedPeriod)) {
            // this part is executed every minute (as selectedPeriod is 1min) for every instrument
            // add here the code that you want to execute every minute
        }
    }
}


 
 Post subject: Re: Lines question Post rating: 0   New post Posted: Wed 11 Sep, 2013, 07:42 
User avatar

User rating: 1
Joined: Fri 08 Jun, 2012, 12:15
Posts: 14
Location: Russian FederationRussian Federation
Thanks guys for proposed solutions.

I still cannot get results from onBar method. I tried what tcsabina suggested, but it didn't work.

At the end of onStart method I set period equals to 20 seconds.

private Period period; // declaration before onStart()
 
onStart(){
this.period = Period.ONE_MINUTE; // this one used to open 1 min chart

this.period = Period.TWENTY_SECS;
}

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

if (period.equals(Period.TWENTY_SECS)){
console.getOut().println("I am inside onBar, got to repeat every 20 sec");
}


It should println in console every 20 secs, but nothing happens!


 
 Post subject: Re: Lines question Post rating: 1   New post Posted: Wed 11 Sep, 2013, 09:34 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Is 20secs a standard period? I don't think you can select 20secs for a chart on the platform for example, so I would say it is not a standard period.
However, based on Javadoc, it is defined (public static final Period TWENTY_SECS). I am not sure...

You have two variables with the same name: period.
I am not completely sure how Java handles such manners (global vs. local variable name conflict), but to be safe, just rename your private variable (the one you define before onStart()) to something else.
But I guess that in the line
if (period.equals(Period.TWENTY_SECS)){
the onBar()'s parameter is being checked instead of your local variable, and as that (the parameter of onBar()) is never 20secs, the condition is always false.

Give it a try with a period that you can select for a chart on the platform (10secs, or 1min for example), and see if that works.

Edit:
If you really need periods that are not standard, take a look here on how to define them, as that is possible.
If you need repetition execution for certain tasks (for example you want to do/check something every 20 second) you can take a look on this wiki page, which explains scheduled tasks execution within a strategy.

Good luck!


 
 Post subject: Re: Lines question Post rating: 1   New post Posted: Wed 11 Sep, 2013, 10:21 
User avatar

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

the basic bar events are:



Image

By default, the onBar() function only have those. If you need other periods, you must create the feed with the period you want if not a default one.

See https://www.dukascopy.com/wiki/#Chart_feeds

Trade well

JL


Attachments:
barevents.png [29.98 KiB]
Downloaded 258 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.
 

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