package com.dukascopy.visualforex.spaima1976; import java.util.*; import com.dukascopy.api.*; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.concurrent.CopyOnWriteArrayList; import java.lang.reflect.*; import java.math.BigDecimal; /* * Created by VisualJForex Generator, version 2.35 * Date: 11.10.2016 18:49 */ public class a2002 implements IStrategy { private CopyOnWriteArrayList tradeEventActions = new CopyOnWriteArrayList(); private static final String DATE_FORMAT_NOW = "yyyyMMdd_HHmmss"; private IEngine engine; private IConsole console; private IHistory history; private IContext context; private IIndicators indicators; private IUserInterface userInterface; @Configurable("defaultSlippage:") public int defaultSlippage = 2; @Configurable("defaultTradeAmount:") public double defaultTradeAmount = 5.0; @Configurable("defaultPeriod:") public Period defaultPeriod = Period.TEN_MINS; @Configurable("defaultInstrument:") public Instrument defaultInstrument = Instrument.AUDJPY; @Configurable("defaultTakeProfit:") public int defaultTakeProfit = 95; @Configurable("defaultStopLoss:") public int defaultStopLoss = 35; private String AccountCurrency = ""; private int _tempVar92 = 200; private Period _tempVar94 = Period.ONE_HOUR; private double _tempVar120 = 55.0; private Period _tempVar90 = Period.ONE_HOUR; private double _out19Current; private double _out19Prev; private int _tempVar96 = 100; private Tick LastTick = null ; private Period _tempVar98 = Period.ONE_HOUR; private double _Percent; private double Equity; private double _line33; private double _Dif1; private int _TakeProfit1 = 95; private int _tempVar100 = 50; private double _tempVar110 = 75.0; private List AllPositions = null ; private double _ema13; private Period _tempVar102 = Period.ONE_HOUR; private double _ema12; private int _TakeProfit2 = 35; private double _ema11; private int _TakeProfit3 = 55; private double _ema10; private int _tempVar108 = 10; private double _tempVar109 = 25.0; private int _tempVar104 = 21; private Period _tempVar106 = Period.ONE_HOUR; private double _Dif4; private double _Dif3; private Candle LastBidCandle = null ; private double _Dif2; private IOrder _Position_3 = null ; private IOrder _Position_4 = null ; private double Leverage; private IOrder _Position_1 = null ; private IOrder _Position_2 = null ; private Period _tempVar208 = Period.ONE_HOUR; private int _tempVar140 = 7; private double _tempVar146 = 55.0; private int _tempVar180 = 2; private Period _tempVar138 = Period.FIFTEEN_MINS; private double _TakeProfit; private String AccountId = ""; private Period _tempVar172 = Period.ONE_HOUR; private double UseofLeverage; private List PendingPositions = null ; private Period _tempVar178 = Period.ONE_HOUR; private double _tempVar130 = 65.0; private double _tempVar133 = 25.0; private double _Percent6; private double _out19; private double _Percent4; private int _tempVar125 = 35; private double _Percent5; private double _tempVar126 = 50.0; private Candle LastAskCandle = null ; private int MarginCutLevel; private int OverWeekendEndLeverage; private double _Percent3; private double _Percent1; private boolean GlobalAccount; private List OpenPositions = null ; private IMessage LastTradeEvent = null ; 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(); subscriptionInstrumentCheck(defaultInstrument); ITick lastITick = context.getHistory().getLastTick(defaultInstrument); LastTick = new Tick(lastITick, defaultInstrument); IBar bidBar = context.getHistory().getBar(defaultInstrument, defaultPeriod, OfferSide.BID, 1); IBar askBar = context.getHistory().getBar(defaultInstrument, defaultPeriod, OfferSide.ASK, 1); LastAskCandle = new Candle(askBar, defaultPeriod, defaultInstrument, OfferSide.ASK); LastBidCandle = new Candle(bidBar, defaultPeriod, defaultInstrument, OfferSide.BID); if (indicators.getIndicator("EMA") == null) { indicators.registerDownloadableIndicator("11554","EMA"); } if (indicators.getIndicator("EMA") == null) { indicators.registerDownloadableIndicator("11554","EMA"); } if (indicators.getIndicator("EMA") == null) { indicators.registerDownloadableIndicator("11554","EMA"); } if (indicators.getIndicator("EMA") == null) { indicators.registerDownloadableIndicator("11554","EMA"); } if (indicators.getIndicator("RSI") == null) { indicators.registerDownloadableIndicator("1286","RSI"); } if (indicators.getIndicator("SMA") == null) { indicators.registerDownloadableIndicator("1314","SMA"); } subscriptionInstrumentCheck(Instrument.fromString("AUD/JPY")); } public void onAccount(IAccount account) throws JFException { AccountCurrency = account.getCurrency().toString(); Leverage = account.getLeverage(); AccountId= account.getAccountId(); Equity = account.getEquity(); UseofLeverage = account.getUseOfLeverage(); OverWeekendEndLeverage = account.getOverWeekEndLeverage(); MarginCutLevel = account.getMarginCutLevel(); GlobalAccount = account.isGlobal(); } private void updateVariables(Instrument instrument) { try { AllPositions = engine.getOrders(); List listMarket = new ArrayList(); for (IOrder order: AllPositions) { if (order.getState().equals(IOrder.State.FILLED)){ listMarket.add(order); } } List listPending = new ArrayList(); for (IOrder order: AllPositions) { if (order.getState().equals(IOrder.State.OPENED)){ listPending.add(order); } } OpenPositions = listMarket; PendingPositions = listPending; } catch(JFException e) { e.printStackTrace(); } } public void onMessage(IMessage message) throws JFException { if (message.getOrder() != null) { updateVariables(message.getOrder().getInstrument()); LastTradeEvent = message; for (TradeEventAction event : tradeEventActions) { IOrder order = message.getOrder(); if (order != null && event != null && message.getType().equals(event.getMessageType())&& order.getLabel().equals(event.getPositionLabel())) { Method method; try { method = this.getClass().getDeclaredMethod(event.getNextBlockId(), Integer.class); method.invoke(this, new Integer[] {event.getFlowId()}); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } tradeEventActions.remove(event); } } } } public void onStop() throws JFException { } public void onTick(Instrument instrument, ITick tick) throws JFException { LastTick = new Tick(tick, instrument); updateVariables(instrument); } public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { LastAskCandle = new Candle(askBar, period, instrument, OfferSide.ASK); LastBidCandle = new Candle(bidBar, period, instrument, OfferSide.BID); updateVariables(instrument); If_block_24(1); } public void subscriptionInstrumentCheck(Instrument instrument) { try { if (!context.getSubscribedInstruments().contains(instrument)) { Set instruments = new HashSet(); instruments.add(instrument); context.setSubscribedInstruments(instruments, true); Thread.sleep(100); } } catch (InterruptedException e) { e.printStackTrace(); } } public double round(double price, Instrument instrument) { BigDecimal big = new BigDecimal("" + price); big = big.setScale(instrument.getPipScale() + 1, BigDecimal.ROUND_HALF_UP); return big.doubleValue(); } public ITick getLastTick(Instrument instrument) { try { return (context.getHistory().getTick(instrument, 0)); } catch (JFException e) { e.printStackTrace(); } return null; } private void EMA_block_10(Integer flow) { Instrument argument_1 = defaultInstrument; Period argument_2 = _tempVar90; int argument_3 = 0; int argument_4 = _tempVar92; OfferSide[] offerside = new OfferSide[1]; IIndicators.AppliedPrice[] appliedPrice = new IIndicators.AppliedPrice[1]; offerside[0] = OfferSide.BID; appliedPrice[0] = IIndicators.AppliedPrice.CLOSE; Object[] params = new Object[1]; params[0] = _tempVar92; try { subscriptionInstrumentCheck(argument_1); long time = context.getHistory().getBar(argument_1, argument_2, OfferSide.BID, argument_3).getTime(); Object[] indicatorResult = context.getIndicators().calculateIndicator(argument_1, argument_2, offerside, "EMA", appliedPrice, params, Filter.WEEKENDS, 1, time, 0); if ((new Double(((double [])indicatorResult[0])[0])) == null) { this._ema10 = Double.NaN; } else { this._ema10 = (((double [])indicatorResult[0])[0]); } EMA_block_11(flow); } catch (JFException e) { e.printStackTrace(); console.getErr().println(e); this._ema10 = Double.NaN; } } private void EMA_block_11(Integer flow) { Instrument argument_1 = defaultInstrument; Period argument_2 = _tempVar94; int argument_3 = 0; int argument_4 = _tempVar96; OfferSide[] offerside = new OfferSide[1]; IIndicators.AppliedPrice[] appliedPrice = new IIndicators.AppliedPrice[1]; offerside[0] = OfferSide.BID; appliedPrice[0] = IIndicators.AppliedPrice.CLOSE; Object[] params = new Object[1]; params[0] = _tempVar96; try { subscriptionInstrumentCheck(argument_1); long time = context.getHistory().getBar(argument_1, argument_2, OfferSide.BID, argument_3).getTime(); Object[] indicatorResult = context.getIndicators().calculateIndicator(argument_1, argument_2, offerside, "EMA", appliedPrice, params, Filter.WEEKENDS, 1, time, 0); if ((new Double(((double [])indicatorResult[0])[0])) == null) { this._ema11 = Double.NaN; } else { this._ema11 = (((double [])indicatorResult[0])[0]); } EMA_block_12(flow); } catch (JFException e) { e.printStackTrace(); console.getErr().println(e); this._ema11 = Double.NaN; } } private void EMA_block_12(Integer flow) { Instrument argument_1 = defaultInstrument; Period argument_2 = _tempVar98; int argument_3 = 0; int argument_4 = _tempVar100; OfferSide[] offerside = new OfferSide[1]; IIndicators.AppliedPrice[] appliedPrice = new IIndicators.AppliedPrice[1]; offerside[0] = OfferSide.BID; appliedPrice[0] = IIndicators.AppliedPrice.CLOSE; Object[] params = new Object[1]; params[0] = _tempVar100; try { subscriptionInstrumentCheck(argument_1); long time = context.getHistory().getBar(argument_1, argument_2, OfferSide.BID, argument_3).getTime(); Object[] indicatorResult = context.getIndicators().calculateIndicator(argument_1, argument_2, offerside, "EMA", appliedPrice, params, Filter.WEEKENDS, 1, time, 0); if ((new Double(((double [])indicatorResult[0])[0])) == null) { this._ema12 = Double.NaN; } else { this._ema12 = (((double [])indicatorResult[0])[0]); } EMA_block_13(flow); } catch (JFException e) { e.printStackTrace(); console.getErr().println(e); this._ema12 = Double.NaN; } } private void EMA_block_13(Integer flow) { Instrument argument_1 = defaultInstrument; Period argument_2 = _tempVar102; int argument_3 = 0; int argument_4 = _tempVar104; OfferSide[] offerside = new OfferSide[1]; IIndicators.AppliedPrice[] appliedPrice = new IIndicators.AppliedPrice[1]; offerside[0] = OfferSide.BID; appliedPrice[0] = IIndicators.AppliedPrice.CLOSE; Object[] params = new Object[1]; params[0] = _tempVar104; try { subscriptionInstrumentCheck(argument_1); long time = context.getHistory().getBar(argument_1, argument_2, OfferSide.BID, argument_3).getTime(); Object[] indicatorResult = context.getIndicators().calculateIndicator(argument_1, argument_2, offerside, "EMA", appliedPrice, params, Filter.WEEKENDS, 1, time, 0); if ((new Double(((double [])indicatorResult[0])[0])) == null) { this._ema13 = Double.NaN; } else { this._ema13 = (((double [])indicatorResult[0])[0]); } SMA_block_33(flow); } catch (JFException e) { e.printStackTrace(); console.getErr().println(e); this._ema13 = Double.NaN; } } private void If_block_14(Integer flow) { double argument_1 = _ema12; double argument_2 = _ema13; if (argument_1< argument_2) { } else if (argument_1> argument_2) { MultipleAction_block_29(flow); } else if (argument_1== argument_2) { } } private void If_block_15(Integer flow) { double argument_1 = _ema10; double argument_2 = _ema11; if (argument_1< argument_2) { If_block_16(flow); } else if (argument_1> argument_2) { If_block_17(flow); } else if (argument_1== argument_2) { } } private void If_block_16(Integer flow) { double argument_1 = _ema11; double argument_2 = _ema12; if (argument_1< argument_2) { If_block_18(flow); } else if (argument_1> argument_2) { } else if (argument_1== argument_2) { } } private void If_block_17(Integer flow) { double argument_1 = _ema11; double argument_2 = _ema12; if (argument_1< argument_2) { } else if (argument_1> argument_2) { If_block_14(flow); } else if (argument_1== argument_2) { } } private void If_block_18(Integer flow) { double argument_1 = _ema12; double argument_2 = _ema13; if (argument_1< argument_2) { MultipleAction_block_30(flow); } else if (argument_1> argument_2) { } else if (argument_1== argument_2) { } } private void RSI_block_19(Integer flow) { Instrument argument_1 = defaultInstrument; Period argument_2 = _tempVar106; int argument_3 = 0; int argument_4 = _tempVar108; OfferSide[] offerside = new OfferSide[1]; IIndicators.AppliedPrice[] appliedPrice = new IIndicators.AppliedPrice[1]; offerside[0] = OfferSide.BID; appliedPrice[0] = IIndicators.AppliedPrice.CLOSE; Object[] params = new Object[1]; params[0] = _tempVar108; try { subscriptionInstrumentCheck(argument_1); long time = context.getHistory().getBar(argument_1, argument_2, OfferSide.BID, argument_3).getTime(); Object[] indicatorResult = context.getIndicators().calculateIndicator(argument_1, argument_2, offerside, "RSI", appliedPrice, params, Filter.WEEKENDS, 1, time, 0); if ((new Double(((double [])indicatorResult[0])[0])) == null) { this._out19 = Double.NaN; } else { this._out19 = (((double [])indicatorResult[0])[0]); } MultipleAction_block_43(flow); } catch (JFException e) { e.printStackTrace(); console.getErr().println(e); this._out19 = Double.NaN; } } private void If_block_20(Integer flow) { double argument_1 = _out19; double argument_2 = 25.0; if (argument_1< argument_2) { CalculationExpression_block_34(flow); } else if (argument_1> argument_2) { } else if (argument_1== argument_2) { } } private void If_block_21(Integer flow) { double argument_1 = _out19; double argument_2 = 70.0; if (argument_1< argument_2) { } else if (argument_1> argument_2) { CalculationExpression_block_39(flow); } else if (argument_1== argument_2) { } } private void OpenatMarket_block_22(Integer flow) { Instrument argument_1 = defaultInstrument; double argument_2 = 1.0; int argument_3 = defaultSlippage; int argument_4 = defaultStopLoss; int argument_5 = _TakeProfit3; String argument_6 = ""; ITick tick = getLastTick(argument_1); IEngine.OrderCommand command = IEngine.OrderCommand.BUY; double stopLoss = tick.getBid() - argument_1.getPipValue() * argument_4; double takeProfit = round(tick.getBid() + argument_1.getPipValue() * argument_5, argument_1); try { String label = getLabel(); IOrder order = context.getEngine().submitOrder(label, argument_1, command, argument_2, 0, argument_3, stopLoss, takeProfit, 0, argument_6); } catch (JFException e) { e.printStackTrace(); } } private void OpenatMarket_block_23(Integer flow) { Instrument argument_1 = defaultInstrument; double argument_2 = 1.0; int argument_3 = defaultSlippage; int argument_4 = 55; int argument_5 = 55; String argument_6 = ""; ITick tick = getLastTick(argument_1); IEngine.OrderCommand command = IEngine.OrderCommand.SELL; double stopLoss = tick.getAsk() + argument_1.getPipValue() * argument_4; double takeProfit = round(tick.getAsk() - argument_1.getPipValue() * argument_5, argument_1); try { String label = getLabel(); IOrder order = context.getEngine().submitOrder(label, argument_1, command, argument_2, 0, argument_3, stopLoss, takeProfit, 0, argument_6); } catch (JFException e) { e.printStackTrace(); } } private void If_block_24(Integer flow) { int argument_1 = AllPositions.size(); int argument_2 = 1; if (argument_1< argument_2) { EMA_block_10(flow); } else if (argument_1> argument_2) { } else if (argument_1== argument_2) { } } private void If_block_25(Integer flow) { double argument_1 = _out19; double argument_2 = 50.0; if (argument_1< argument_2) { If_block_71(flow); } else if (argument_1> argument_2) { } else if (argument_1== argument_2) { } } private void OpenatMarket_block_26(Integer flow) { Instrument argument_1 = defaultInstrument; double argument_2 = 3.0; int argument_3 = defaultSlippage; int argument_4 = 55; int argument_5 = 55; String argument_6 = ""; ITick tick = getLastTick(argument_1); IEngine.OrderCommand command = IEngine.OrderCommand.SELL; double stopLoss = tick.getAsk() + argument_1.getPipValue() * argument_4; double takeProfit = round(tick.getAsk() - argument_1.getPipValue() * argument_5, argument_1); try { String label = getLabel(); _Position_4 = context.getEngine().submitOrder(label, argument_1, command, argument_2, 0, argument_3, stopLoss, takeProfit, 0, argument_6); } catch (JFException e) { e.printStackTrace(); } } private void If_block_27(Integer flow) { double argument_1 = _out19; double argument_2 = 51.0; if (argument_1< argument_2) { } else if (argument_1> argument_2) { If_block_72(flow); } else if (argument_1== argument_2) { } } private void OpenatMarket_block_28(Integer flow) { Instrument argument_1 = defaultInstrument; double argument_2 = 3.0; int argument_3 = defaultSlippage; int argument_4 = 55; int argument_5 = 55; String argument_6 = ""; ITick tick = getLastTick(argument_1); IEngine.OrderCommand command = IEngine.OrderCommand.BUY; double stopLoss = tick.getBid() - argument_1.getPipValue() * argument_4; double takeProfit = round(tick.getBid() + argument_1.getPipValue() * argument_5, argument_1); try { String label = getLabel(); _Position_3 = context.getEngine().submitOrder(label, argument_1, command, argument_2, 0, argument_3, stopLoss, takeProfit, 0, argument_6); } catch (JFException e) { e.printStackTrace(); } } private void MultipleAction_block_29(Integer flow) { If_block_20(flow); If_block_25(flow); } private void MultipleAction_block_30(Integer flow) { If_block_21(flow); If_block_27(flow); } private void SMA_block_33(Integer flow) { Instrument argument_1 = defaultInstrument; Period argument_2 = _tempVar208; int argument_3 = 0; int argument_4 = _tempVar140; OfferSide[] offerside = new OfferSide[1]; IIndicators.AppliedPrice[] appliedPrice = new IIndicators.AppliedPrice[1]; offerside[0] = OfferSide.BID; appliedPrice[0] = IIndicators.AppliedPrice.CLOSE; Object[] params = new Object[1]; params[0] = _tempVar140; try { subscriptionInstrumentCheck(argument_1); long time = context.getHistory().getBar(argument_1, argument_2, OfferSide.BID, argument_3).getTime(); Object[] indicatorResult = context.getIndicators().calculateIndicator(argument_1, argument_2, offerside, "SMA", appliedPrice, params, Filter.WEEKENDS, 1, time, 0); if ((new Double(((double [])indicatorResult[0])[0])) == null) { this._line33 = Double.NaN; } else { this._line33 = (((double [])indicatorResult[0])[0]); } RSI_block_19(flow); } catch (JFException e) { e.printStackTrace(); console.getErr().println(e); this._line33 = Double.NaN; } } private void CalculationExpression_block_34(Integer flow) { _Percent = 100*(_ema10-_line33)/ (float)_ema10; If_block_36(flow); } private void If_block_36(Integer flow) { double argument_1 = _Percent; double argument_2 = 1.8; if (argument_1< argument_2) { } else if (argument_1> argument_2) { If_block_54(flow); } else if (argument_1== argument_2) { } } private void CalculationExpression_block_37(Integer flow) { _Percent1 = 100*(_ema10-_line33)/ (float)_ema10; If_block_38(flow); } private void If_block_38(Integer flow) { double argument_1 = _Percent1; double argument_2 = 0.3; if (argument_1< argument_2) { OpenatMarket_block_26(flow); } else if (argument_1> argument_2) { } else if (argument_1== argument_2) { } } private void CalculationExpression_block_39(Integer flow) { _Percent3 = 100*(_line33-_ema10)/ (float)_line33; If_block_40(flow); } private void If_block_40(Integer flow) { double argument_1 = _Percent3; double argument_2 = 1.8; if (argument_1< argument_2) { } else if (argument_1> argument_2) { If_block_60(flow); } else if (argument_1== argument_2) { } } private void CalculationExpression_block_41(Integer flow) { _Percent4 = 100*(_line33-_ema10)/ (float)_line33; If_block_42(flow); } private void If_block_42(Integer flow) { double argument_1 = _Percent4; double argument_2 = 0.3; if (argument_1< argument_2) { OpenatMarket_block_28(flow); } else if (argument_1> argument_2) { } else if (argument_1== argument_2) { } } private void MultipleAction_block_43(Integer flow) { If_block_44(flow); If_block_49(flow); If_block_15(flow); } private void If_block_44(Integer flow) { double argument_1 = _ema10; double argument_2 = _ema13; if (argument_1< argument_2) { If_block_67(flow); } else if (argument_1> argument_2) { } else if (argument_1== argument_2) { } } private void If_block_45(Integer flow) { double argument_1 = _ema13; double argument_2 = _line33; if (argument_1< argument_2) { CalculationExpression_block_46(flow); } else if (argument_1> argument_2) { } else if (argument_1== argument_2) { } } private void CalculationExpression_block_46(Integer flow) { _Percent5 = (_ema13-_ema10)/ (float)_ema13*100; If_block_47(flow); } private void If_block_47(Integer flow) { double argument_1 = _Percent5; double argument_2 = 0.25; if (argument_1< argument_2) { OpenatMarket_block_48(flow); } else if (argument_1> argument_2) { } else if (argument_1== argument_2) { } } private void OpenatMarket_block_48(Integer flow) { Instrument argument_1 = defaultInstrument; double argument_2 = defaultTradeAmount; int argument_3 = defaultSlippage; int argument_4 = 95; int argument_5 = defaultTakeProfit; String argument_6 = ""; ITick tick = getLastTick(argument_1); IEngine.OrderCommand command = IEngine.OrderCommand.BUY; double stopLoss = tick.getBid() - argument_1.getPipValue() * argument_4; double takeProfit = round(tick.getBid() + argument_1.getPipValue() * argument_5, argument_1); try { String label = getLabel(); _Position_1 = context.getEngine().submitOrder(label, argument_1, command, argument_2, 0, argument_3, stopLoss, takeProfit, 0, argument_6); } catch (JFException e) { e.printStackTrace(); } } private void If_block_49(Integer flow) { double argument_1 = _ema10; double argument_2 = _ema13; if (argument_1< argument_2) { } else if (argument_1> argument_2) { If_block_68(flow); } else if (argument_1== argument_2) { } } private void If_block_50(Integer flow) { double argument_1 = _ema13; double argument_2 = _line33; if (argument_1< argument_2) { } else if (argument_1> argument_2) { CalculationExpression_block_51(flow); } else if (argument_1== argument_2) { } } private void CalculationExpression_block_51(Integer flow) { _Percent6 = (_ema10-_ema13)/ (float)_ema10*100; If_block_52(flow); } private void If_block_52(Integer flow) { double argument_1 = _Percent6; double argument_2 = 0.25; if (argument_1< argument_2) { OpenatMarket_block_53(flow); } else if (argument_1> argument_2) { } else if (argument_1== argument_2) { } } private void OpenatMarket_block_53(Integer flow) { Instrument argument_1 = defaultInstrument; double argument_2 = defaultTradeAmount; int argument_3 = defaultSlippage; int argument_4 = 95; int argument_5 = defaultTakeProfit; String argument_6 = ""; ITick tick = getLastTick(argument_1); IEngine.OrderCommand command = IEngine.OrderCommand.SELL; double stopLoss = tick.getAsk() + argument_1.getPipValue() * argument_4; double takeProfit = round(tick.getAsk() - argument_1.getPipValue() * argument_5, argument_1); try { String label = getLabel(); _Position_2 = context.getEngine().submitOrder(label, argument_1, command, argument_2, 0, argument_3, stopLoss, takeProfit, 0, argument_6); } catch (JFException e) { e.printStackTrace(); } } private void If_block_54(Integer flow) { double argument_1 = _Percent; double argument_2 = 2.0; if (argument_1< argument_2) { OpenatMarket_block_22(flow); } else if (argument_1> argument_2) { If_block_55(flow); } else if (argument_1== argument_2) { } } private void If_block_55(Integer flow) { double argument_1 = _Percent; double argument_2 = 2.2; if (argument_1< argument_2) { OpenatMarket_block_56(flow); } else if (argument_1> argument_2) { If_block_57(flow); } else if (argument_1== argument_2) { } } private void OpenatMarket_block_56(Integer flow) { Instrument argument_1 = defaultInstrument; double argument_2 = 2.0; int argument_3 = defaultSlippage; int argument_4 = defaultStopLoss; int argument_5 = 65; String argument_6 = ""; ITick tick = getLastTick(argument_1); IEngine.OrderCommand command = IEngine.OrderCommand.BUY; double stopLoss = tick.getBid() - argument_1.getPipValue() * argument_4; double takeProfit = round(tick.getBid() + argument_1.getPipValue() * argument_5, argument_1); try { String label = getLabel(); IOrder order = context.getEngine().submitOrder(label, argument_1, command, argument_2, 0, argument_3, stopLoss, takeProfit, 0, argument_6); } catch (JFException e) { e.printStackTrace(); } } private void If_block_57(Integer flow) { double argument_1 = _Percent; double argument_2 = 2.4; if (argument_1< argument_2) { OpenatMarket_block_58(flow); } else if (argument_1> argument_2) { OpenatMarket_block_59(flow); } else if (argument_1== argument_2) { } } private void OpenatMarket_block_58(Integer flow) { Instrument argument_1 = defaultInstrument; double argument_2 = 3.0; int argument_3 = defaultSlippage; int argument_4 = defaultStopLoss; int argument_5 = 75; String argument_6 = ""; ITick tick = getLastTick(argument_1); IEngine.OrderCommand command = IEngine.OrderCommand.BUY; double stopLoss = tick.getBid() - argument_1.getPipValue() * argument_4; double takeProfit = round(tick.getBid() + argument_1.getPipValue() * argument_5, argument_1); try { String label = getLabel(); IOrder order = context.getEngine().submitOrder(label, argument_1, command, argument_2, 0, argument_3, stopLoss, takeProfit, 0, argument_6); } catch (JFException e) { e.printStackTrace(); } } private void OpenatMarket_block_59(Integer flow) { Instrument argument_1 = defaultInstrument; double argument_2 = defaultTradeAmount; int argument_3 = defaultSlippage; int argument_4 = 75; int argument_5 = defaultTakeProfit; String argument_6 = ""; ITick tick = getLastTick(argument_1); IEngine.OrderCommand command = IEngine.OrderCommand.BUY; double stopLoss = tick.getBid() - argument_1.getPipValue() * argument_4; double takeProfit = round(tick.getBid() + argument_1.getPipValue() * argument_5, argument_1); try { String label = getLabel(); IOrder order = context.getEngine().submitOrder(label, argument_1, command, argument_2, 0, argument_3, stopLoss, takeProfit, 0, argument_6); } catch (JFException e) { e.printStackTrace(); } } private void If_block_60(Integer flow) { double argument_1 = _Percent3; double argument_2 = 2.0; if (argument_1< argument_2) { OpenatMarket_block_23(flow); } else if (argument_1> argument_2) { If_block_61(flow); } else if (argument_1== argument_2) { } } private void If_block_61(Integer flow) { double argument_1 = _Percent3; double argument_2 = 2.2; if (argument_1< argument_2) { OpenatMarket_block_63(flow); } else if (argument_1> argument_2) { If_block_62(flow); } else if (argument_1== argument_2) { } } private void If_block_62(Integer flow) { double argument_1 = _Percent3; double argument_2 = 2.4; if (argument_1< argument_2) { OpenatMarket_block_64(flow); } else if (argument_1> argument_2) { OpenatMarket_block_65(flow); } else if (argument_1== argument_2) { } } private void OpenatMarket_block_63(Integer flow) { Instrument argument_1 = defaultInstrument; double argument_2 = 2.0; int argument_3 = defaultSlippage; int argument_4 = 45; int argument_5 = 65; String argument_6 = ""; ITick tick = getLastTick(argument_1); IEngine.OrderCommand command = IEngine.OrderCommand.BUY; double stopLoss = tick.getBid() - argument_1.getPipValue() * argument_4; double takeProfit = round(tick.getBid() + argument_1.getPipValue() * argument_5, argument_1); try { String label = getLabel(); IOrder order = context.getEngine().submitOrder(label, argument_1, command, argument_2, 0, argument_3, stopLoss, takeProfit, 0, argument_6); } catch (JFException e) { e.printStackTrace(); } } private void OpenatMarket_block_64(Integer flow) { Instrument argument_1 = defaultInstrument; double argument_2 = defaultTradeAmount; int argument_3 = defaultSlippage; int argument_4 = defaultStopLoss; int argument_5 = 75; String argument_6 = ""; ITick tick = getLastTick(argument_1); IEngine.OrderCommand command = IEngine.OrderCommand.BUY; double stopLoss = tick.getBid() - argument_1.getPipValue() * argument_4; double takeProfit = round(tick.getBid() + argument_1.getPipValue() * argument_5, argument_1); try { String label = getLabel(); IOrder order = context.getEngine().submitOrder(label, argument_1, command, argument_2, 0, argument_3, stopLoss, takeProfit, 0, argument_6); } catch (JFException e) { e.printStackTrace(); } } private void OpenatMarket_block_65(Integer flow) { Instrument argument_1 = defaultInstrument; double argument_2 = defaultTradeAmount; int argument_3 = defaultSlippage; int argument_4 = 75; int argument_5 = defaultTakeProfit; String argument_6 = ""; ITick tick = getLastTick(argument_1); IEngine.OrderCommand command = IEngine.OrderCommand.BUY; double stopLoss = tick.getBid() - argument_1.getPipValue() * argument_4; double takeProfit = round(tick.getBid() + argument_1.getPipValue() * argument_5, argument_1); try { String label = getLabel(); IOrder order = context.getEngine().submitOrder(label, argument_1, command, argument_2, 0, argument_3, stopLoss, takeProfit, 0, argument_6); } catch (JFException e) { e.printStackTrace(); } } private void CloseandCancelPosition_block_66(Integer flow) { try { if (_Position_1 != null && (_Position_1.getState() == IOrder.State.OPENED||_Position_1.getState() == IOrder.State.FILLED)){ _Position_1.close(); } } catch (JFException e) { e.printStackTrace(); } } private void If_block_67(Integer flow) { int argument_1 = AllPositions.size(); int argument_2 = 0; if (argument_1< argument_2) { } else if (argument_1> argument_2) { MultipleAction_block_75(flow); } else if (argument_1== argument_2) { If_block_45(flow); } } private void If_block_68(Integer flow) { int argument_1 = AllPositions.size(); int argument_2 = 0; if (argument_1< argument_2) { } else if (argument_1> argument_2) { MultipleAction_block_76(flow); } else if (argument_1== argument_2) { If_block_50(flow); } } private void CloseandCancelPosition_block_69(Integer flow) { try { if (_Position_1 != null && (_Position_1.getState() == IOrder.State.OPENED||_Position_1.getState() == IOrder.State.FILLED)){ _Position_1.close(); } } catch (JFException e) { e.printStackTrace(); } } private void CloseandCancelPosition_block_70(Integer flow) { try { if (_Position_3 != null && (_Position_3.getState() == IOrder.State.OPENED||_Position_3.getState() == IOrder.State.FILLED)){ _Position_3.close(); } } catch (JFException e) { e.printStackTrace(); } } private void If_block_71(Integer flow) { int argument_1 = AllPositions.size(); int argument_2 = 0; if (argument_1< argument_2) { } else if (argument_1> argument_2) { CloseandCancelPosition_block_70(flow); } else if (argument_1== argument_2) { CalculationExpression_block_37(flow); } } private void If_block_72(Integer flow) { int argument_1 = AllPositions.size(); int argument_2 = 0; if (argument_1< argument_2) { } else if (argument_1> argument_2) { CloseandCancelPosition_block_73(flow); } else if (argument_1== argument_2) { CalculationExpression_block_41(flow); } } private void CloseandCancelPosition_block_73(Integer flow) { try { if (_Position_4 != null && (_Position_4.getState() == IOrder.State.OPENED||_Position_4.getState() == IOrder.State.FILLED)){ _Position_4.close(); } } catch (JFException e) { e.printStackTrace(); } } private void CloseandCancelPosition_block_74(Integer flow) { try { if (_Position_4 != null && (_Position_4.getState() == IOrder.State.OPENED||_Position_4.getState() == IOrder.State.FILLED)){ _Position_4.close(); } } catch (JFException e) { e.printStackTrace(); } } private void MultipleAction_block_75(Integer flow) { CloseandCancelPosition_block_66(flow); CloseandCancelPosition_block_74(flow); } private void MultipleAction_block_76(Integer flow) { CloseandCancelPosition_block_69(flow); CloseandCancelPosition_block_77(flow); } private void CloseandCancelPosition_block_77(Integer flow) { try { if (_Position_3 != null && (_Position_3.getState() == IOrder.State.OPENED||_Position_3.getState() == IOrder.State.FILLED)){ _Position_3.close(); } } catch (JFException e) { e.printStackTrace(); } } class Candle { IBar bar; Period period; Instrument instrument; OfferSide offerSide; public Candle(IBar bar, Period period, Instrument instrument, OfferSide offerSide) { this.bar = bar; this.period = period; this.instrument = instrument; this.offerSide = offerSide; } public Period getPeriod() { return period; } public void setPeriod(Period period) { this.period = period; } public Instrument getInstrument() { return instrument; } public void setInstrument(Instrument instrument) { this.instrument = instrument; } public OfferSide getOfferSide() { return offerSide; } public void setOfferSide(OfferSide offerSide) { this.offerSide = offerSide; } public IBar getBar() { return bar; } public void setBar(IBar bar) { this.bar = bar; } public long getTime() { return bar.getTime(); } public double getOpen() { return bar.getOpen(); } public double getClose() { return bar.getClose(); } public double getLow() { return bar.getLow(); } public double getHigh() { return bar.getHigh(); } public double getVolume() { return bar.getVolume(); } } class Tick { private ITick tick; private Instrument instrument; public Tick(ITick tick, Instrument instrument){ this.instrument = instrument; this.tick = tick; } public Instrument getInstrument(){ return instrument; } public double getAsk(){ return tick.getAsk(); } public double getBid(){ return tick.getBid(); } public double getAskVolume(){ return tick.getAskVolume(); } public double getBidVolume(){ return tick.getBidVolume(); } public long getTime(){ return tick.getTime(); } public ITick getTick(){ return tick; } } protected String getLabel() { String label; label = "IVF" + getCurrentTime(LastTick.getTime()) + generateRandom(10000) + generateRandom(10000); return label; } private String getCurrentTime(long time) { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); return sdf.format(time); } private static String generateRandom(int n) { int randomNumber = (int) (Math.random() * n); String answer = "" + randomNumber; if (answer.length() > 3) { answer = answer.substring(0, 4); } return answer; } class TradeEventAction { private IMessage.Type messageType; private String nextBlockId = ""; private String positionLabel = ""; private int flowId = 0; public IMessage.Type getMessageType() { return messageType; } public void setMessageType(IMessage.Type messageType) { this.messageType = messageType; } public String getNextBlockId() { return nextBlockId; } public void setNextBlockId(String nextBlockId) { this.nextBlockId = nextBlockId; } public String getPositionLabel() { return positionLabel; } public void setPositionLabel(String positionLabel) { this.positionLabel = positionLabel; } public int getFlowId() { return flowId; } public void setFlowId(int flowId) { this.flowId = flowId; } } }