Hello
Is there a way to automatically execute orders once a fractal appears.
I have reviewd the below code for printing the figures but is there a way to adapt this to execute trades based on when the fractal appears?
package jforex;
import com.dukascopy.api.*;
public class FractalTest implements IStrategy {
private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IUserInterface userInterface;
@Configurable("Number of Fractal values back")
public int valuesBack = 3;
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
this.history = context.getHistory();
this.context = context;
this.indicators = context.getIndicators();
this.userInterface = context.getUserInterface();
}
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 {
if (instrument.equals(Instrument.EURUSD) && (period.equals(Period.TEN_SECS))) {
double[] macd0 = indicators.macd(instrument, period, OfferSide.BID, IIndicators.AppliedPrice.MEDIAN_PRICE, 12, 26, 9, 0);
double macd = macd0[0];
Double fractalMax = Double.NaN;
Double fractalMin = Double.NaN;
int maxCount = 0;
int minCount = 0;
int shift = 0;
while (maxCount < valuesBack || minCount < valuesBack) {
double[] fractal = indicators.fractal(instrument, period, OfferSide.BID, 5, shift);
if (!Double.isNaN(fractal[0]) && maxCount < valuesBack) {
fractalMax = fractal[0];
maxCount++;
}
if (!Double.isNaN(fractal[1]) && minCount < valuesBack) {
fractalMin = fractal[1];
minCount++;
}
shift++;
}
console.getOut().println("MACD=" + macd);
console.getOut().println("Fractal maximum: " + fractalMax + "; Fractal minimum: " + fractalMin);
}
}
}