#ifndef __VolumeBlockMinAndMax_h_ #define __VolumeBlockMinAndMax_h_ /* TVolumeBlockMinAndMax converts volume bars into a series of upward and * downward lines. Sometimes it can be slow to show a change in direction * because it needs at least one whole volume bar going in the opposite * direction of the current trend before it makes an announcement. * * This class wakes the listener every time the underlying volume bars * data node wakes it. The turning points may or may not have changed. * One update may contain zero, one, or more additions to the list of * turning points. * * If the volume blocks data node resets, this data node will also reset, * presenting a list of 0 turning points. Except for that case, the list * of turning points can only grow. The existing points won't change or * go away. */ #include "NormalVolumeBreakBars.h" class VolumeBlockMinAndMax : public DataNode { public: enum Orientation { vboHigh, vboLow }; struct TurningPoint { double price; int index; Orientation orientation; }; typedef std::vector< TurningPoint > TurningPoints; private: enum Direction { vbdUnknown, vbdUp, vbdDown, vbdPossibleUp, vbdPossibleDown }; class MinAndMaxAccumulator { private: int _blockCount; Direction _initialDirection; // This will never be vbdPossibleUp or vbdPossibleDown. Direction _currentDirection; struct RecentBlock { VolumeBlock block; int index; }; std::vector< RecentBlock > _recentBlocks; TurningPoints _turningPoints; void addRecentBlock(VolumeBlock const &block); void setRecentBlock(VolumeBlock const &block); void addTurningPoint(VolumeBlock const &block, int recentBlockIndex, Orientation orientation); public: void reset(); MinAndMaxAccumulator(); int getBlockCount() const { return _blockCount; } Direction getInitialDirection() const { return _initialDirection; } Direction getCurrentDirection() const; // This will never be vbdPossibleUp or vbdPossibleDown. TurningPoints const &getTurningPoints() const { return _turningPoints; } void addBlock(VolumeBlock const &block); }; NormalVolumeBreakBars *_barData; MinAndMaxAccumulator _highsAndLows; void onWakeup(int msgId); void checkInvariants(std::string const &symbol); VolumeBlockMinAndMax(DataNodeArgument const &args); friend class DataNode; public: VolumeBlocks const &getAllBlocks() const { return _barData->getBlocks(); } TurningPoints const &getTurningPoints() const { return _highsAndLows.getTurningPoints(); } static DataNodeLink *find(DataNodeListener *listener, int msgId, VolumeBlockMinAndMax *&node, std::string const &symbol); }; #endif