public class ForexStrategies implements IStrategy { private InnerStrategy AUDUSD_H1; private InnerStrategy EURJPY_H1; private InnerStrategy EURUSD_H1; private InnerStrategy GBPUSD_H1; private InnerStrategy USDCAD_H1; private InnerStrategy USDJPY_H1;
public void onStart(IContext context) throws JFException { AUDUSD_H1 = new InnerStrategy(); AUDUSD_H1.myInstrument = Instrument.AUDUSD; AUDUSD_H1.myLabel = "AUDUSD";
EURJPY_H1 = new InnerStrategy(); EURJPY_H1.myInstrument = Instrument.EURJPY; EURJPY_H1.myLabel = "EURJPY";
EURUSD_H1 = new InnerStrategy(); EURUSD_H1.myInstrument = Instrument.EURUSD; EURUSD_H1.myLabel = "EURUSD";
GBPUSD_H1 = new InnerStrategy(); GBPUSD_H1.myInstrument = Instrument.GBPUSD; GBPUSD_H1.myLabel = "GBPUSD";
USDCAD_H1 = new InnerStrategy(); USDCAD_H1.myInstrument = Instrument.USDCAD; USDCAD_H1.myLabel = "USDCAD";
USDJPY_H1 = new InnerStrategy(); USDJPY_H1.myInstrument = Instrument.USDJPY; USDJPY_H1.myLabel = "USDJPY";
AUDUSD_H1.onStart(context); EURJPY_H1.onStart(context); EURUSD_H1.onStart(context); GBPUSD_H1.onStart(context); USDCAD_H1.onStart(context); USDJPY_H1.onStart(context); }
public void onTick(Instrument instrument, ITick tick) throws JFException { AUDUSD_H1.onTick(instrument, tick); EURJPY_H1.onTick(instrument, tick); EURUSD_H1.onTick(instrument, tick); GBPUSD_H1.onTick(instrument, tick); USDCAD_H1.onTick(instrument, tick); USDJPY_H1.onTick(instrument, tick); }
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { AUDUSD_H1.onBar(instrument, period, askBar, bidBar); EURJPY_H1.onBar(instrument, period, askBar, bidBar); EURUSD_H1.onBar(instrument, period, askBar, bidBar); GBPUSD_H1.onBar(instrument, period, askBar, bidBar); USDCAD_H1.onBar(instrument, period, askBar, bidBar); USDJPY_H1.onBar(instrument, period, askBar, bidBar); }
public void onMessage(IMessage message) throws JFException { AUDUSD_H1.onMessage(message); EURJPY_H1.onMessage(message); EURUSD_H1.onMessage(message); GBPUSD_H1.onMessage(message); USDCAD_H1.onMessage(message); USDJPY_H1.onMessage(message); }
public void onAccount(IAccount account) throws JFException { AUDUSD_H1.onAccount(account); EURJPY_H1.onAccount(account); EURUSD_H1.onAccount(account); GBPUSD_H1.onAccount(account); USDCAD_H1.onAccount(account); USDJPY_H1.onAccount(account); }
public void onStop() throws JFException { AUDUSD_H1.onStop(); EURJPY_H1.onStop(); EURUSD_H1.onStop(); GBPUSD_H1.onStop(); USDCAD_H1.onStop(); USDJPY_H1.onStop(); } }
class InnerStrategy implements IStrategy { private IAccount account; private IBar bar; private IChart chart; private IConsole console; private IContext context; private IEngine engine; private IHistory history; private IHorizontalLineChartObject hline; private IIndicators indicators; private IUserInterface userInterface; private Calendar calendar;
@Configurable("myInstrument") public Instrument myInstrument = Instrument.AUDUSD; @Configurable("myLabel") public String myLabel = "AUDUSD";
public final Period myPeriod = Period.ONE_HOUR; public final double myAmount = 0.1;
//---Indicatiors public final OfferSide mySide = OfferSide.BID; public final MaType myMaType = MaType.EMA; public final AppliedPrice myPrice = AppliedPrice.CLOSE; public final int bbandPeriod = 20; public final double nbDevUp = 2.0; public final double nbDevDn = 2.0; public final int fastPeriod = 12; public final int slowPeriod = 26; public final int signalPeriod = 2; public final double fastpr = 2.0 / (1 + fastPeriod); public final double slowpr = 2.0 / (1 + slowPeriod);
//---Constants public final int sleepTime = 2000;
//---Viarables public long lastBarTime; public long lastTickTime;
//---Statics public static long frTime1; public static long toTime1; public static long frTime2; public static long toTime2; public static long frTime3; public static long toTime3; public static long filledBarTime; public static boolean isCloseOutFlag;
public void onTick(Instrument instrument, ITick tick) throws JFException { account = context.getAccount(); history = context.getHistory();
double pip = myInstrument.getPipValue(); double mypip = 0.1 * pip; double commission = 1.0 * pip; double myStopLoss = 50.0 * pip; double myTakeProfit = 50.0 * pip; double slippage = 0.3;
double bid = history.getLastTick(myInstrument).getBid(); double ask = history.getLastTick(myInstrument).getAsk(); double size = engine.getOrders(myInstrument).size(); double close0 = history.getBar(myInstrument,myPeriod,mySide,0).getClose();
lastBarTime = history.getBar(myInstrument,myPeriod,mySide,0).getTime(); lastTickTime = history.getTimeOfLastTick(myInstrument); ...... ...... ...... ...... ...... ......
Above is about onTick getting historial data. Is it enough? THX!
|