Lean
$LEAN_TAG$
ChartPoint.cs
1
/*
2
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8
*
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
14
*/
15
16
using
System;
17
using
Newtonsoft.Json;
18
using
QuantConnect
.
Util
;
19
20
namespace
QuantConnect
21
{
22
/// <summary>
23
/// Single Chart Point Value Type for QCAlgorithm.Plot();
24
/// </summary>
25
[JsonConverter(typeof(
ChartPointJsonConverter
))]
26
public
class
ChartPoint
:
ISeriesPoint
27
{
28
private
DateTime _time;
29
private
long
_x;
30
private
decimal? _y;
31
32
/// <summary>
33
/// Time of this chart series point
34
/// </summary>
35
[JsonIgnore]
36
public
DateTime
Time
37
{
38
get
39
{
40
return
_time;
41
}
42
set
43
{
44
_time = value;
45
_x = Convert.ToInt64(
QuantConnect
.
Time
.
DateTimeToUnixTimeStamp
(_time));
46
}
47
}
48
49
/// <summary>
50
/// Chart point time
51
/// </summary>
52
/// <remarks>Lower case for javascript encoding simplicity</remarks>
53
public
long
x
54
{
55
get
56
{
57
return
_x;
58
}
59
set
60
{
61
_time =
QuantConnect
.
Time
.
UnixTimeStampToDateTime
(value);
62
_x = value;
63
}
64
}
65
66
/// <summary>
67
/// Chart point value
68
/// </summary>
69
/// <remarks>Lower case for javascript encoding simplicity</remarks>
70
public
decimal?
y
71
{
72
get
73
{
74
return
_y;
75
}
76
set
77
{
78
_y = value.SmartRounding();
79
}
80
}
81
82
/// <summary>
83
/// Shortcut for <see cref="x"/> for C# naming conventions
84
/// </summary>
85
[JsonIgnore]
86
public
long
X
=>
x
;
87
88
/// <summary>
89
/// Shortcut for <see cref="y"/> for C# naming conventions
90
/// </summary>
91
[JsonIgnore]
92
public
decimal?
Y
=>
y
;
93
94
/// <summary>
95
/// Default constructor. Using in SeriesSampler.
96
/// </summary>
97
public
ChartPoint
() { }
98
99
/// <summary>
100
/// Constructor that takes both x, y value pairs
101
/// </summary>
102
/// <param name="xValue">X value often representing a time in seconds</param>
103
/// <param name="yValue">Y value</param>
104
public
ChartPoint
(
long
xValue, decimal? yValue)
105
: this()
106
{
107
x
= xValue;
108
y
= yValue;
109
}
110
111
/// <summary>
112
/// Constructor that takes both x, y value pairs
113
/// </summary>
114
/// <param name="time">This point time</param>
115
/// <param name="value">Y value</param>
116
public
ChartPoint
(DateTime time, decimal? value)
117
: this()
118
{
119
Time
= time;
120
y
= value;
121
}
122
123
///Cloner Constructor:
124
public
ChartPoint
(
ChartPoint
point)
125
{
126
_time = point._time;
127
_x = point._x;
128
_y = point._y;
129
}
130
131
/// <summary>
132
/// Provides a readable string representation of this instance.
133
/// </summary>
134
public
override
string
ToString
()
135
{
136
return
Messages
.
ChartPoint
.
ToString
(
this
);
137
}
138
139
/// <summary>
140
/// Clones this instance
141
/// </summary>
142
/// <returns>Clone of this instance</returns>
143
public
virtual
ISeriesPoint
Clone
()
144
{
145
return
new
ChartPoint
(
this
);
146
}
147
}
148
}
Common
ChartPoint.cs
Generated by
1.8.17