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.

SMA over RSI custom indicator
 Post subject: SMA over RSI custom indicator Post rating: 0   New post Posted: Tue 06 Apr, 2010, 13:09 

User rating: 0
Joined: Tue 18 Aug, 2009, 15:09
Posts: 10
Hi,

I'm trying to use the custom indicator from this topic :
viewtopic.php?f=6&t=191&p=641&hilit=calculateIndicator#p641

first I call calculateindicator :
Object[] smarsi = indicators.calculateIndicator(instrument, Period.DAILY, new OfferSide[] {OfferSide.BID}, "SMA_RSI", new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE}, new Object[] {rsi, ema}, Filter.WEEKENDS, 1, tick.getTime(), 0);

When I try to read values :
//getting output on console
for (int i=0;i< smarsi.length;i++){
this.console.getOut().print("smarsi["+i+"]: "+(Double) smarsi[i]);
}
this is what I get :
12:08:20 Strategy tester: java.lang.ClassCastException: [D cannot be cast to java.lang.Double @ Litz.Litz.onTick(Litz.java:172)
Without th cast into Double (this.console.getOut().print(" smarsi["+i+"]: "+smarsi[i]);) I get :
12:10:54 smarsi[0]: [D@276eb37b smarsi[1]: [D@54c96476

How do I get the rsi and sma values from indicator ?


 
 Post subject: Re: SMA over RSI custom indicator Post rating: 0   New post Posted: Wed 07 Apr, 2010, 16:36 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
please consider this sample code
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
          if (instrument.equals(Instrument.EURUSD) && period.equals(Period.TEN_SECS)){
            Object[] smarsi = context.getIndicators().calculateIndicator(instrument, period,
                    new OfferSide[] {OfferSide.BID}, "SMA_RSI",
                    new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE},
                    new Object[] {14,14},
                    Filter.WEEKENDS, 1, context.getHistory().getLastTick(instrument).getTime(), 0);
           
            for (Object o : smarsi){
                for (double d : (double[])o){
                    context.getConsole().getOut().print(d);               
                }                   
            }
            context.getConsole().getOut().println();
        }


 
 Post subject: Re: SMA over RSI custom indicator Post rating: 0   New post Posted: Thu 08 Apr, 2010, 15:05 

User rating: 0
Joined: Tue 18 Aug, 2009, 15:09
Posts: 10
Hello,

Thank you for your answer, however, when I run your sample code, I don't get the same values as the ones shown by the sam over rsi indicator on the chart.
Any ideas ?
thanks


 
 Post subject: Re: SMA over RSI custom indicator Post rating: 0   New post Posted: Tue 13 Apr, 2010, 15:11 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
For this particular case, the indicator need to be added for an EURUSD instrument. The period need to be set to 10 seconds and offerSide is BID. When you adding indicator, check if both RSI and SMA time periods are 14. Please check, if all these is set correctly.


 

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