Exemple #1
0
 public List<Level> levels() {
   List<Level> ret = new ArrayList<Level>(levels);
   for (Bar child : children) {
     ret.addAll(child.levels());
   }
   return ret;
 }
Exemple #2
0
  protected void groupSameDirectionBars(int fullTicksSize) {
    if (childrenFormZigZag()) {
      return;
    }
    List<Bar> bars;
    bars = new LinkedList<Bar>(children);
    children.clear();
    int dir = 0;
    List<PriceTick> currentBarsGroup = new LinkedList<PriceTick>();
    Bar currentBar = null;
    for (int i = 0; i < bars.size(); i++) {
      currentBar = bars.get(i);

      if (dir == 0) {
        currentBarsGroup.add(currentBar);
        dir = currentBar.direction();
        if (i == bars.size() - 1) {
          addChildren(currentBarsGroup, fullTicksSize);
        }
      } else {
        if (currentBar.direction() == 0 || currentBar.direction() == dir) {
          currentBarsGroup.add(currentBar);
          if (i == bars.size() - 1) {
            addChildren(currentBarsGroup, fullTicksSize);
          }
        } else {
          addChildren(currentBarsGroup, fullTicksSize);
          currentBarsGroup.clear();
          dir = currentBar.direction();
          // currentBarsGroup.add(currentBar);
          i--;
        }
      }
    }
  }
Exemple #3
0
  public Bar(List<PriceTick> ticks) {
    super((PriceTick) getEarliestBarFromCollection(convertTicksToBars(ticks)));
    int fullTicksSize = ticks.size();
    List<Bar> bars = convertTicksToBars(ticks);

    if (bars.size() > 1) {
      for (int i = 0; i < bars.size(); i++) {
        Bar bar = bars.get(i);
        if (bar.isTick()) {
          if (i < bars.size() - 1) {
            children.add(new Bar(bar, bars.get(i + 1)));
          }
        } else {
          children.add(bar);
        }
      }
      boolean negativeDetected = false;
      boolean positiveDetected = false;
      boolean opposingDetected = negativeDetected && positiveDetected;
      // boolean hasZeroes = false;
      while (!(children.size() <= 2 || childrenFormZigZag() || childrenConsolidatedByDirection())) {
        // hasZeroes = false;
        groupSameDirectionBars(fullTicksSize);

        for (Bar bar : children) {
          if (bar.direction() == 1) {
            positiveDetected = true;
          } else if (bar.direction() == -1) {
            negativeDetected = true;
          }
        }
        opposingDetected = negativeDetected && positiveDetected;

        if (children.size() > 3 && opposingDetected) {
          groupZigZags();
        }

        // grouped = true;
      }
    } else {
      isTick = true;
    }
    if (children.size() == 1) {
      Bar childBar = children.get(0);
      children.clear();
      children = new ArrayList<Bar>(childBar.children);
    }
    if (children.size() > 0) {
      startBar = children.get(0);
      endBar = children.get(children.size() - 1);
    }
    calculateDirection();

    if (!isTick() && direction() != 0 && openBid() != 0 && closeBid() != 0) {
      levels.add(new Level(closeBid(), duration(), direction(), closingTime()));
    }
    // printChildren();
  }
Exemple #4
0
 public List<Bar> atomicDeltas(long maxTime) {
   List<Bar> ret = new LinkedList<Bar>();
   if (isAtomicDelta() && closingTime() <= maxTime) {
     ret.add(this);
     return ret;
   }
   for (Bar child : children) {
     ret.addAll(child.atomicDeltas(maxTime));
   }
   return ret;
 }
Exemple #5
0
 public boolean levelNeutralizedByMovement(Level level, List<Bar> barsToCheck) {
   double minPrice = 0;
   double maxPrice = 0;
   for (Bar bar : barsToCheck) {
     if (bar.openTime() > level.timeAppeared()
     // || (bar.openTime() == level.timeAppeared() && closeBid() == level.price())
     ) {
       minPrice = Math.min(bar.openBid(), bar.closeBid());
       maxPrice = Math.max(bar.openBid(), bar.closeBid());
       if (level.price() >= minPrice && level.price() <= maxPrice) {
         return true;
       }
       if (level.direction == 1 && minPrice > level.price()) {
         return true;
       }
       if (level.direction == -1 && maxPrice < level.price()) {
         return true;
       }
     }
   }
   return false;
 }
Exemple #6
0
 protected boolean childrenConsolidatedByDirection() {
   int negativeFound = 0;
   // int neutralFound = 0;
   int positiveFound = 0;
   for (Bar bar : children) {
     if (bar.direction() == -1) {
       negativeFound++;
     } else if (bar.direction() == 0) {
       // neutralFound++;
     } else if (bar.direction() == 1) {
       positiveFound++;
     }
   }
   if (negativeFound > 0 && positiveFound == 0) {
     return true;
   }
   if (negativeFound == 0 && positiveFound > 0) {
     return true;
   } else if (negativeFound == 0 && positiveFound == 0) {
     return true;
   }
   return false;
 }
Exemple #7
0
 public long closingTime() {
   if (endBar != null) {
     return endBar.closingTime();
   }
   return time;
 }
Exemple #8
0
 public long openTime() {
   if (startBar != null) {
     return startBar.openTime();
   }
   return time;
 }
Exemple #9
0
 public double closeBid() {
   if (endBar != null) {
     return endBar.closeBid();
   }
   return bid;
 }
Exemple #10
0
 public double openBid() {
   if (startBar != null) {
     return startBar.openBid();
   }
   return bid;
 }
Exemple #11
0
 public void printChildren() {
   System.out.print(toString());
   for (Bar bar : children) {
     System.out.print(bar.toString());
   }
 }