/* * 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; namespace QuantConnect.Data.Market { /// /// Represents a bar sectioned not by time, but by some amount of movement in volume /// public class VolumeRenkoBar : BaseRenkoBar { /// /// Gets whether or not this bar is considered closed. /// public override bool IsClosed => Volume >= BrickSize; /// /// Initializes a new default instance of the class. /// public VolumeRenkoBar() { } /// /// Initializes a new instance of the class with the specified values /// /// symbol of the data /// The current data start time /// The current data end time /// The preset volume capacity of this bar /// The current data open value /// The current data high value /// The current data low value /// The current data close value /// The current data volume public VolumeRenkoBar(Symbol symbol, DateTime start, DateTime endTime, decimal brickSize, decimal open, decimal high, decimal low, decimal close, decimal volume) { Type = RenkoType.Classic; BrickSize = brickSize; Symbol = symbol; Start = start; EndTime = endTime; Open = open; Close = close; Volume = volume; High = high; Low = low; } /// /// Updates this with the specified values and returns whether or not this bar is closed /// /// The current data end time /// The current data high value /// The current data low value /// The current data close value /// The current data volume /// The excess volume that the current bar cannot absorb public decimal Update(DateTime time, decimal high, decimal low, decimal close, decimal volume) { // can't update a closed renko bar if (IsClosed) return 0m; EndTime = time; var excessVolume = Volume + volume - BrickSize; if (excessVolume > 0) { Volume = BrickSize; } else { Volume += volume; } Close = close; if (high > High) High = high; if (low < Low) Low = low; return excessVolume; } /// /// Create a new with previous information rollover /// public VolumeRenkoBar Rollover() { return new VolumeRenkoBar { Type = Type, BrickSize = BrickSize, Symbol = Symbol, Open = Close, // rollover open is the previous close High = Close, Low = Close, Close = Close, Start = EndTime, // rollover start time is the previous end time EndTime = EndTime, Volume = 0m }; } } }