コード例 #1
0
  public void populateChartAnalysis(final PriceAnalysisData currentPrice) {
    if (currentPrice == null
        || currentPrice.getPrice() == null
        || currentPrice.getPrice().getDateType() != TradeDateType.TRADING_DATE
        || currentPrice.getPrice().getVolume() == null
        || currentPrice.getPrice().getVolume() == 0) {
      return;
    }

    if (currentPrice.getPrice().getPriceDate().after(cal.getTime())) {
      System.err.print("");
    }

    final BigDecimal atr = atrHelper.processTick(currentPrice.getPrice());

    if (prevPrice == null) {
      prevPrice = currentPrice;
      return;
    }

    try {
      if (currentPrice.getPrice().getLow().doubleValue()
          <= prevPrice.getPrice().getHigh().doubleValue()) {
        return;
      }

      double threshold = 0.01;
      if (atr != null) {
        threshold = atr.doubleValue();
      } else {
        threshold = atrHelper.getRollingATR();
      }

      PriceAnalysisElementData pae = null;
      if (currentPrice.getPrice().getLow().doubleValue()
          >= prevPrice.getPrice().getHigh().doubleValue() + threshold) {
        pae = new PriceAnalysisElementData();
        pae.setAnalysisType(ChartAnalysisType.GAP_UP);
        pae.setElementType(ChartElementType.PRICE);
      } else if (currentPrice.getPrice().getHigh().doubleValue()
          <= prevPrice.getPrice().getLow().doubleValue() - threshold) {
        pae = new PriceAnalysisElementData();
        pae.setAnalysisType(ChartAnalysisType.GAP_DOWN);
        pae.setElementType(ChartElementType.PRICE);
      }

      if (pae != null) {
        currentPrice.getPriceAnalysisElements().add(pae);
      }
    } finally {
      prevPrice = currentPrice;
    }
  }
コード例 #2
0
  public void populateChartAnalysis(final PriceAnalysisData currentPrice) {
    if (currentPrice == null
        || currentPrice.getPrice() == null
        || currentPrice.getPrice().getDateType() != TradeDateType.TRADING_DATE
        || currentPrice.getPrice().getVolume() == null
        || currentPrice.getPrice().getVolume() == 0) {
      return;
    }

    final boolean new52wkHigh = calendar365DaysHighHelper.processTick(currentPrice.getPrice());
    trading100DaysHighHelper.processTick(currentPrice.getPrice());

    ChartAnalysisType analysisType = null;
    if (new52wkHigh) {
      final InstrumentPriceModel previousHigh = calendar365DaysHighHelper.getPreviousHighTick();
      if (previousHigh != null
          && currentPrice.getPrice().getClose().doubleValue()
              >= previousHigh.getHigh().doubleValue()) {
        analysisType = ChartAnalysisType.NEW_HIGHS;
        final PriceAnalysisElementData analysis = new PriceAnalysisElementData();
        analysis.setElementType(ChartElementType.PRICE);
        analysis.setAnalysisType(analysisType);
        currentPrice.getPriceAnalysisElements().add(analysis);
      }
    }

    // add recent-high logic ONLY if 52-wk high is not added
    if (analysisType == null) {
      if (trading100DaysHighHelper.getHighTick() != null
          && currentPrice.getPrice() == trading100DaysHighHelper.getHighTick()) {
        final InstrumentPriceModel previousHigh = calendar365DaysHighHelper.getPreviousHighTick();
        if (previousHigh != null
            && currentPrice.getPrice().getClose().doubleValue()
                >= previousHigh.getHigh().doubleValue()) {
          analysisType = ChartAnalysisType.NEW_RECENT_HIGHS;
          final PriceAnalysisElementData analysis = new PriceAnalysisElementData();
          analysis.setElementType(ChartElementType.PRICE);
          analysis.setAnalysisType(analysisType);

          currentPrice.getPriceAnalysisElements().add(analysis);
        }
      }
    }
  }
コード例 #3
0
  public void populateChartAnalysis(final PriceAnalysisData currentPrice) {
    if (currentPrice == null
        || currentPrice.getPrice() == null
        || currentPrice.getPrice().getDateType() != TradeDateType.TRADING_DATE
        || currentPrice.getPrice().getVolume() == null
        || currentPrice.getPrice().getVolume() <= 0) {
      return;
    }

    if (previousPrice == null) {
      previousPrice = currentPrice;
      return;
    }

    final BigDecimal currentMA = getMA(currentPrice);
    final BigDecimal previousMA = getMA(previousPrice);
    if (currentMA == null || previousMA == null) {
      previousPrice = currentPrice;
      return;
    }

    final double chgPct =
        100
            * (currentPrice.getPrice().getClose().doubleValue()
                - previousPrice.getPrice().getClose().doubleValue())
            / previousPrice.getPrice().getClose().doubleValue();

    ChartAnalysisType currentTickAnalysisType = null;

    // first check if the tick is breaking-up or down .. we only check this condition if the
    // previous tick is at support
    if (previousTickAnalysisType == ChartAnalysisType.SUPPORT
        || previousTickAnalysisType == ChartAnalysisType.RESISTANCE) {
      if (isPriceBelowResistanceThreshold(currentPrice.getPrice(), currentMA)) {
        if (chgPct >= 0) {
          currentTickAnalysisType = ChartAnalysisType.RESISTANCE;
        } else {
          currentTickAnalysisType = ChartAnalysisType.BREAKING_DOWN;
        }
      } else if (isPriceAboveSupportThreshold(currentPrice.getPrice(), currentMA)) {
        if (chgPct <= 0) {
          currentTickAnalysisType = ChartAnalysisType.SUPPORT;
        } else {
          currentTickAnalysisType = ChartAnalysisType.BREAKING_UP;
        }
      }
    } else if (isPriceAtSupport(currentPrice.getPrice(), currentMA)) {
      if (isPriceBelowResistanceThreshold(currentPrice.getPrice(), currentMA)) {
        if (chgPct >= 0) {
          currentTickAnalysisType = ChartAnalysisType.RESISTANCE;
        } else {
          currentTickAnalysisType = ChartAnalysisType.BREAKING_DOWN;
        }
      } else if (isPriceAboveSupportThreshold(currentPrice.getPrice(), currentMA)) {
        if (chgPct <= 0) {
          currentTickAnalysisType = ChartAnalysisType.SUPPORT;
        } else {
          currentTickAnalysisType = ChartAnalysisType.BREAKING_UP;
        }
      }
    }

    if (currentTickAnalysisType == null) {
      if (previousMA.doubleValue() >= currentMA.doubleValue()) {
        // trending-down.. we only check for resistance and breaking-down

        // we only check resistance if it is not breaking-down
        if (currentTickAnalysisType == null) {
          boolean flag = isPriceAtResistance(currentPrice.getPrice(), currentMA);
          if (flag) {
            currentTickAnalysisType = ChartAnalysisType.RESISTANCE;
          }
        }
      } else {
        // trending-up.. we only check for support
        boolean flag = isPriceAtSupport(currentPrice.getPrice(), currentMA);
        if (flag) {
          currentTickAnalysisType = ChartAnalysisType.SUPPORT;
        }
      }
    }

    if (currentTickAnalysisType == null) {
      if (previousPrice.getPrice().getClose().doubleValue() > previousMA.doubleValue()
          && currentPrice.getPrice().getClose().doubleValue() < currentMA.doubleValue()) {
        currentTickAnalysisType = ChartAnalysisType.BREAKING_DOWN;
      } else if (previousPrice.getPrice().getClose().doubleValue() < previousMA.doubleValue()
          && currentPrice.getPrice().getClose().doubleValue() > currentMA.doubleValue()) {
        currentTickAnalysisType = ChartAnalysisType.BREAKING_UP;
      }
    }

    if (currentTickAnalysisType != null) {
      final PriceAnalysisElementData analysis = new PriceAnalysisElementData();
      analysis.setElementType(geChartElementType());
      analysis.setAnalysisType(currentTickAnalysisType);

      currentPrice.getPriceAnalysisElements().add(analysis);
    }

    previousTickAnalysisType = currentTickAnalysisType;
    previousPrice = currentPrice;
  }