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.

Getting Custom Indicator outputs
 Post subject: Getting Custom Indicator outputs Post rating: 0   New post Posted: Mon 29 Nov, 2010, 14:57 

User rating: 0
Joined: Thu 19 Aug, 2010, 13:53
Posts: 62
Hi,

I have a custom indicator which has 4 outputs; It is working ok on chart, as expected.
I want now call it from code and get that 4 values calculated for a shift.
I need to use the calculateIndicator() variant with filters and I call it as below. Then I try printout the values but I get a class cast exception errror when it finds (Double)aArr[i] code.
Because I use filter variant with numberOfCandlesBefore/After, I would expect the return data to be in form Object[][] as the built in indicators have this method, but I dont know how to interpret the returned Object[] into my 4 output values. Can you help ?

int aShift = 1;
      IBar aBar = getIBar(aTimeFrame,aShift);
      Object[] aArr = iStrategy.iIndicators.calculateIndicator(iInstr,aTimeFrame,new  OfferSide[] {OfferSide.BID,OfferSide.BID},"MYIND",new IIndicators.AppliedPrice[] {aAppliedPrice}, new Object[]{aTimePeriod,aMaType.ordinal()},Filter.ALL_FLATS,1,aBar.getTime(),0);
      
      if(aArr == null || aArr.length <= 0)
         throw new JFException("Indicator not ready.");   
      
        for (int i=0;i<aArr.length;i++)
           printMessage("output["+i+"]: "+(Double)aArr[i]);


 
 Post subject: Re: Getting Custom Indicator outputs Post rating: 0   New post Posted: Mon 29 Nov, 2010, 16:36 

User rating: 1
Joined: Fri 26 Mar, 2010, 19:19
Posts: 116
Location: Canada
perhaps
(double[][])objs[0]
where objs is the returned value from calculateIndicator().

that's why I'm advocating for a community common library


 
 Post subject: Re: Getting Custom Indicator outputs Post rating: 0   New post Posted: Tue 30 Nov, 2010, 08:11 

User rating: 0
Joined: Thu 19 Aug, 2010, 13:53
Posts: 62
if I use this

double[][] aValues = (double[][])aArr[0];

I get:

07:07:51 java.lang.ClassCastException: [D cannot be cast to [[D
07:07:51 [D cannot be cast to [[D

In case of only one output line in indicator, I am able to get the value via
double[] aValues = (double [])aArr[0];
return aValues[0]; // my only one output

Also, if I use the indicator with 4 outputs, the above code returns the value of the first output in indicator
and the length aValues.length returned is 1.

But for multiple inicator outputs I get the above errors and unable to retrieved all 4 values. Any help ? Dukascopy ? thank you.


 
 Post subject: Re: Getting Custom Indicator outputs Post rating: 0   New post Posted: Wed 01 Dec, 2010, 16:13 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
It's difficult to give you the answer right away without seeing the actual code of your indicator,
Please have a look at the following example:
long prevBarTime = history.getBar(Instrument.EURUSD, Period.ONE_HOUR, OfferSide.ASK, 1).getTime();
Object[] universalMinMax = indicators.calculateIndicator(Instrument.EURUSD, Period.ONE_HOUR, new  OfferSide[] {OfferSide.ASK}, "MINMAX", 
             new AppliedPrice[] {IIndicators.AppliedPrice.CLOSE}, new Object[]{5}, Filter.ALL_FLATS,
             1, prevBarTime, 0);   
       
console.getOut().println("universalMinMax values: " + ((double[])universalMinMax[0])[0] + ", " + ((double[])universalMinMax[1])[0]);


 
 Post subject: Re: Getting Custom Indicator outputs Post rating: 0   New post Posted: Thu 02 Dec, 2010, 08:20 

User rating: 0
Joined: Thu 19 Aug, 2010, 13:53
Posts: 62
I used this and I get correct values from indicator:

double aRsi = ((double[])aArr[0])[0];
double aMfi = ((double[])aArr[1])[0];
double aStoch = ((double[])aArr[2])[0];
double aAvg = ((double[])aArr[3])[0];

Output is correct like on the indicator's chart:
07:15:15 13 Sep 2010 09:00:00 GMT Rsi/Mfi/Stoch/Avg: 0.8527738654072327/0.25278088988213376/-0.3264397962811042/0.25970498633608735

Thank you for your help.


 

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