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 set instrument - period - chart according to current chart?
 Post subject: how to set instrument - period - chart according to current chart? Post rating: 0   New post Posted: Tue 18 Jun, 2013, 09:18 

User rating: 1
Joined: Tue 18 Jun, 2013, 09:03
Posts: 14
Location: GermanyGermany
Hi community,

currently i am working on my first strategy and i am stuck with the following:

When backtesting my strategy i can choose the instrument to be traded and (if visual enabled) i see the according chart.

onBar ontick etc. provide me with the correct instrument and period i selected in the historical tester.

However when running the strategy on my live local demo account the instrument is set randomly and the period is 10s.. whatever i draw on the chart of that selected instrument is not visible on the chart i open manually according to the selected instrument..

How do i control what is handed to onBar, onTick etc.?

Greetings,

Fabs


 
 Post subject: Re: how to set instrument - period - chart according to current chart? Post rating: 0   New post Posted: Tue 18 Jun, 2013, 11:29 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Use IChart.getFeedDescriptor().
See example here:
https://www.dukascopy.com/wiki/#Chart_Operations/Retrieve_feed_properties
You can also use the feed descriptor rightaway to work with indicators and history, see:
https://www.dukascopy.com/wiki/#Chart_feeds/Feed_history,_indicator_calculation_and_chart_opening


 
 Post subject: Re: how to set instrument - period - chart according to current chart? Post rating: 0   New post Posted: Tue 18 Jun, 2013, 14:54 
User avatar

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

I am not sure if I understand your problem properly (maybe Support does, and support`s reply is the relevant help for you...), but you asked how to control what is handed to onBar() and onTick().

For every instrument and for every time period these functions are called. You have to filter those that you don`t want.

For your strategy, you have to add 2 parameters:
@Configurable("Instrument")
public Instrument selectedInstrument = Instrument.EURUSD;
@Configurable("Period")
public Period selectedPeriod = Period.ONE_MIN;

and in onBar() and in onTick() you have to filter:
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    if ( (instrument.equals(selectedInstrument)) && (period.equals(selectedPeriod)))
    {
     // here comes your onBar execution method
    }
}


With this you can ignore those instruments and time periods that you don`t want.


About your drawing issue:
I don`t understand at all what are you trying to say.


Again saying, if I misunderstood your problem, then sorry for the post.


 
 Post subject: Re: how to set instrument - period - chart according to current chart? Post rating: 0   New post Posted: Wed 19 Jun, 2013, 14:07 

User rating: 1
Joined: Tue 18 Jun, 2013, 09:03
Posts: 14
Location: GermanyGermany
Thank you very much for your answers, both are relevant i figured out.

One question is left though:

If i add configurable period and instrument, how can i still enable multiple instruments being considered when doing backtesting.

I do i could do something like:

if (!period.equals(myPeriod) || !instruments.contains(instrument)) {
return;
}

However, all the valid pairs will be send down to my strategy code one after another accessing the same resources (lists, objects etc.). Is there anyway that i tell the backtester to just use one instance of my code per instrument instead of considering multiple instruments entering the same code?

Does this make sense?

Thanks in advance


 
 Post subject: Re: how to set instrument - period - chart according to current chart? Post rating: 0   New post Posted: Wed 19 Jun, 2013, 14:21 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
fabwa wrote:
However, all the valid pairs will be send down to my strategy code one after another accessing the same resources (lists, objects etc.). Is there anyway that i tell the backtester to just use one instance of my code per instrument instead of considering multiple instruments entering the same code?
Could you please elaborate on this?


 
 Post subject: Re: how to set instrument - period - chart according to current chart? Post rating: 0   New post Posted: Wed 19 Jun, 2013, 14:29 

User rating: 1
Joined: Tue 18 Jun, 2013, 09:03
Posts: 14
Location: GermanyGermany
In my strategy e.g. i have an arraylist holding price retracements. If i accept more than one instrument to "use" my strategy, this arraylist gets messed up as it now used by two independent instruments.

Instead of changing my structure i was wondering whether it is possible to restrict one instance of code to one instrument. I.e. running a backtest with multiple instruments without making my code robust to multiple use.

Is that more clear?

Basically i wonder, what actually is different when i enable just certain instruments in the backtester if anyways all instruments are passed to onBar etc.?


 
The Best Answer  Post subject: Re: how to set instrument - period - chart according to current chart? Post rating: 0   New post Posted: Wed 19 Jun, 2013, 14:48 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
fabwa wrote:
In my strategy e.g. i have an arraylist holding price retracements. If i accept more than one instrument to "use" my strategy, this arraylist gets messed up as it now used by two independent instruments.

Instead of changing my structure i was wondering whether it is possible to restrict one instance of code to one instrument. I.e. running a backtest with multiple instruments without making my code robust to multiple use.

Is that more clear?
Then the easiest option would be filtering the bars/ticks by the particular instrument by using the snippet that you mentioned in your previous post. However, if you wish to work with multiple instruments, consider mapping the retracement list to the corresponding instrument by using the java.util.Map, for instance:

    Map<Instrument, List<Object>> retracementMap = new HashMap<Instrument, List<Object>>();

    @Override
    public void onStart(IContext context) throws JFException {
        retracementMap.put(Instrument.EURUSD, new ArrayList<Object>(Arrays.asList( "R1_EURUSD", "R2_EURUSD" )));
        retracementMap.put(Instrument.AUDCAD, new ArrayList<Object>(Arrays.asList( "R1_AUDCAD", "R2_AUDCAD", "R3_AUDCAD" )));
        //this overwrites the last EURUSD value
        retracementMap.put(Instrument.EURUSD, new ArrayList<Object>(Arrays.asList( "RRRR1_EURUSD" )));
        if(retracementMap.containsKey(Instrument.EURUSD)){
            retracementMap.get(Instrument.EURUSD).add("RRRR_ADDED_EURUSD");
            retracementMap.get(Instrument.EURUSD).add("RRRR_ADDED_SECOND_EURUSD");
        }
        context.getConsole().getOut().println("simple print: " + retracementMap);
        for(Map.Entry<Instrument, List<Object>> entry : retracementMap.entrySet()){
            context.getConsole().getOut().format("%s has %s retracements: %s", entry.getKey(), entry.getValue().size(), entry.getValue()).println();
        }
    }

fabwa wrote:
if anyways all instruments are passed to onBar
It is not the case.


Attachments:
MultiInstrumentRetracaments.java [1.77 KiB]
Downloaded 353 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:  

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