/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using Newtonsoft.Json;
using QuantConnect.Util;
namespace QuantConnect
{
///
/// Single Chart Point Value Type for QCAlgorithm.Plot();
///
[JsonConverter(typeof(ChartPointJsonConverter))]
public class ChartPoint : ISeriesPoint
{
private DateTime _time;
private long _x;
private decimal? _y;
///
/// Time of this chart series point
///
[JsonIgnore]
public DateTime Time
{
get
{
return _time;
}
set
{
_time = value;
_x = Convert.ToInt64(QuantConnect.Time.DateTimeToUnixTimeStamp(_time));
}
}
///
/// Chart point time
///
/// Lower case for javascript encoding simplicity
public long x
{
get
{
return _x;
}
set
{
_time = QuantConnect.Time.UnixTimeStampToDateTime(value);
_x = value;
}
}
///
/// Chart point value
///
/// Lower case for javascript encoding simplicity
public decimal? y
{
get
{
return _y;
}
set
{
_y = value.SmartRounding();
}
}
///
/// Shortcut for for C# naming conventions
///
[JsonIgnore]
public long X => x;
///
/// Shortcut for for C# naming conventions
///
[JsonIgnore]
public decimal? Y => y;
///
/// Default constructor. Using in SeriesSampler.
///
public ChartPoint() { }
///
/// Constructor that takes both x, y value pairs
///
/// X value often representing a time in seconds
/// Y value
public ChartPoint(long xValue, decimal? yValue)
: this()
{
x = xValue;
y = yValue;
}
///
/// Constructor that takes both x, y value pairs
///
/// This point time
/// Y value
public ChartPoint(DateTime time, decimal? value)
: this()
{
Time = time;
y = value;
}
///Cloner Constructor:
public ChartPoint(ChartPoint point)
{
_time = point._time;
_x = point._x;
_y = point._y;
}
///
/// Provides a readable string representation of this instance.
///
public override string ToString()
{
return Messages.ChartPoint.ToString(this);
}
///
/// Clones this instance
///
/// Clone of this instance
public virtual ISeriesPoint Clone()
{
return new ChartPoint(this);
}
}
}