package com.dukascopy.visualforex.visualjforex;

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.40
 * Date: 02.08.2017 15:55
 */
public class ATR_CHanel implements IStrategy {

    private CopyOnWriteArrayList<TradeEventAction> tradeEventActions = new CopyOnWriteArrayList<TradeEventAction>();
    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("defaultTakeProfit:")
    public int defaultTakeProfit = 12;
    @Configurable("defaultTradeAmount:")
    public double defaultTradeAmount = 10.0;
    @Configurable("defaultInstrument:")
    public Instrument defaultInstrument = Instrument.EURUSD;
    @Configurable("defaultSlippage:")
    public int defaultSlippage = 2;
    @Configurable("defaultStopLoss:")
    public int defaultStopLoss = 12;
    @Configurable("defaultPeriod:")
    public Period defaultPeriod = Period.ONE_MIN;

    private Instrument _USD_CAD = Instrument.USDCAD;
    private double _lowerBand_eur_usd;
    private double _upperBand_eur_jpy;
    private double _upperBand_gbp_usd;
    private Candle _EUR_JPY_CANDLE =  null ;
    private Tick LastTick =  null ;
    private String AccountCurrency = "";
    private double _Sell_Eur;
    private double _Sell_GBP_JPY;
    private double _upperBand_gbp_jpy;
    private double Leverage;
    private double _ATR_GBP_MUL;
    private double _Sell_Cad;
    private double _Buy_Eur_JPY;
    private Instrument _GBP_USD = Instrument.GBPUSD;
    private Candle _CAD_CANDLE =  null ;
    private double _lowerBand_gbp_jpy;
    private double _ATR_CAD_MUL;
    private double _ATR_EUR;
    private double _ATR_CAD;
    private Instrument _EUR_JPY = Instrument.EURJPY;
    private double _lowerBand_eur_jpy;
    private double _lowerBand_gbp_usd;
    private Candle _Eur_JPY_Candle =  null ;
    private Instrument _GBP_JPY = Instrument.GBPJPY;
    private Candle LastAskCandle =  null ;
    private double _Buy_GBP_JPY;
    private double _ATR_EUR_JPY_MUL;
    private double _ATR_GBP_JPY_MUL;
    private Candle _GBP_JPY_CANDLE =  null ;
    private double _middleBand40;
    private Candle LastBidCandle =  null ;
    private String AccountId = "";
    private double _Sell_GBP;
    private double Equity;
    private double _ATR_GBP_JPY;
    private double _Sell_Eur_Jpy;
    private int OverWeekendEndLeverage;
    private double _middleBand32;
    private Instrument _EUR_USD = Instrument.EURUSD;
    private double _ATR_EUR_MUL;
    private double _middleBand38;
    private double _lowerBand_cad;
    private double _middleBand36;
    private double _Buy_GBP;
    private double _ATR_GBP_USD;
    private List<IOrder> PendingPositions =  null ;
    private Candle _EUR_CANDLE =  null ;
    private double _upperBand_cad;
    private double _Buy_Cad;
    private Candle _GBP_CANDLE =  null ;
    private List<IOrder> OpenPositions =  null ;
    private double _ATR_EUR_JPY;
    private double _Buy_Eur;
    private double UseofLeverage;
    private double _upperBand_eur_usd;
    private IMessage LastTradeEvent =  null ;
    private boolean GlobalAccount;
    private double _middleBand28;
    private int MarginCutLevel;
    private List<IOrder> AllPositions =  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("ATR") == null) {
            indicators.registerDownloadableIndicator("1305","ATR");
        }
        if (indicators.getIndicator("KELTNER") == null) {
            indicators.registerDownloadableIndicator("1299","KELTNER");
        }
        if (indicators.getIndicator("ATR") == null) {
            indicators.registerDownloadableIndicator("1305","ATR");
        }
        if (indicators.getIndicator("KELTNER") == null) {
            indicators.registerDownloadableIndicator("1299","KELTNER");
        }
        if (indicators.getIndicator("ATR") == null) {
            indicators.registerDownloadableIndicator("1305","ATR");
        }
        if (indicators.getIndicator("KELTNER") == null) {
            indicators.registerDownloadableIndicator("1299","KELTNER");
        }
        if (indicators.getIndicator("ATR") == null) {
            indicators.registerDownloadableIndicator("1305","ATR");
        }
        if (indicators.getIndicator("KELTNER") == null) {
            indicators.registerDownloadableIndicator("1299","KELTNER");
        }
        if (indicators.getIndicator("ATR") == null) {
            indicators.registerDownloadableIndicator("1305","ATR");
        }
        if (indicators.getIndicator("KELTNER") == null) {
            indicators.registerDownloadableIndicator("1299","KELTNER");
        }
        subscriptionInstrumentCheck(Instrument.fromString("USD/CAD"));

        subscriptionInstrumentCheck(Instrument.fromString("GBP/USD"));

        subscriptionInstrumentCheck(Instrument.fromString("EUR/JPY"));

        subscriptionInstrumentCheck(Instrument.fromString("GBP/JPY"));

        subscriptionInstrumentCheck(Instrument.fromString("EUR/USD"));

        subscriptionInstrumentCheck(Instrument.fromString("EUR/USD"));

    }

    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<IOrder> listMarket = new ArrayList<IOrder>();
            for (IOrder order: AllPositions) {
                if (order.getState().equals(IOrder.State.FILLED)){
                    listMarket.add(order);
                }
            }
            List<IOrder> listPending = new ArrayList<IOrder>();
            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_16(1);

    }

    public void subscriptionInstrumentCheck(Instrument instrument) {
        try {
              if (!context.getSubscribedInstruments().contains(instrument)) {
                  Set<Instrument> instruments = new HashSet<Instrument>();
                  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 If_block_10(Integer flow) {
        Instrument argument_1 = _EUR_JPY;
        Instrument argument_2 = LastBidCandle.getInstrument();
        if (argument_1 == null && argument_2 !=null || (argument_1!= null && !argument_1.equals(argument_2))) {
            If_block_11(flow);
        }
        else if (argument_1!= null && argument_1.equals(argument_2)) {
            GetHistoricalCandle_block_22(flow);
        }
    }

    private  void If_block_11(Integer flow) {
        Instrument argument_1 = _GBP_JPY;
        Instrument argument_2 = LastBidCandle.getInstrument();
        if (argument_1 == null && argument_2 !=null || (argument_1!= null && !argument_1.equals(argument_2))) {
            If_block_12(flow);
        }
        else if (argument_1!= null && argument_1.equals(argument_2)) {
            GetHistoricalCandle_block_23(flow);
        }
    }

    private  void If_block_12(Integer flow) {
        Instrument argument_1 = _GBP_USD;
        Instrument argument_2 = LastBidCandle.getInstrument();
        if (argument_1 == null && argument_2 !=null || (argument_1!= null && !argument_1.equals(argument_2))) {
            If_block_13(flow);
        }
        else if (argument_1!= null && argument_1.equals(argument_2)) {
            GetHistoricalCandle_block_24(flow);
        }
    }

    private  void If_block_13(Integer flow) {
        Instrument argument_1 = _EUR_USD;
        Instrument argument_2 = LastBidCandle.getInstrument();
        if (argument_1 == null && argument_2 !=null || (argument_1!= null && !argument_1.equals(argument_2))) {
            If_block_14(flow);
        }
        else if (argument_1!= null && argument_1.equals(argument_2)) {
            GetHistoricalCandle_block_25(flow);
        }
    }

    private  void If_block_14(Integer flow) {
        Instrument argument_1 = _USD_CAD;
        Instrument argument_2 = LastBidCandle.getInstrument();
        if (argument_1 == null && argument_2 !=null || (argument_1!= null && !argument_1.equals(argument_2))) {
        }
        else if (argument_1!= null && argument_1.equals(argument_2)) {
            GetHistoricalCandle_block_26(flow);
        }
    }

    private  void If_block_16(Integer flow) {
        Period argument_1 = defaultPeriod;
        Period argument_2 = LastBidCandle.getPeriod();
        if (argument_1 == null && argument_2 !=null || (argument_1!= null && !argument_1.equals(argument_2))) {
        }
        else if (argument_1!= null && argument_1.equals(argument_2)) {
            If_block_10(flow);
        }
    }

    private  void GetHistoricalCandle_block_22(Integer flow) {
        Instrument argument_1 = _EUR_JPY;
        Period argument_2 = defaultPeriod;
        OfferSide argument_3 = OfferSide.BID;
        int argument_4 = 1;
            subscriptionInstrumentCheck(argument_1);
         
        try {
            IBar tempBar = history.getBar(argument_1, argument_2, argument_3, argument_4); 
            _Eur_JPY_Candle = new Candle(tempBar, argument_2, argument_1, argument_3); 
        } catch (JFException e) {
            e.printStackTrace();
        }
        ATR_block_27(flow);
    }

    private  void GetHistoricalCandle_block_23(Integer flow) {
        Instrument argument_1 = _GBP_JPY;
        Period argument_2 = defaultPeriod;
        OfferSide argument_3 = OfferSide.BID;
        int argument_4 = 1;
            subscriptionInstrumentCheck(argument_1);
         
        try {
            IBar tempBar = history.getBar(argument_1, argument_2, argument_3, argument_4); 
            _GBP_JPY_CANDLE = new Candle(tempBar, argument_2, argument_1, argument_3); 
        } catch (JFException e) {
            e.printStackTrace();
        }
        ATR_block_39(flow);
    }

    private  void GetHistoricalCandle_block_24(Integer flow) {
        Instrument argument_1 = _GBP_USD;
        Period argument_2 = defaultPeriod;
        OfferSide argument_3 = OfferSide.BID;
        int argument_4 = 1;
            subscriptionInstrumentCheck(argument_1);
         
        try {
            IBar tempBar = history.getBar(argument_1, argument_2, argument_3, argument_4); 
            _GBP_CANDLE = new Candle(tempBar, argument_2, argument_1, argument_3); 
        } catch (JFException e) {
            e.printStackTrace();
        }
        ATR_block_31(flow);
    }

    private  void GetHistoricalCandle_block_25(Integer flow) {
        Instrument argument_1 = _EUR_USD;
        Period argument_2 = defaultPeriod;
        OfferSide argument_3 = OfferSide.BID;
        int argument_4 = 1;
            subscriptionInstrumentCheck(argument_1);
         
        try {
            IBar tempBar = history.getBar(argument_1, argument_2, argument_3, argument_4); 
            _EUR_CANDLE = new Candle(tempBar, argument_2, argument_1, argument_3); 
        } catch (JFException e) {
            e.printStackTrace();
        }
        ATR_block_35(flow);
    }

    private  void GetHistoricalCandle_block_26(Integer flow) {
        Instrument argument_1 = _USD_CAD;
        Period argument_2 = defaultPeriod;
        OfferSide argument_3 = OfferSide.BID;
        int argument_4 = 1;
            subscriptionInstrumentCheck(argument_1);
         
        try {
            IBar tempBar = history.getBar(argument_1, argument_2, argument_3, argument_4); 
            _CAD_CANDLE = new Candle(tempBar, argument_2, argument_1, argument_3); 
        } catch (JFException e) {
            e.printStackTrace();
        }
        ATR_block_37(flow);
    }

    private void ATR_block_27(Integer flow) {
        Instrument argument_1 = _EUR_JPY;
        Period argument_2 = Period.ONE_MIN;
        int argument_3 = 2;
        int argument_4 = 61;
        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] = 61;
        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,
                    "ATR", appliedPrice, params, Filter.WEEKENDS, 1, time, 0);
            if ((new Double(((double [])indicatorResult[0])[0])) == null) {
                this._ATR_EUR_JPY = Double.NaN;
            } else { 
                this._ATR_EUR_JPY = (((double [])indicatorResult[0])[0]);
            } 
        KELTNER_block_28(flow);
        } catch (JFException e) {
            e.printStackTrace();
            console.getErr().println(e);
            this._ATR_EUR_JPY = Double.NaN;
        }
    }

    private void KELTNER_block_28(Integer flow) {
        Instrument argument_1 = _EUR_JPY;
        Period argument_2 = Period.ONE_MIN;
        int argument_3 = 2;
        int argument_4 = 61;
        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] = 61;
        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,
                    "KELTNER", appliedPrice, params, Filter.WEEKENDS, 1, time, 0);
            if ((new Double(((double [])indicatorResult[0])[0])) == null) {
                this._upperBand_eur_jpy = Double.NaN;
            } else { 
                this._upperBand_eur_jpy = (((double [])indicatorResult[0])[0]);
            } 
            if ((new Double(((double [])indicatorResult[1])[0])) == null) {
                this._middleBand28 = Double.NaN;
            } else { 
                this._middleBand28 = (((double [])indicatorResult[1])[0]);
            } 
            if ((new Double(((double [])indicatorResult[2])[0])) == null) {
                this._lowerBand_eur_jpy = Double.NaN;
            } else { 
                this._lowerBand_eur_jpy = (((double [])indicatorResult[2])[0]);
            } 
        Calculation_block_41(flow);
        } catch (JFException e) {
            e.printStackTrace();
            console.getErr().println(e);
            this._upperBand_eur_jpy = Double.NaN;
            this._middleBand28 = Double.NaN;
            this._lowerBand_eur_jpy = Double.NaN;
        }
    }

    private void ATR_block_31(Integer flow) {
        Instrument argument_1 = _GBP_USD;
        Period argument_2 = Period.ONE_MIN;
        int argument_3 = 2;
        int argument_4 = 61;
        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] = 61;
        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,
                    "ATR", appliedPrice, params, Filter.WEEKENDS, 1, time, 0);
            if ((new Double(((double [])indicatorResult[0])[0])) == null) {
                this._ATR_GBP_USD = Double.NaN;
            } else { 
                this._ATR_GBP_USD = (((double [])indicatorResult[0])[0]);
            } 
        KELTNER_block_32(flow);
        } catch (JFException e) {
            e.printStackTrace();
            console.getErr().println(e);
            this._ATR_GBP_USD = Double.NaN;
        }
    }

    private void KELTNER_block_32(Integer flow) {
        Instrument argument_1 = _GBP_USD;
        Period argument_2 = Period.ONE_MIN;
        int argument_3 = 2;
        int argument_4 = 61;
        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] = 61;
        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,
                    "KELTNER", appliedPrice, params, Filter.WEEKENDS, 1, time, 0);
            if ((new Double(((double [])indicatorResult[0])[0])) == null) {
                this._upperBand_gbp_usd = Double.NaN;
            } else { 
                this._upperBand_gbp_usd = (((double [])indicatorResult[0])[0]);
            } 
            if ((new Double(((double [])indicatorResult[1])[0])) == null) {
                this._middleBand32 = Double.NaN;
            } else { 
                this._middleBand32 = (((double [])indicatorResult[1])[0]);
            } 
            if ((new Double(((double [])indicatorResult[2])[0])) == null) {
                this._lowerBand_gbp_usd = Double.NaN;
            } else { 
                this._lowerBand_gbp_usd = (((double [])indicatorResult[2])[0]);
            } 
        Calculation_block_43(flow);
        } catch (JFException e) {
            e.printStackTrace();
            console.getErr().println(e);
            this._upperBand_gbp_usd = Double.NaN;
            this._middleBand32 = Double.NaN;
            this._lowerBand_gbp_usd = Double.NaN;
        }
    }

    private void ATR_block_35(Integer flow) {
        Instrument argument_1 = _EUR_USD;
        Period argument_2 = Period.ONE_MIN;
        int argument_3 = 2;
        int argument_4 = 61;
        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] = 61;
        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,
                    "ATR", appliedPrice, params, Filter.WEEKENDS, 1, time, 0);
            if ((new Double(((double [])indicatorResult[0])[0])) == null) {
                this._ATR_EUR = Double.NaN;
            } else { 
                this._ATR_EUR = (((double [])indicatorResult[0])[0]);
            } 
        KELTNER_block_36(flow);
        } catch (JFException e) {
            e.printStackTrace();
            console.getErr().println(e);
            this._ATR_EUR = Double.NaN;
        }
    }

    private void KELTNER_block_36(Integer flow) {
        Instrument argument_1 = _EUR_USD;
        Period argument_2 = Period.ONE_MIN;
        int argument_3 = 2;
        int argument_4 = 61;
        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] = 61;
        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,
                    "KELTNER", appliedPrice, params, Filter.WEEKENDS, 1, time, 0);
            if ((new Double(((double [])indicatorResult[0])[0])) == null) {
                this._upperBand_eur_usd = Double.NaN;
            } else { 
                this._upperBand_eur_usd = (((double [])indicatorResult[0])[0]);
            } 
            if ((new Double(((double [])indicatorResult[1])[0])) == null) {
                this._middleBand36 = Double.NaN;
            } else { 
                this._middleBand36 = (((double [])indicatorResult[1])[0]);
            } 
            if ((new Double(((double [])indicatorResult[2])[0])) == null) {
                this._lowerBand_eur_usd = Double.NaN;
            } else { 
                this._lowerBand_eur_usd = (((double [])indicatorResult[2])[0]);
            } 
        Calculation_block_44(flow);
        } catch (JFException e) {
            e.printStackTrace();
            console.getErr().println(e);
            this._upperBand_eur_usd = Double.NaN;
            this._middleBand36 = Double.NaN;
            this._lowerBand_eur_usd = Double.NaN;
        }
    }

    private void ATR_block_37(Integer flow) {
        Instrument argument_1 = _USD_CAD;
        Period argument_2 = Period.ONE_MIN;
        int argument_3 = 2;
        int argument_4 = 61;
        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] = 61;
        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,
                    "ATR", appliedPrice, params, Filter.WEEKENDS, 1, time, 0);
            if ((new Double(((double [])indicatorResult[0])[0])) == null) {
                this._ATR_CAD = Double.NaN;
            } else { 
                this._ATR_CAD = (((double [])indicatorResult[0])[0]);
            } 
        KELTNER_block_38(flow);
        } catch (JFException e) {
            e.printStackTrace();
            console.getErr().println(e);
            this._ATR_CAD = Double.NaN;
        }
    }

    private void KELTNER_block_38(Integer flow) {
        Instrument argument_1 = _USD_CAD;
        Period argument_2 = Period.ONE_MIN;
        int argument_3 = 2;
        int argument_4 = 61;
        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] = 61;
        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,
                    "KELTNER", appliedPrice, params, Filter.WEEKENDS, 1, time, 0);
            if ((new Double(((double [])indicatorResult[0])[0])) == null) {
                this._upperBand_cad = Double.NaN;
            } else { 
                this._upperBand_cad = (((double [])indicatorResult[0])[0]);
            } 
            if ((new Double(((double [])indicatorResult[1])[0])) == null) {
                this._middleBand38 = Double.NaN;
            } else { 
                this._middleBand38 = (((double [])indicatorResult[1])[0]);
            } 
            if ((new Double(((double [])indicatorResult[2])[0])) == null) {
                this._lowerBand_cad = Double.NaN;
            } else { 
                this._lowerBand_cad = (((double [])indicatorResult[2])[0]);
            } 
        Calculation_block_45(flow);
        } catch (JFException e) {
            e.printStackTrace();
            console.getErr().println(e);
            this._upperBand_cad = Double.NaN;
            this._middleBand38 = Double.NaN;
            this._lowerBand_cad = Double.NaN;
        }
    }

    private void ATR_block_39(Integer flow) {
        Instrument argument_1 = _GBP_JPY;
        Period argument_2 = Period.ONE_MIN;
        int argument_3 = 2;
        int argument_4 = 61;
        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] = 61;
        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,
                    "ATR", appliedPrice, params, Filter.WEEKENDS, 1, time, 0);
            if ((new Double(((double [])indicatorResult[0])[0])) == null) {
                this._ATR_GBP_JPY = Double.NaN;
            } else { 
                this._ATR_GBP_JPY = (((double [])indicatorResult[0])[0]);
            } 
        KELTNER_block_40(flow);
        } catch (JFException e) {
            e.printStackTrace();
            console.getErr().println(e);
            this._ATR_GBP_JPY = Double.NaN;
        }
    }

    private void KELTNER_block_40(Integer flow) {
        Instrument argument_1 = _GBP_JPY;
        Period argument_2 = Period.ONE_MIN;
        int argument_3 = 2;
        int argument_4 = 61;
        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] = 61;
        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,
                    "KELTNER", appliedPrice, params, Filter.WEEKENDS, 1, time, 0);
            if ((new Double(((double [])indicatorResult[0])[0])) == null) {
                this._upperBand_gbp_jpy = Double.NaN;
            } else { 
                this._upperBand_gbp_jpy = (((double [])indicatorResult[0])[0]);
            } 
            if ((new Double(((double [])indicatorResult[1])[0])) == null) {
                this._middleBand40 = Double.NaN;
            } else { 
                this._middleBand40 = (((double [])indicatorResult[1])[0]);
            } 
            if ((new Double(((double [])indicatorResult[2])[0])) == null) {
                this._lowerBand_gbp_jpy = Double.NaN;
            } else { 
                this._lowerBand_gbp_jpy = (((double [])indicatorResult[2])[0]);
            } 
        Calculation_block_42(flow);
        } catch (JFException e) {
            e.printStackTrace();
            console.getErr().println(e);
            this._upperBand_gbp_jpy = Double.NaN;
            this._middleBand40 = Double.NaN;
            this._lowerBand_gbp_jpy = Double.NaN;
        }
    }

    private void Calculation_block_41(Integer flow) {
        double argument_1 = _ATR_EUR_JPY;
        double argument_2 = 7.0;
        _ATR_EUR_JPY_MUL = argument_1 * argument_2;
        Calculation_block_54(flow);
    }

    private void Calculation_block_42(Integer flow) {
        double argument_1 = _ATR_GBP_JPY;
        double argument_2 = 7.0;
        _ATR_GBP_JPY_MUL = argument_1 * argument_2;
        Calculation_block_52(flow);
    }

    private void Calculation_block_43(Integer flow) {
        double argument_1 = _ATR_GBP_USD;
        double argument_2 = 7.0;
        _ATR_GBP_MUL = argument_1 * argument_2;
        Calculation_block_50(flow);
    }

    private void Calculation_block_44(Integer flow) {
        double argument_1 = _ATR_EUR;
        double argument_2 = 7.0;
        _ATR_EUR_MUL = argument_1 * argument_2;
        Calculation_block_48(flow);
    }

    private void Calculation_block_45(Integer flow) {
        double argument_1 = _ATR_CAD;
        double argument_2 = 7.0;
        _ATR_CAD_MUL = argument_1 * argument_2;
        Calculation_block_46(flow);
    }

    private void Calculation_block_46(Integer flow) {
        double argument_1 = _upperBand_cad;
        double argument_2 = _ATR_CAD_MUL;
        _Sell_Cad = argument_1 + argument_2;
        Calculation_block_47(flow);
    }

    private void Calculation_block_47(Integer flow) {
        double argument_1 = _lowerBand_cad;
        double argument_2 = _ATR_CAD_MUL;
        _Buy_Cad = argument_1 - argument_2;
        If_block_77(flow);
    }

    private void Calculation_block_48(Integer flow) {
        double argument_1 = _upperBand_eur_usd;
        double argument_2 = _ATR_EUR_MUL;
        _Sell_Eur = argument_1 + argument_2;
        Calculation_block_49(flow);
    }

    private void Calculation_block_49(Integer flow) {
        double argument_1 = _lowerBand_eur_usd;
        double argument_2 = _ATR_EUR_MUL;
        _Buy_Eur = argument_1 - argument_2;
        If_block_76(flow);
    }

    private void Calculation_block_50(Integer flow) {
        double argument_1 = _upperBand_gbp_usd;
        double argument_2 = _ATR_GBP_MUL;
        _Sell_GBP = argument_1 + argument_2;
        Calculation_block_51(flow);
    }

    private void Calculation_block_51(Integer flow) {
        double argument_1 = _lowerBand_gbp_usd;
        double argument_2 = _ATR_GBP_MUL;
        _Buy_GBP = argument_1 - argument_2;
        If_block_78(flow);
    }

    private void Calculation_block_52(Integer flow) {
        double argument_1 = _upperBand_gbp_jpy;
        double argument_2 = _ATR_GBP_JPY_MUL;
        _Sell_GBP_JPY = argument_1 + argument_2;
        Calculation_block_53(flow);
    }

    private void Calculation_block_53(Integer flow) {
        double argument_1 = _lowerBand_gbp_jpy;
        double argument_2 = _ATR_GBP_JPY_MUL;
        _Buy_GBP_JPY = argument_1 * argument_2;
        If_block_79(flow);
    }

    private void Calculation_block_54(Integer flow) {
        double argument_1 = _upperBand_eur_jpy;
        double argument_2 = _ATR_EUR_JPY_MUL;
        _Sell_Eur_Jpy = argument_1 + argument_2;
        Calculation_block_55(flow);
    }

    private void Calculation_block_55(Integer flow) {
        double argument_1 = _lowerBand_eur_jpy;
        double argument_2 = _ATR_EUR_JPY_MUL;
        _Buy_Eur_JPY = argument_1 - argument_2;
        If_block_80(flow);
    }

    private  void If_block_56(Integer flow) {
        double argument_1 = _Eur_JPY_Candle.getHigh();
        double argument_2 = _Sell_Eur_Jpy;
        if (argument_1< argument_2) {
            If_block_57(flow);
        }
        else if (argument_1> argument_2) {
            If_block_81(flow);
        }
        else if (argument_1== argument_2) {
            If_block_81(flow);
        }
    }

    private  void If_block_57(Integer flow) {
        double argument_1 = _Eur_JPY_Candle.getLow();
        double argument_2 = _Buy_Eur_JPY;
        if (argument_1< argument_2) {
            If_block_82(flow);
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
            If_block_82(flow);
        }
    }

    private  void OpenatMarket_block_58(Integer flow) {
        Instrument argument_1 = _EUR_JPY;
        double argument_2 = defaultTradeAmount;
        int argument_3 = defaultSlippage;
        int argument_4 = defaultStopLoss;
        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();           
               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 = _EUR_JPY;
        double argument_2 = defaultTradeAmount;
        int argument_3 = defaultSlippage;
        int argument_4 = defaultStopLoss;
        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 = _GBP_JPY_CANDLE.getHigh();
        double argument_2 = _Sell_GBP_JPY;
        if (argument_1< argument_2) {
            If_block_61(flow);
        }
        else if (argument_1> argument_2) {
            If_block_83(flow);
        }
        else if (argument_1== argument_2) {
            If_block_83(flow);
        }
    }

    private  void If_block_61(Integer flow) {
        double argument_1 = _GBP_JPY_CANDLE.getLow();
        double argument_2 = _Buy_GBP_JPY;
        if (argument_1< argument_2) {
            If_block_84(flow);
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
            If_block_84(flow);
        }
    }

    private  void OpenatMarket_block_62(Integer flow) {
        Instrument argument_1 = _GBP_JPY;
        double argument_2 = defaultTradeAmount;
        int argument_3 = defaultSlippage;
        int argument_4 = defaultStopLoss;
        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();           
               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_63(Integer flow) {
        Instrument argument_1 = _GBP_JPY;
        double argument_2 = defaultTradeAmount;
        int argument_3 = defaultSlippage;
        int argument_4 = defaultStopLoss;
        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_64(Integer flow) {
        double argument_1 = _GBP_CANDLE.getHigh();
        double argument_2 = _Sell_GBP;
        if (argument_1< argument_2) {
            If_block_65(flow);
        }
        else if (argument_1> argument_2) {
            If_block_85(flow);
        }
        else if (argument_1== argument_2) {
            If_block_85(flow);
        }
    }

    private  void If_block_65(Integer flow) {
        double argument_1 = _GBP_CANDLE.getLow();
        double argument_2 = _Buy_GBP;
        if (argument_1< argument_2) {
            If_block_86(flow);
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
            If_block_86(flow);
        }
    }

    private  void OpenatMarket_block_66(Integer flow) {
        Instrument argument_1 = _GBP_USD;
        double argument_2 = defaultTradeAmount;
        int argument_3 = defaultSlippage;
        int argument_4 = defaultStopLoss;
        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();           
               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_67(Integer flow) {
        Instrument argument_1 = _GBP_USD;
        double argument_2 = defaultTradeAmount;
        int argument_3 = defaultSlippage;
        int argument_4 = defaultStopLoss;
        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_68(Integer flow) {
        double argument_1 = _EUR_CANDLE.getHigh();
        double argument_2 = _Sell_Eur;
        if (argument_1< argument_2) {
            If_block_69(flow);
        }
        else if (argument_1> argument_2) {
            If_block_87(flow);
        }
        else if (argument_1== argument_2) {
            If_block_87(flow);
        }
    }

    private  void If_block_69(Integer flow) {
        double argument_1 = _EUR_CANDLE.getLow();
        double argument_2 = _Buy_Eur;
        if (argument_1< argument_2) {
            If_block_88(flow);
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
            If_block_88(flow);
        }
    }

    private  void OpenatMarket_block_70(Integer flow) {
        Instrument argument_1 = _EUR_USD;
        double argument_2 = defaultTradeAmount;
        int argument_3 = defaultSlippage;
        int argument_4 = defaultStopLoss;
        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();           
               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_71(Integer flow) {
        Instrument argument_1 = _EUR_USD;
        double argument_2 = defaultTradeAmount;
        int argument_3 = defaultSlippage;
        int argument_4 = defaultStopLoss;
        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_72(Integer flow) {
        double argument_1 = _CAD_CANDLE.getHigh();
        double argument_2 = _Sell_Cad;
        if (argument_1< argument_2) {
            If_block_74(flow);
        }
        else if (argument_1> argument_2) {
            If_block_89(flow);
        }
        else if (argument_1== argument_2) {
            If_block_89(flow);
        }
    }

    private  void OpenatMarket_block_73(Integer flow) {
        Instrument argument_1 = _USD_CAD;
        double argument_2 = defaultTradeAmount;
        int argument_3 = defaultSlippage;
        int argument_4 = defaultStopLoss;
        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();           
               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_74(Integer flow) {
        double argument_1 = _CAD_CANDLE.getLow();
        double argument_2 = _Buy_Cad;
        if (argument_1< argument_2) {
            If_block_90(flow);
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
            If_block_90(flow);
        }
    }

    private  void OpenatMarket_block_75(Integer flow) {
        Instrument argument_1 = _USD_CAD;
        double argument_2 = defaultTradeAmount;
        int argument_3 = defaultSlippage;
        int argument_4 = defaultStopLoss;
        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_76(Integer flow) {
        int argument_1 = OpenPositions.size();
        int argument_2 = 0;
        if (argument_1< argument_2) {
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
            If_block_68(flow);
        }
    }

    private  void If_block_77(Integer flow) {
        int argument_1 = OpenPositions.size();
        int argument_2 = 0;
        if (argument_1< argument_2) {
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
            If_block_72(flow);
        }
    }

    private  void If_block_78(Integer flow) {
        int argument_1 = OpenPositions.size();
        int argument_2 = 0;
        if (argument_1< argument_2) {
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
            If_block_64(flow);
        }
    }

    private  void If_block_79(Integer flow) {
        int argument_1 = OpenPositions.size();
        int argument_2 = 0;
        if (argument_1< argument_2) {
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
            If_block_60(flow);
        }
    }

    private  void If_block_80(Integer flow) {
        int argument_1 = OpenPositions.size();
        int argument_2 = 0;
        if (argument_1< argument_2) {
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
            If_block_56(flow);
        }
    }

    private  void If_block_81(Integer flow) {
        double argument_1 = _Eur_JPY_Candle.getClose();
        double argument_2 = _Sell_Eur_Jpy;
        if (argument_1< argument_2) {
            OpenatMarket_block_58(flow);
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
        }
    }

    private  void If_block_82(Integer flow) {
        double argument_1 = _Eur_JPY_Candle.getClose();
        double argument_2 = _Buy_Eur_JPY;
        if (argument_1< argument_2) {
        }
        else if (argument_1> argument_2) {
            OpenatMarket_block_59(flow);
        }
        else if (argument_1== argument_2) {
        }
    }

    private  void If_block_83(Integer flow) {
        double argument_1 = _GBP_JPY_CANDLE.getClose();
        double argument_2 = _Sell_GBP_JPY;
        if (argument_1< argument_2) {
            OpenatMarket_block_62(flow);
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
        }
    }

    private  void If_block_84(Integer flow) {
        double argument_1 = _GBP_JPY_CANDLE.getClose();
        double argument_2 = _Buy_GBP_JPY;
        if (argument_1< argument_2) {
        }
        else if (argument_1> argument_2) {
            OpenatMarket_block_63(flow);
        }
        else if (argument_1== argument_2) {
        }
    }

    private  void If_block_85(Integer flow) {
        double argument_1 = _GBP_CANDLE.getClose();
        double argument_2 = _Sell_GBP;
        if (argument_1< argument_2) {
            OpenatMarket_block_66(flow);
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
        }
    }

    private  void If_block_86(Integer flow) {
        double argument_1 = _GBP_CANDLE.getClose();
        double argument_2 = _Buy_GBP;
        if (argument_1< argument_2) {
        }
        else if (argument_1> argument_2) {
            OpenatMarket_block_67(flow);
        }
        else if (argument_1== argument_2) {
        }
    }

    private  void If_block_87(Integer flow) {
        double argument_1 = _EUR_CANDLE.getClose();
        double argument_2 = _Sell_Eur;
        if (argument_1< argument_2) {
            OpenatMarket_block_70(flow);
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
        }
    }

    private  void If_block_88(Integer flow) {
        double argument_1 = _EUR_CANDLE.getClose();
        double argument_2 = _Buy_Eur;
        if (argument_1< argument_2) {
        }
        else if (argument_1> argument_2) {
            OpenatMarket_block_71(flow);
        }
        else if (argument_1== argument_2) {
        }
    }

    private  void If_block_89(Integer flow) {
        double argument_1 = _CAD_CANDLE.getClose();
        double argument_2 = _Sell_Cad;
        if (argument_1< argument_2) {
            OpenatMarket_block_73(flow);
        }
        else if (argument_1> argument_2) {
        }
        else if (argument_1== argument_2) {
        }
    }

    private  void If_block_90(Integer flow) {
        double argument_1 = _CAD_CANDLE.getClose();
        double argument_2 = _Buy_Cad;
        if (argument_1< argument_2) {
        }
        else if (argument_1> argument_2) {
            OpenatMarket_block_75(flow);
        }
        else if (argument_1== argument_2) {
        }
    }

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;
        }
    }
}