/**
  * Create a new Candle node to represent a single data item
  *
  * @param seriesIndex The index of the series the data item is in
  * @param item The data item to create node for
  * @param itemIndex The index of the data item in the series
  * @return New candle node to represent the give data item
  */
 private Node createCandle(int seriesIndex, final Data item, int itemIndex) {
   Node candle = item.getNode();
   // check if candle has already been created
   if (candle instanceof Candle) {
     ((Candle) candle).setSeriesAndDataStyleClasses("series" + seriesIndex, "data" + itemIndex);
   } else {
     candle = new Candle("series" + seriesIndex, "data" + itemIndex);
     item.setNode(candle);
   }
   return candle;
 }
  /** Called to update and layout the content for the plot */
  @Override
  protected void layoutPlotChildren() {
    // we have nothing to layout if no data is present
    if (getData() == null) {
      return;
    }
    // update candle positions
    for (int seriesIndex = 0; seriesIndex < getData().size(); seriesIndex++) {
      Series<String, Number> series = getData().get(seriesIndex);
      Iterator<Data<String, Number>> iter = getDisplayedDataIterator(series);
      Path seriesPath = null;
      if (series.getNode() instanceof Path) {
        seriesPath = (Path) series.getNode();
        seriesPath.getElements().clear();
      }
      while (iter.hasNext()) {
        Data<String, Number> item = iter.next();
        double x = getXAxis().getDisplayPosition(getCurrentDisplayedXValue(item));
        double y = getYAxis().getDisplayPosition(getCurrentDisplayedYValue(item));
        Node itemNode = item.getNode();
        BarData bar = (BarData) item.getExtraValue();
        if (itemNode instanceof Candle && item.getYValue() != null) {
          Candle candle = (Candle) itemNode;

          double close = getYAxis().getDisplayPosition(bar.getClose());
          double high = getYAxis().getDisplayPosition(bar.getHigh());
          double low = getYAxis().getDisplayPosition(bar.getLow());
          double candleWidth = 10;
          // update candle
          candle.update(close - y, high - y, low - y, candleWidth);

          // update tooltip content
          candle.updateTooltip(bar.getOpen(), bar.getClose(), bar.getHigh(), bar.getLow());

          // position the candle
          candle.setLayoutX(x);
          candle.setLayoutY(y);
        }
      }
    }
  }
예제 #3
0
 @Test
 public void testEquals() {
   Candle c1 = new Candle();
   Candle c2 = new Candle();
   long time = System.currentTimeMillis();
   Date date1 = new Date(time);
   Date date2 = new Date(time);
   c1.setDate(date1).setClose(10.0).setOpen(5.0).setHigh(15.0).setLow(2.0).setVolume(30);
   c2.setDate(date2).setClose(10.0).setOpen(5.0).setHigh(15.0).setLow(2.0).setVolume(30);
   assertTrue(c1.equals(c2));
   c1.setDate(new Date(time + 1));
   assertFalse(c1.equals(c2));
 }
예제 #4
0
 @Test
 public void testProcessTick() {
   candle.setDate(Utils.parseDate("01.09.2015 12:15:00.000"));
   candle.processTick(tick1);
   Arrays.asList(
           PriceType.OPEN,
           PriceType.LOW,
           PriceType.HIGH,
           PriceType.CLOSE,
           PriceType.WEIGHTED_CLOSE)
       .forEach(pt -> assertTrue(candle.getPriceValueByType(pt) == tick1.getPrice()));
   candle.processTick(tick2);
   assertEquals(candle.getPriceValueByType(PriceType.OPEN), tick1.getPrice());
   assertEquals(
       candle.getPriceValueByType(PriceType.HIGH), Math.max(tick1.getPrice(), tick2.getPrice()));
   assertEquals(
       candle.getPriceValueByType(PriceType.LOW), Math.min(tick1.getPrice(), tick2.getPrice()));
   assertEquals(candle.getPriceValueByType(PriceType.CLOSE), tick2.getPrice());
   candle.processTick(tick3);
   assertEquals(candle.getPriceValueByType(PriceType.WEIGHTED_CLOSE), 10.375, 0.001); //
   assertEquals(
       candle.getPriceValueByType(PriceType.VOLUME_WEIGHTED), 9.235294117647058, 0.001); //
 }
예제 #5
0
 @Override
 public double calculaPara(int posicao, SerieTemporal serie) {
   Candle candle = serie.get(posicao);
   return candle.getAbertura();
 }
예제 #6
0
 public void setArchitecture(String cpu) {
   Wix.Arch arch = (cpu == null || cpu.isEmpty()) ? Wix.Arch.x86 : Wix.Arch.valueOf(cpu);
   ((Candle) candle).setArch(arch);
 }