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.

Cant use custom indicator calculation in custom strategy
 Post subject: Cant use custom indicator calculation in custom strategy Post rating: 0   New post Posted: Thu 21 Oct, 2010, 17:19 

User rating: 0
Joined: Tue 28 Sep, 2010, 09:41
Posts: 18
Hello I have problem with using my custom indicator "LS_I_DirectionalCorrelation_vs_GBPUSD" in my strategy.
Let me explain more details..

I have my custom indicator with name "LS_I_DirectionalCorrelation_vs_GBPUSD".
This indicator is calculating correlation index between by-user-chosen instrument and GBPUSD instrument.
Here is source code of the indicator if you are interested: https://files.lorencsoftware.cz/20000007 ... BPUSD.java

The indicator is working fine, I have no problems with the indicator.
I tried to calculete the indicator values from strategy code.
Like this:
            Object[] vals = context.getIndicators().calculateIndicator(
                    Instrument.EURUSD,
                    Period.createCustomPeriod(Unit.Minute, 60),
                    new OfferSide[] {OfferSide.BID, OfferSide.BID},
                    "LS_I_DirectionalCorrelation_vs_GBPUSD",
                    new AppliedPrice[] {AppliedPrice.CLOSE, AppliedPrice.CLOSE},
                    new Object[] {14},
                    1);
            context.getConsole().getOut().println(vals[0].toString());

This works fine, there is no problem.
Result looks like for example this: 0.706331927573264 ..is instance of Double
everythink is ok.


But after that I realized the code is taking data from weekend also.
And I want to exclude the weekend bars from calculation.
I want the correlation index is calculated from bars of week, and weekends have to be skiped.

So I have decided to use this implementation of calculateIndicator method...
Object[] calculateIndicator(Instrument instrument,
                            Period period,
                            OfferSide[] side,
                            String functionName,
                            IIndicators.AppliedPrice[] inputTypes,
                            Object[] optParams,
                            long from,
                            long to)
                            throws JFException



So in my case it looks like this:
            Object[] values = context.getIndicators().calculateIndicator(
                    Instrument.EURUSD,
                    Period.createCustomPeriod(Unit.Minute, 60),
                    new OfferSide[] {OfferSide.BID, OfferSide.BID},
                    "LS_I_DirectionalCorrelation_vs_GBPUSD",
                    new AppliedPrice[] {AppliedPrice.CLOSE, AppliedPrice.CLOSE},
                    new Object[] {14},
                    Filter.WEEKENDS,
                    1,
                    askBar.getTime(),
                    0);
            context.getConsole().getOut().println(values[0].toString());



The compilation of this code is OK, and it runs without exceptions.
But here is finally my problem: :)
I dont know what is the type of the Object instances inside Object[] result of the calculation... ?
Is array of objects? Or is array of arrays of objects? Or what??

when you will try to invoke .toString() method on the instance of Object from Object[] array - result of the calculation
You will see somthing like this: [D@db6096

As you know, in Java the toString() (if its not overwritten) method is defined like getClass().getName() + '@' + Integer.toHexString(hashCode())
see https://www.ifs.tuwien.ac.at/ifs/lehre/e ... #toString()

So what is the class type of the result ???
I can not work with the result because I can not recognize the class.

I am waiting for your response,
thak you for assistance.
Best regards
Marek Lorenc


 
 Post subject: Re: Cant use custom indicator calculation in custom strategy Post rating: 0   New post Posted: Mon 01 Nov, 2010, 09:29 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Returned array is Object[numberOfOutputs][elements of output type]
For example this code should work:
for (int i = 0; i < numberOfOutputs; i++) {
double[] output = (double[]) indicatorResult[i];
}

You have only one outputs, so this code can be simplified
double[] output = (double[]) indicatorResult[0];


 
 Post subject: Re: Cant use custom indicator calculation in custom strategy Post rating: 0   New post Posted: Tue 02 Nov, 2010, 19:23 

User rating: 0
Joined: Tue 28 Sep, 2010, 09:41
Posts: 18
Hello
unfortunately your sugestion is not working..

I tried following:

    public double correlate2(long bidTime) throws JFException {
        Double[] values = (Double[]) context.getIndicators().calculateIndicator(
                Instrument.EURUSD,
                Period.createCustomPeriod(Unit.Minute, 60),
                new OfferSide[] {OfferSide.BID, OfferSide.BID},
                "LS_I_DirectionalCorrelation_vs_GBPUSD",
                new AppliedPrice[] {AppliedPrice.CLOSE, AppliedPrice.CLOSE},
                new Object[] {14},
                Filter.WEEKENDS,
                1,
                bidTime,
                0)[0];

        Double d = values[0];

        return d;
    }


And the result is this exception:
18:20:01 Strategy tester: java.lang.ClassCastException: [D cannot be cast to [Ljava.lang.Double; @ jforex.LS_S_Test.correlate2(LS_S_Test.java:75)


 
 Post subject: Re: Cant use custom indicator calculation in custom strategy Post rating: 0   New post Posted: Tue 02 Nov, 2010, 19:28 

User rating: 1
Joined: Fri 26 Mar, 2010, 19:19
Posts: 116
Location: Canada
You can't cast double[] to Double[] like that. Try using double and double[], all lower case, instead.


 

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