#include "../misc_framework/CsvFileDataNodes.h" #include "RecentHighsAndLows.h" void RecentHighsAndLows::onWakeup(int msgId) { _previouslyValid = _tosValid; _tosValid = _tosData->getValid(); const double newValue = currentInput(); if ((newValue != 0.0) && (newValue != _lastValue)) { _lastValue = newValue; notifyListeners(); } } double RecentHighsAndLows::currentInput() { if (!_tosData->getValid()) return 0.0; if (_high) return _tosData->getLast().high; return _tosData->getLast().low; } RecentHighsAndLows::RecentHighsAndLows(DataNodeArgument const &args) : _tosValid(false), _previouslyValid(false) { DataNodeArgumentVector const &argList = args.getListValue(); // high, symbol assert(argList.size() == 2); _high = argList[0].getBooleanValue(); const std::string &symbol = argList[1].getStringValue(); addAutoLink(GenericTosDataNode::find(this, 0, _tosData, symbol)); _lastValue = strtodDefault(FileOwnerDataNode::getStringValue ("TC_OvernightData.csv", (_high?"Previous High":"Previous Low"), symbol), 0); onWakeup(0); } double RecentHighsAndLows::getCurrentValue() { // Always try to use the most current value. // If the caller is listening to multiple // data nodes, he may call this right before // we do any update. For example, the // initialization code for the new high/low // bid/ask could see the first bid/ask before // this data node gets the first high/low, and // the new high/low bid/ask code can never // recover from that. const double result = currentInput(); if (result <= 0) return _lastValue; return result; } DataNodeLink *RecentHighsAndLows::find(DataNodeListener *listener, int msgId, RecentHighsAndLows *&node, bool high, std::string const &symbol) { return findHelper(listener, msgId, node, argList(high, symbol)); }