@Test public void test() throws InterruptedException { TradingBotOnMovingBarSeries.main(null); }
public static void main(String[] args) throws InterruptedException { System.out.println("********************** Initialization **********************"); BarSeries series = initMovingBarSeries(20); Strategy strategy = buildStrategy(series); TradingRecord tradingRecord = new BaseTradingRecord(); System.out.println("************************************************************"); for (int i = 0; i < 50; i++) { Thread.sleep(30); Bar newBar = generateRandomBar(); System.out.println("------------------------------------------------------\n" + "Bar " + i + " added, close price = " + newBar.getClosePrice().doubleValue()); series.addBar(newBar); int endIndex = series.getEndIndex(); if (strategy.shouldEnter(endIndex)) { System.out.println("Strategy should ENTER on " + endIndex); boolean entered = tradingRecord.enter(endIndex, newBar.getClosePrice(), PrecisionNum.valueOf(10)); if (entered) { Order entry = tradingRecord.getLastEntry(); System.out.println("Entered on " + entry.getIndex() + " (price=" + entry.getNetPrice().doubleValue() + ", amount=" + entry.getAmount().doubleValue() + ")"); } } else if (strategy.shouldExit(endIndex)) { System.out.println("Strategy should EXIT on " + endIndex); boolean exited = tradingRecord.exit(endIndex, newBar.getClosePrice(), PrecisionNum.valueOf(10)); if (exited) { Order exit = tradingRecord.getLastExit(); System.out.println("Exited on " + exit.getIndex() + " (price=" + exit.getNetPrice().doubleValue() + ", amount=" + exit.getAmount().doubleValue() + ")"); } } } }
TradingBotOnMovingBarSeries { public static void main(String[] args) throws InterruptedException { System.out.println("********************** Initialization **********************"); BarSeries series = initMovingBarSeries(20); Strategy strategy = buildStrategy(series); TradingRecord tradingRecord = new BaseTradingRecord(); System.out.println("************************************************************"); for (int i = 0; i < 50; i++) { Thread.sleep(30); Bar newBar = generateRandomBar(); System.out.println("------------------------------------------------------\n" + "Bar " + i + " added, close price = " + newBar.getClosePrice().doubleValue()); series.addBar(newBar); int endIndex = series.getEndIndex(); if (strategy.shouldEnter(endIndex)) { System.out.println("Strategy should ENTER on " + endIndex); boolean entered = tradingRecord.enter(endIndex, newBar.getClosePrice(), PrecisionNum.valueOf(10)); if (entered) { Order entry = tradingRecord.getLastEntry(); System.out.println("Entered on " + entry.getIndex() + " (price=" + entry.getNetPrice().doubleValue() + ", amount=" + entry.getAmount().doubleValue() + ")"); } } else if (strategy.shouldExit(endIndex)) { System.out.println("Strategy should EXIT on " + endIndex); boolean exited = tradingRecord.exit(endIndex, newBar.getClosePrice(), PrecisionNum.valueOf(10)); if (exited) { Order exit = tradingRecord.getLastExit(); System.out.println("Exited on " + exit.getIndex() + " (price=" + exit.getNetPrice().doubleValue() + ", amount=" + exit.getAmount().doubleValue() + ")"); } } } } }
TradingBotOnMovingBarSeries { public static void main(String[] args) throws InterruptedException { System.out.println("********************** Initialization **********************"); BarSeries series = initMovingBarSeries(20); Strategy strategy = buildStrategy(series); TradingRecord tradingRecord = new BaseTradingRecord(); System.out.println("************************************************************"); for (int i = 0; i < 50; i++) { Thread.sleep(30); Bar newBar = generateRandomBar(); System.out.println("------------------------------------------------------\n" + "Bar " + i + " added, close price = " + newBar.getClosePrice().doubleValue()); series.addBar(newBar); int endIndex = series.getEndIndex(); if (strategy.shouldEnter(endIndex)) { System.out.println("Strategy should ENTER on " + endIndex); boolean entered = tradingRecord.enter(endIndex, newBar.getClosePrice(), PrecisionNum.valueOf(10)); if (entered) { Order entry = tradingRecord.getLastEntry(); System.out.println("Entered on " + entry.getIndex() + " (price=" + entry.getNetPrice().doubleValue() + ", amount=" + entry.getAmount().doubleValue() + ")"); } } else if (strategy.shouldExit(endIndex)) { System.out.println("Strategy should EXIT on " + endIndex); boolean exited = tradingRecord.exit(endIndex, newBar.getClosePrice(), PrecisionNum.valueOf(10)); if (exited) { Order exit = tradingRecord.getLastExit(); System.out.println("Exited on " + exit.getIndex() + " (price=" + exit.getNetPrice().doubleValue() + ", amount=" + exit.getAmount().doubleValue() + ")"); } } } }  }
TradingBotOnMovingBarSeries { public static void main(String[] args) throws InterruptedException { System.out.println("********************** Initialization **********************"); BarSeries series = initMovingBarSeries(20); Strategy strategy = buildStrategy(series); TradingRecord tradingRecord = new BaseTradingRecord(); System.out.println("************************************************************"); for (int i = 0; i < 50; i++) { Thread.sleep(30); Bar newBar = generateRandomBar(); System.out.println("------------------------------------------------------\n" + "Bar " + i + " added, close price = " + newBar.getClosePrice().doubleValue()); series.addBar(newBar); int endIndex = series.getEndIndex(); if (strategy.shouldEnter(endIndex)) { System.out.println("Strategy should ENTER on " + endIndex); boolean entered = tradingRecord.enter(endIndex, newBar.getClosePrice(), PrecisionNum.valueOf(10)); if (entered) { Order entry = tradingRecord.getLastEntry(); System.out.println("Entered on " + entry.getIndex() + " (price=" + entry.getNetPrice().doubleValue() + ", amount=" + entry.getAmount().doubleValue() + ")"); } } else if (strategy.shouldExit(endIndex)) { System.out.println("Strategy should EXIT on " + endIndex); boolean exited = tradingRecord.exit(endIndex, newBar.getClosePrice(), PrecisionNum.valueOf(10)); if (exited) { Order exit = tradingRecord.getLastExit(); System.out.println("Exited on " + exit.getIndex() + " (price=" + exit.getNetPrice().doubleValue() + ", amount=" + exit.getAmount().doubleValue() + ")"); } } } }  static void main(String[] args); }
TradingBotOnMovingBarSeries { public static void main(String[] args) throws InterruptedException { System.out.println("********************** Initialization **********************"); BarSeries series = initMovingBarSeries(20); Strategy strategy = buildStrategy(series); TradingRecord tradingRecord = new BaseTradingRecord(); System.out.println("************************************************************"); for (int i = 0; i < 50; i++) { Thread.sleep(30); Bar newBar = generateRandomBar(); System.out.println("------------------------------------------------------\n" + "Bar " + i + " added, close price = " + newBar.getClosePrice().doubleValue()); series.addBar(newBar); int endIndex = series.getEndIndex(); if (strategy.shouldEnter(endIndex)) { System.out.println("Strategy should ENTER on " + endIndex); boolean entered = tradingRecord.enter(endIndex, newBar.getClosePrice(), PrecisionNum.valueOf(10)); if (entered) { Order entry = tradingRecord.getLastEntry(); System.out.println("Entered on " + entry.getIndex() + " (price=" + entry.getNetPrice().doubleValue() + ", amount=" + entry.getAmount().doubleValue() + ")"); } } else if (strategy.shouldExit(endIndex)) { System.out.println("Strategy should EXIT on " + endIndex); boolean exited = tradingRecord.exit(endIndex, newBar.getClosePrice(), PrecisionNum.valueOf(10)); if (exited) { Order exit = tradingRecord.getLastExit(); System.out.println("Exited on " + exit.getIndex() + " (price=" + exit.getNetPrice().doubleValue() + ", amount=" + exit.getAmount().doubleValue() + ")"); } } } }  static void main(String[] args);  }