Summary
Represents the Bars interface - the collection of Bar objects.
Syntax
public interface Bars : IEnumerable
Members
Name | Type | Summary |
---|---|---|
BarOpened | Event | Occurs when the last bar is closed and a new bar is opened. |
ClosePrices | Property | Gets the Close price bars data. |
Count | Property | Gets the number of bars. |
HighPrices | Property | Gets the High price bars data. |
HistoryLoaded | Event | Occurs when more history is loaded due to chart scroll on the left or due to API call. |
Last | Method | Gets the bar from the end of the collection. |
LastBar | Property | Gets the last bar in the chart. |
LoadMoreHistory | Method | Loads more historical bars. Method returns the number of loaded bars that were added to the beginning of the collection. |
LoadMoreHistoryAsync | Method | Loads more historical bars asynchronously. |
LowPrices | Property | Gets the Low price bars data. |
MedianPrices | Property | Gets the Median prices data. |
OpenPrices | Property | Gets the Open price bars data. |
OpenTimes | Property | Gets the open bar time data. |
Reloaded | Event | Occurs when bars are refreshed due to reconnect. |
SymbolName | Property | Gets the symbol name. |
this[int index] | Property | |
Tick | Event | Occurs when a new Tick arrives. |
TickVolumes | Property | Gets the Tick volumes data. |
TimeFrame | Property | Get the timeframe. |
TypicalPrices | Property | Gets the Typical prices data. |
WeightedPrices | Property | Gets the Weighted prices data. |
Example 1
using cAlgo.API; using System; namespace cAlgo { // A sample indicator that shows how to use Bars [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class BarsSample : Indicator { private TextBlock _barTicksNumberTextBlock, _barsStateTextBlock; [Output("Range", LineColor = "RoyalBlue")] public IndicatorDataSeries Range { get; set; } [Output("Body", LineColor = "Yellow")] public IndicatorDataSeries Body { get; set; } protected override void Initialize() { // Bars events Bars.BarOpened += Bars_BarOpened; Bars.Tick += Bars_Tick; Bars.HistoryLoaded += Bars_HistoryLoaded; Bars.Reloaded += Bars_Reloaded; var grid = new Grid(2, 2) { BackgroundColor = Color.DarkGoldenrod, HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top, Opacity = 0.5 }; grid.AddChild(new TextBlock { Text = "Bar Ticks #", Margin = 5 }, 0, 0); _barTicksNumberTextBlock = new TextBlock { Text = "0", Margin = 5 }; grid.AddChild(_barTicksNumberTextBlock, 0, 1); grid.AddChild(new TextBlock { Text = "Bars State", Margin = 5 }, 1, 0); _barsStateTextBlock = new TextBlock { Margin = 5 }; grid.AddChild(_barsStateTextBlock, 1, 1); IndicatorArea.AddControl(grid); } private void Bars_Reloaded(BarsHistoryLoadedEventArgs obj) { _barsStateTextBlock.Text = "Reloaded"; } private void Bars_HistoryLoaded(BarsHistoryLoadedEventArgs obj) { _barsStateTextBlock.Text = "History Loaded"; } private void Bars_Tick(BarsTickEventArgs obj) { _barTicksNumberTextBlock.Text = Bars.TickVolumes.LastValue.ToString(); } private void Bars_BarOpened(BarOpenedEventArgs obj) { _barsStateTextBlock.Text = "New Bar Opened"; } public override void Calculate(int index) { Range[index] = Bars.HighPrices[index] - Bars.LowPrices[index]; Body[index] = Math.Abs(Bars.ClosePrices[index] - Bars.OpenPrices[index]); } } }