-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrade_data.cpp
More file actions
45 lines (39 loc) · 923 Bytes
/
trade_data.cpp
File metadata and controls
45 lines (39 loc) · 923 Bytes
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
#include "trade_data.h"
TradeData::TradeData()
: m_maxHigh(0)
, m_maxLow(0)
, m_minHigh(0)
, m_minLow(0)
{}
PriceStatus TradeData::appendPrice(unsigned int _price)
{
if (m_maxHigh == 0)
{
m_maxHigh = _price;
m_minLow = _price;
return PriceStatusUnknown;
}
if (_price > m_maxHigh)
{
m_maxHigh = _price;
return PriceStatusHighest;
}
else if (_price < m_minLow)
{
m_minLow = _price;
return PriceStatusLowest;
}
unsigned int deltaMin = _price - m_minLow;
unsigned int deltaMax = m_maxHigh - _price;
if (deltaMin < deltaMax)
{
m_minHigh = _price;
return PriceStatusLow;
}
m_maxLow = _price;
return PriceStatusHigh;
}
unsigned int TradeData::getPrice(bool _isMax, bool _isHigh)
{
return _isMax ? (_isHigh ? m_maxHigh : m_maxLow) : (_isHigh ? m_minHigh : m_minLow);
}