I am new to JForex.
This is my attempt to try and get last 10 RSI(7, Close) values.
Problem is i get different results for both methods.
Also in Method 1 using calculateIndicator in indicators values of 10 and 9 are always same and I loose 1 reading
Can someone please help.
Here is a code
package Strategies;
import java.util.*;
import com.dukascopy.api.*;
import com.dukascopy.api.IIndicators.AppliedPrice;
public class ConfusingRSI implements IStrategy {
private IContext context = null;
private int tagCounter = 0;
private IConsole console;
private IHistory history;
private IEngine engine;
private IIndicators indicators;
public void onStart(IContext context) throws JFException {
this.context = context;
this.console = context.getConsole();
this.history = context.getHistory();
this.engine = context.getEngine();
this.indicators = context.getIndicators();
console.getOut().println("Started");
}
public void onStop() throws JFException {
console.getOut().println("Stopped");
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
if (!period.equals(Period.ONE_MIN) || !instrument.equals(Instrument.AUDCAD))
return;
IBar myBar = history.getBar(instrument,period,OfferSide.ASK, 1);
long myBartime = myBar.getTime();
double rsi_7 = context.getIndicators().rsi(instrument, period, OfferSide.BID, IIndicators.AppliedPrice.CLOSE, 7, 1);
double rsi_7_1 = context.getIndicators().rsi(instrument, period, OfferSide.BID, IIndicators.AppliedPrice.CLOSE, 7, 2);
int numBars = 10;
console.getOut().println("Instrument = " + instrument);
console.getOut().println("Method 1: Calculate Indicator Method");
Object[] results = indicators.calculateIndicator(instrument,
period,
new OfferSide[] {OfferSide.BID},
"RSI",
new AppliedPrice[]{AppliedPrice.CLOSE},
new Object[]{7},
Filter.WEEKENDS, 1, myBartime, numBars);
double[] RSIs = (double[])results[0];
int count = 0;
for (Object o : RSIs) {
console.getOut().println(count++ + "> " + o + ", rsi7 " + rsi_7 + ", rsi7-1 " + rsi_7_1);
}
console.getOut().println("Method 2: Calling RSI on indicators");
double[] indRSI = indicators.rsi(instrument, period, OfferSide.BID , IIndicators.AppliedPrice.CLOSE, 7, Filter.WEEKENDS, numBars + 1, myBartime, 0);
count = 0;
for (double rsiVal : indRSI) {
console.getOut().println(count++ + "> " + rsiVal + ", rsi7 " + rsi_7 + ", rsi7-1 " + rsi_7_1);
}
}
public void onMessage(IMessage message) throws JFException {
}
public void onAccount(IAccount account) throws JFException {
}
}