Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

Could you tell me how to use the return value of indicators.rsi method
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=52174
Page 1 of 1

Author:  leevo [ Mon 26 Jan, 2015, 20:02 ]
Post subject:  Could you tell me how to use the return value of indicators.rsi method

double[] rsi14askResults = indicators.rsi(Instrument.EURUSD, Period.ONE_HOUR, OfferSide.ASK, AppliedPrice.CLOSE, 14, Filter.NO_FILTER, 30, time, 0);

the return values are not closed to right rsi values, which I can find in jforex platform.

another important question is I see the rsi values in jforex platform maybe a half of the ask price add bid price, but in the indicators.rsi method, I must give one offerside, can I set the offerside in jforex platform? or get the same a half of the ask price add bid price from the strategy.

Author:  API Support [ Wed 28 Jan, 2015, 09:37 ]
Post subject:  Re: Could you tell me how to use the return value of indicators.rsi method

RSI indicator is recursive and requires more values to be calculated. Only then will the outputs exactly match chart values.


public void onStart(IContext context) throws JFException {
   this.console = context.getConsole();
   this.history = context.getHistory();
   this.indicators = context.getIndicators();

   Instrument instrument = Instrument.EURUSD;
   Period period = Period.ONE_HOUR;
   long time = history.getLastTick(instrument).getTime();
   time = history.getBarStart(period, time);
   int len = 4000;
   double[] rsiOut = indicators.rsi(instrument, Period.ONE_HOUR, OfferSide.ASK, AppliedPrice.CLOSE, 14, Filter.NO_FILTER, len, time, 0);
   
   console.getOut().println(arrToString(rsiOut, len - 3, instrument));
}

private String arrToString(double[] arr, int from, Instrument instrument) {
   StringBuffer sb = new StringBuffer();
   for (int r = from; r < arr.length; r++) {
      sb.append(String.format("[%s] %." + (instrument.getPipScale() + 1) + "f; ", r, arr[r]));
   }
   return sb.toString();
}

Author:  leevo [ Wed 28 Jan, 2015, 14:23 ]
Post subject:  Re: Could you tell me how to use the return value of indicators.rsi method

Oh. it's too bad, so you should rewrite the method for rsi with using parameter 'shift', it can not get right so far.

API Support wrote:
RSI indicator is recursive and requires more values to be calculated. Only then will the outputs exactly match chart values.


public void onStart(IContext context) throws JFException {
   this.console = context.getConsole();
   this.history = context.getHistory();
   this.indicators = context.getIndicators();

   Instrument instrument = Instrument.EURUSD;
   Period period = Period.ONE_HOUR;
   long time = history.getLastTick(instrument).getTime();
   time = history.getBarStart(period, time);
   int len = 4000;
   double[] rsiOut = indicators.rsi(instrument, Period.ONE_HOUR, OfferSide.ASK, AppliedPrice.CLOSE, 14, Filter.NO_FILTER, len, time, 0);
   
   console.getOut().println(arrToString(rsiOut, len - 3, instrument));
}

private String arrToString(double[] arr, int from, Instrument instrument) {
   StringBuffer sb = new StringBuffer();
   for (int r = from; r < arr.length; r++) {
      sb.append(String.format("[%s] %." + (instrument.getPipScale() + 1) + "f; ", r, arr[r]));
   }
   return sb.toString();
}

  Page 1 of 1