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.

usage of multiinstrumnet indicator in backtest
 Post subject: usage of multiinstrumnet indicator in backtest Post rating: 0   New post Posted: Wed 06 Oct, 2010, 14:29 

User rating: 0
Joined: Tue 28 Sep, 2010, 09:41
Posts: 18
Hello,

I finally wrote the multiinstrument indicator (correlation between two instruments) as I was asking you here
viewtopic.php?f=6&t=23861
without any response from your side...

So the indicator is done, I created my own algorithm how to synchronize data of two instrument for the calculation.
The indicator is working fine, you can try it (code is in attachment LS_I_DirectionalCorrelation_vs_GBPUSD.java)
indicator is calculating correlation index between GBPUSD instrument and instrument of chart where the indicator is added.
I just dont know how to correctly use the indicator in code of strategy for live trading or backtesting to access the values of indicator. How to calculate values of this my indicator inside of some strategy...?

In attachment is code of test stretegy what I tried "LS_S_UsingIndicatorInStrategy.java" the strategy is just trying to calculate values of the indicator.
But when I am trying to do backtest there is still exception:¨

13:21:24 Strategy tester: java.lang.ArrayIndexOutOfBoundsException: 1 @ jforex.LS_S_UsingIndicatorInStrategy.onBar(LS_S_UsingIndicatorInStrategy.java:20)

Can you please advice me how to create strategy code to access values from this my indicator??
Thank you


 
 Post subject: Re: usage of multiinstrumnet indicator in backtest Post rating: 0   New post Posted: Fri 08 Oct, 2010, 12:19 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
You need to specify the OfferSide for the second input:
indicators.calculateIndicator(
                    instrument,
                    period,
                    new OfferSide[] {OfferSide.BID, OfferSide.BID},
                    "LS_I_DirectionalCorrelation_vs_GBPUSD",
                    new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE},
                    new Object[] {14},
                    1);

Then use the result to access the indicator output as follows:
Object[] val = indicators.calculateIndicator(
                    instrument,
                    period,
                    new OfferSide[] {OfferSide.BID, OfferSide.BID},
                    "LS_I_DirectionalCorrelation_vs_GBPUSD",
                    new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE},
                    new Object[] {14},
                    1);
console.getOut().println('indicator value: ' + val[0]);


 
 Post subject: Re: usage of multiinstrumnet indicator in backtest Post rating: 0   New post Posted: Fri 08 Oct, 2010, 14:06 

User rating: 0
Joined: Tue 28 Sep, 2010, 09:41
Posts: 18
Great! Its working :) thank you very much, I didnt realize that I have to set OfferSide for all used inputs.
Could you please remove the source code of the indicator from this thread? Thanks


 
 Post subject: Re: usage of multiinstrumnet indicator in backtest Post rating: 0   New post Posted: Wed 13 Oct, 2010, 15:42 

User rating: 0
Joined: Tue 28 Sep, 2010, 09:41
Posts: 18
Is it OK that there is only one AppliedPrice in the array?
Because when the indicator use two instruments for calculation and there has to be two OfferSide defined I was wondering if there also has to be two AppliedPrice defined.. ?

Thank you for your response


 
 Post subject: Re: usage of multiinstrumnet indicator in backtest Post rating: 0   New post Posted: Fri 15 Oct, 2010, 09:27 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
Since you use the InputParameterInfo.Type.BAR in your indicator and explicitly specify the type of price you use, you don't need to specify the AppliedPrice at all.


 

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