#ifndef __CurrentCandles_h_ #define __CurrentCandles_h_ /* This is generally similar to StandardCandles, except that it includes the * current candle in progress. Like StandardCandles it only updates during * market hours. Like StandardCandles, it is safe to call this at any time. * This class will automatically update its state as soon as you ask for data. * * The LinearRegression data node tries to do this work itself. It listens * to StandardCandles and to TOS directly. It seems much better to seperate * the idea of building thse candles from the formulas written on top of them. * * LinearRegressions is different in another way. As soon as there is a new * candle, it will look twice. It will take one last look at the old candle, * a last chance before the new candle is built. Then it will immeidately * create a new candle based on the last print, and look at that. That new * candle will have a high/low/open/close which might be outside of the final * high/low for that candle. CurrentCandles will not try to build the next * candle until the next print after the last candle closes. In fact, the end * of the current candle on the underlying StandardCandles might not cause * any change to (or notification from) this candle. */ #include "StandardCandles.h" class CurrentCandles : public DataNode { public: typedef StandardCandles::CandleArray CandleArray; typedef StandardCandles::SingleCandle SingleCandle; typedef uint64_t Epoch; enum LastTransition { ltReset, // Major changes. ltNewCandle, // Added one new candle to the end, nothing else changed. ltUpdateCurrentCandle, /* The last candle changed, but nothing else. * It's possible that nothing at all changed, but * this data node will generally try to avoid * sending reports in that case. Any change is * possible, even a high getting lower. */ ltNone /* Nothing changed. We will never store this internally, but * if someone asked what's changed recently he might get this * answer. */ }; private: StandardCandles *_candleData; GenericTosDataNode *_tosData; // This will be generally similar to _andleData->getHistory(). // There might be one extra item. That extra item will generally be similar // to _candlesData->getCurrentCandle(). CandleArray _history; // Use this to avoid a bunch of warning about comparing signed and unsigned. int historySize() const { return _history.size(); } // The epoch updates pretty much every time _history updates. You can not // read this directly like in standard candles. We don't have that mechanism // in place. Any print could change this. Epoch _selfEpoch; LastTransition _lastTransition; StandardCandles::Epoch _baseEpoch; bool _freezeUpdates; // This is purely a optimization. bool _somethingChanged; // Call notifyListeners() soon. enum { wTosData, wCandleData }; void onWakeup(int msgId); void makeCurrent(); void optionallyNotifyListeners(); CurrentCandles(DataNodeArgument const &args); friend class DataNode; public: static DataNodeLink *find(DataNodeListener *listener, int msgId, CurrentCandles *&node, std::string const &symbol, int minutesPerBar); // For performance reasons we put this all together. Initialize epoch to 0. // Pass in that variable to this on each call. This function will // automatically decide how much you've mised since last time, update your // epoch variable, and return the last transition. CandleArray const &getHistory(Epoch &epoch, LastTransition &lastTransition); }; #endif