/** * Copyright Mikael Högdahl - triyana@users.sourceforge.net * * This source is distributed under the terms of the Q Public License version 1.0, * created by Trolltech (www.trolltech.com). */ #ifndef MHPrice_H #define MHPrice_H #include "MHString.h" #include "MHVector.h" /** * A class for storing chart data points or other numerical * data that needs to be stored in a time serie. * There are also some static utility methods to convert time series of the points. */ class MHPrice : public MH { public: char aDate[9]; double aHigh; double aLow; double aClose; double aOpen; double aVol; enum { MVG_ATR = 14, MVG_BOLLINGER = 20, MVG_ELONG = 16, MVG_ESHORT = 8, MVG_LONG = 16, MVG_MACD_ESMA = 9, MVG_MACD_LONG = 26, MVG_MACD_SHORT = 12, MVG_MOMENTUM = 10, MVG_RSI = 14, MVG_SHORT = 8, MVG_STD = 20, MVG_STOCHASTICS_K = 14, MVG_STOCHASTICS_SMA_K = 1, MVG_STOCHASTICS_SMA_D = 3, BUY = 1, NEUTRAL = 0, SELL = -1, }; static const double MIN_VALUE; static const double MAX_VALUE; static const double ZERO_VALUE; MHPrice () {aHigh = aLow = aClose = aOpen = aVol = 0.0; *aDate = '\0';} MHPrice (const MHPrice&); MHPrice (const char* d, double h); MHPrice (double h, double c); MHPrice (const char* d, double h, double l, double c, double o, double v); MHPrice& operator=(const MHPrice&); bool operator==(const MHPrice& x) {return (strcmp (aDate, x.aDate) == 0) ? true : false;} bool operator==(const char* s) {return (strcmp (aDate, s) == 0) ? true : false;} bool operator!=(const MHPrice& x) {return (strcmp (aDate, x.aDate) != 0) ? true : false;} bool operator>(const MHPrice& x) {return (strcmp (aDate, x.aDate) > 0) ? true : false;} bool operator>(const char* s) {return (strcmp (aDate, s) > 0) ? true : false;} bool operator<(const MHPrice& x) {return (strcmp (aDate, x.aDate) < 0) ? true : false;} bool operator<(const char* s){return (strcmp (aDate, s) < 0) ? true : false;} bool operator<=(const MHPrice& x) {return (strcmp (aDate, x.aDate) < 1) ? true : false;} bool operator<=(const char* x) {return (strcmp (aDate, x) < 1) ? true : false;} bool operator>=(const MHPrice& x) {return (strcmp (aDate, x.aDate) >= 0) ? true : false;} bool operator>=(const char* x) {return (strcmp (aDate, x) >= 0) ? true : false;} void Adjust (double price, double volume = -1); const char* Class () {return "MHPrice";} int Compare (const MH* o, int type); void SetDate (const char* val) {strncpy (aDate, val, 8); aDate[8] = '\0';} void SetDate (const MHString* val) {strncpy (aDate, val->Get(), 8); aDate[8] = '\0';} void Validate (); static void ATR (MHVector* in, MHVector*out, int nMvg); static void Bollinger (MHVector* in, MHVector* mvg, MHVector* upper, MHVector* lower, int nDays); static void Clear (MHVector*); static void Copy (MHVector* in, MHVector* out, const char* pStartDate = 0, const char* pStopDate = 0); static void CopyPointers (MHVector* in, MHVector* out); static void Cut (MHVector* in, MHVector* out); static void Day2Week (MHVector* in, MHVector* out, int nWeekDay); static void Diff (MHVector* in1, MHVector* in2, MHVector* out, MHVector* out2 = 0); static void ExponentialMovingAverage (MHVector* in, MHVector* out, int nMvg); static void MACD (MHVector* in, MHVector* macd1, MHVector* macd2, int emaShort, int emaLong, int emaMacd); static void Momentum (MHVector* in, MHVector*out, MHVector* zero, int nMvg); static void MovingAverage (MHVector* in, MHVector* out, int nMvg); static void MovingAverageSignals (MHVector* in_short, MHVector* in_long, MHVector* out); static void Normalise (MHVector* in, MHVector* out, double nOrigo); static void Print (MHVector* in); static void RSI (MHVector* in, MHVector*out, int nMvg); static void RSISignals (MHVector* in, MHVector* out, double low = 30.0, double high = 70.0); static bool Save (const char* pFilename, MHVector* in); static void StdDev (MHVector* in, MHVector* out, int nDays); static void Stochastics (MHVector* in, MHVector* kout, MHVector* dout, int k, int sma, int d); static void Stochastics (MHVector* in, MHVector* kout, MHVector* dout, MHVector* out20, MHVector* out80, int k, int sma, int d); static void Volume (MHVector* in, MHVector* out); private: int compare (MHPrice* price) {return strcmp(aDate, price->aDate);} int compare (MHString* string) {return strcmp(aDate, string->Get());} }; #endif