Class CrossDetector

java.lang.Object
com.wualabs.qtsurfer.engine.strategy.CrossDetector

public final class CrossDetector extends Object
Tracks whether left is above or below right across calls and reports the transition, if any, on check(double, double). One instance per pair being watched — declare it as a field and call it once per tick:
private final CrossDetector fastSlowCross = new CrossDetector();
...
CrossDetector.Cross cross = fastSlowCross.check(fast, slow);
if (cross.above()) emitBuy(price);
if (cross.below()) emitSell(price);

Both directions come from a single call so they always describe the same tick. The shape this replaces — detectCrossAbove/detectCrossBelow sharing one Boolean[] state, int index — let the first of two calls overwrite the value the second one needed to compare against, silently breaking whichever direction ran second; that can't happen here because check(double, double) only mutates once.

  • Constructor Details

    • CrossDetector

      public CrossDetector()
  • Method Details

    • check

      public CrossDetector.Cross check(double left, double right)
      Parameters:
      left - the left-hand value
      right - the right-hand value
      Returns:
      the transition since the last call; both flags false on the first call, since there is no prior value to compare against