checkTrigger method

bool checkTrigger(
  1. double currentPrice,
  2. double previousPrice
)

Evaluates whether the current price update satisfies this alert's trigger condition.

Implementation

bool checkTrigger(double currentPrice, double previousPrice) {
  if (!isActive || isTriggered) return false;

  switch (condition) {
    case AlertTriggerCondition.crossingUp:
      return previousPrice < price && currentPrice >= price;
    case AlertTriggerCondition.crossingDown:
      return previousPrice > price && currentPrice <= price;
    case AlertTriggerCondition.crossing:
      return (previousPrice - price) * (currentPrice - price) <= 0 &&
          previousPrice != currentPrice;
  }
}