-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcandle.cpp
More file actions
53 lines (45 loc) · 871 Bytes
/
candle.cpp
File metadata and controls
53 lines (45 loc) · 871 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
46
47
48
49
50
51
52
53
#include "candle.h"
#include <string>
#include <stdexcept>
Candle::Candle(Price _open, Price _high, Price _low, Price _close)
: open(_open)
, high(_high)
, low(_low)
, close(_close)
{
}
bool Candle::body_contains(const Price &price) const noexcept
{
if(is_green())
{
const Price &max = close;
const Price &min = open;
return price >= min && price <= max;
}
else
{
const Price &max = open;
const Price &min = close;
return price >= min && price <= max;
}
}
bool Candle::contains(const Price &price) const noexcept
{
return price >= low && price <= high;
}
double Candle::full_size() const noexcept
{
return std::abs(low - high);
}
double Candle::body_size() const noexcept
{
return std::abs(open - close);
}
bool Candle::is_green() const noexcept
{
return close > open;
}
bool Candle::is_red() const noexcept
{
return close < open;
}