Hello,
I am quite a beginner to Java. Please help me!
I tried to write a strategy by using fibPivot. I want to buy or sell if the price pierces fibPivots. However, it does not work as I imagine. It's not sensitive. The piercing triggers were so few, actually there should be much more as I saw in the OHLC index. Therefore I write the following codes to check what's wrong, but it does not work neither. It didnot print. Could you please help me on this issue? Do we already have such a existing strategy like this? Or may I have one from you?
Thank you very much! Have a nice weekend!
package jforex;
import com.dukascopy.api.*;
public class Test implements IStrategy {
private IConsole console;
private IHistory history;
private IIndicators indicators;
public Instrument instrument = Instrument.EURUSD;
public Period period = Period.FIFTEEN_MINS;
public void onStart(IContext context) throws JFException {
this.console = context.getConsole();
this.history = context.getHistory();
this.indicators = context.getIndicators();
if (!instrument.equals(this.instrument) || !period.equals(this.period))
return;
IBar prevBar1 = history.getBar(instrument, period, OfferSide.BID, 1);
IBar prevBar2 = history.getBar(instrument, period, OfferSide.BID, 2);
double [] FP = indicators.fibPivot(instrument, Period.DAILY, OfferSide.BID, 7, 0);
for (int r=0; r<FP.length; r++) {
if (((prevBar2.getClose()>=FP[r] && prevBar1.getClose()<FP[r]) || (prevBar2.getClose()<=FP[r] && prevBar1.getClose()>FP[r]))){
print ("piercing");
}
}
}
private void print(Object message) {
console.getOut().println(message);
}
public void onAccount(IAccount account) throws JFException { }
public void onMessage(IMessage message) throws JFException { }
public void onStop() throws JFException { }
public void onTick(Instrument instrument, ITick tick) throws JFException { }
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { }
}