-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathChartDVBasics.h
197 lines (156 loc) · 6.9 KB
/
ChartDVBasics.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/************************************************************************
* Copyright(c) 2013, One Unified. All rights reserved. *
* email: [email protected] *
* *
* This file is provided as is WITHOUT ANY WARRANTY *
* without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* This software may not be used nor distributed without proper license *
* agreement. *
* *
* See the file LICENSE.txt for redistribution information. *
************************************************************************/
// Started 2013/09/29
// Taken from Strategy1/Strategy.h
// used as a base class for super-classes, which would add additional indicators to the existing ones.
#pragma once
#include <OUCharting/ChartDataView.h>
#include <OUCharting/ChartEntryBars.h>
#include <OUCharting/ChartEntryVolume.h>
#include <OUCharting/ChartEntryIndicator.h>
#include <OUCharting/ChartEntryShape.h>
#include <OUCharting/ChartEntryMark.h>
#include <TFTimeSeries/TimeSeries.h>
#include <TFTimeSeries/BarFactory.h>
//#include <TFTimeSeries/Adapters.h>
#include <TFIndicators/Crossing.h>
#include <TFIndicators/ZigZag.h>
#include <TFIndicators/TSEMA.h>
//#include <TFIndicators/TSDifferential.h>
//#include <TFIndicators/TSVariance.h>
#include <TFIndicators/TSSWRunningTally.h>
#include <TFIndicators/TSSWRateOfChange.h>
#include <TFIndicators/TSSWStats.h>
namespace ou { // One Unified
class ChartDVBasics {
public:
ChartDVBasics();
virtual ~ChartDVBasics();
ou::ChartDataView* GetChartDataView() { return &m_dvChart; };
// void HandleFirstQuote( const ou::tf::Quote& quote );
// void HandleFirstTrade( const ou::tf::Trade& trade );
void HandleQuote( const ou::tf::Quote& quote );
void HandleTrade( const ou::tf::Trade& trade );
protected:
enum class ETradeDirection { TradeDirUnkn=0, TradeDirUp, TradeDirDn } m_TradeDirection;
bool m_bFirstTrade;
ou::ChartDataView m_dvChart;
double m_dblUpTicks, m_dblMdTicks, m_dblDnTicks;
double m_dblUpVolume, m_dblMdVolume, m_dblDnVolume;
ou::tf::Prices m_pricesTickDiffs;
ou::tf::TSSWRunningTally m_rtTickDiffs;
ou::tf::Prices m_pricesTickDiffsROC;
ou::tf::TSSWRateOfChange m_rocTickDiffs;
ou::tf::Quote m_quoteLast; // used for classifying the current trade direction
ou::tf::Quotes m_quotes;
ou::tf::Trades m_trades;
ou::tf::BarFactory m_bfTrades;
ou::tf::BarFactory m_bfBuys;
ou::tf::BarFactory m_bfSells;
ou::ChartEntryBars m_ceBars;
ou::tf::ZigZag m_zigzagPrice;
struct ceVolumes_t {
ou::ChartEntryVolume ceVolumeUp;
ou::ChartEntryVolume ceVolumeNeutral;
ou::ChartEntryVolume ceVolumeDn;
void Reserve( ou::ChartEntryVolume::size_type n ) {
ceVolumeUp.Reserve( n );
ceVolumeNeutral.Reserve( n );
ceVolumeDn.Reserve( n );
}
};
enum EVolumes_t { VDn=0, VUp, VCnt_ };
ceVolumes_t m_rVolumes[ VCnt_ ];
struct infoBollinger {
ou::tf::Crossing<double> m_stateAccel;
time_duration m_td;
ou::tf::Quotes& m_quotes;
ou::tf::hf::TSEMA<ou::tf::Quote> m_ema;
ou::tf::TSSWStatsMidQuote m_stats;
ou::ChartEntryIndicator m_ceEma;
ou::ChartEntryIndicator m_ceUpperBollinger;
ou::ChartEntryIndicator m_ceLowerBollinger;
//ou::ChartEntryIndicator m_ceRatio;
ou::tf::TSSWStatsPrice m_statsSlope;
ou::ChartEntryIndicator m_ceSlope;
ou::tf::Prices m_tsStatsSlope;
ou::tf::TSSWStatsPrice m_statsSlopeBy2;
ou::ChartEntryIndicator m_ceSlopeBy2;
ou::tf::Prices m_tsStatsSlopeBy2;
ou::tf::TSSWStatsPrice m_statsSlopeBy3;
ou::ChartEntryIndicator m_ceSlopeBy3;
double m_dblBollingerWidth;
void SetProperties( ou::Colour::EColour colour, const std::string& sName ) {
m_ceEma.SetName( sName );
m_ceEma.SetColour( colour );
m_ceUpperBollinger.SetColour( colour );
m_ceLowerBollinger.SetColour( colour );
//m_ceRatio.SetColour( colour );
m_ceSlope.SetColour( colour );
m_ceSlopeBy2.SetColour( colour );
m_ceSlopeBy3.SetColour( colour );
}
infoBollinger( ou::tf::Quotes& quotes, time_duration td )
: m_td( td ), m_quotes( quotes ), m_dblBollingerWidth( 0.0 ),
m_ema( quotes, td ), m_stats( quotes, td ),
m_statsSlope( m_ema, boost::posix_time::time_duration( 0, 0, 30 ) ),
m_statsSlopeBy2( m_tsStatsSlope, boost::posix_time::time_duration( 0, 0, 30 ) ),
m_statsSlopeBy3( m_tsStatsSlopeBy2, boost::posix_time::time_duration( 0, 0, 15 ) )
{
}
infoBollinger( const infoBollinger& rhs )
: m_td( rhs.m_td ), m_quotes( rhs.m_quotes ), m_dblBollingerWidth( rhs.m_dblBollingerWidth ),
m_ema( m_quotes, m_td ), m_stats( m_quotes, m_td ),
m_statsSlope( m_ema, boost::posix_time::time_duration( 0, 0, 30 ) ),
m_statsSlopeBy2( m_tsStatsSlope, boost::posix_time::time_duration( 0, 0, 30 ) ),
m_statsSlopeBy3( m_tsStatsSlopeBy2, boost::posix_time::time_duration( 0, 0, 15 ) )
{
}
~infoBollinger( void ) {};
};
using vInfoBollinger_t = std::vector<infoBollinger>;
vInfoBollinger_t m_vInfoBollinger;
ou::ChartEntryIndicator m_ceTrade;
ou::ChartEntryIndicator m_ceQuoteUpper;
ou::ChartEntryIndicator m_ceQuoteLower;
ou::ChartEntryIndicator m_ceQuoteSpread;
ou::ChartEntryIndicator m_ceTickDiffs;
ou::ChartEntryIndicator m_ceTickDiffsRoc;
ou::ChartEntryIndicator m_ceZigZag;
// ou::ChartEntryMark m_cemRatio;
ou::ChartEntryMark m_cemSlope;
ou::ChartEntryMark m_cemSlopeBy2;
ou::ChartEntryMark m_cemSlopeBy3;
ou::ChartEntryShape m_ceShortEntries;
ou::ChartEntryShape m_ceLongEntries;
ou::ChartEntryShape m_ceShortFills;
ou::ChartEntryShape m_ceLongFills;
ou::ChartEntryShape m_ceShortExits;
ou::ChartEntryShape m_ceLongExits;
// ou::ChartEntryIndicator m_ceSMA2;
// ou::ChartEntryIndicator m_ceSlopeOfSMA2;
// ou::ChartEntryIndicator m_ceSlopeOfSlopeOfSMA2;
// ou::ChartEntryIndicator m_ceBollinger2Offset;
// ou::ChartEntryIndicator m_ceSlopeOfBollinger2Offset;
//ou::ChartEntryIndicator m_ceBollinger2Ratio;
// ou::ChartEntryIndicator m_ceSMA2RR;
private:
void HandleBarCompletionTrades( const ou::tf::Bar& );
void HandleBarCompletionBuys( const ou::tf::Bar& );
void HandleBarCompletionSells( const ou::tf::Bar& );
void HandleZigZagPeak( const ou::tf::ZigZag&, ptime, double, ou::tf::ZigZag::EDirection );
void HandleZigZagUpDp( const ou::tf::ZigZag& );
void HandleZigZagDnDp( const ou::tf::ZigZag& );
};
} // namespace ou