#ifndef __TradeDirection_h_ #define __TradeDirection_h_ #include // Ideally this would be used by almost every alert definition. Instead, // a lot of this is copied in various places. That's because of the // history of the alerts. I had this idea a long time ago, but it was // hard to implement in Delphi. PDS class TradeDirection { private: bool _long; public: TradeDirection() : _long(false) {} TradeDirection(bool isLong) : _long(isLong) {} bool moreReportable(double a, double b) const; double mostReportable(double a, double b) const; double leastReportable(double a, double b) const; double leastReportable() const; double mostReportable() const { return -leastReportable(); } bool isLong() const { return _long; } bool isShort() const { return !_long; } int direction() const { return _long?1:-1; } bool upByAtLeast(double value, double min) const; bool downByAtLeast(double value, double min) const { return upByAtLeast(-value, min); } bool operator ==(TradeDirection const &other) const { return _long == other._long; } operator std::string() const { return _long?"long":"short"; } }; inline bool TradeDirection::upByAtLeast(double value, double min) const { if (_long) return value >= min; else return value <= -min; } inline bool TradeDirection::moreReportable(double a, double b) const { if (_long) return a > b; else return a < b; } inline double TradeDirection::mostReportable(double a, double b) const { if (_long) return std::max(a, b); else return std::min(a,b); } inline double TradeDirection::leastReportable(double a, double b) const { if (_long) return std::min(a,b); else return std::max(a, b); } inline double TradeDirection::leastReportable() const { if (_long) return -std::numeric_limits< double >::max(); else return std::numeric_limits< double >::max(); } #endif