Skip to content

GetBarsAsync Method (2)

GetBarsAsync (1 of 2)

Summary

The asynchronous method to get the bars for the specific timeframe for the specific symbol.

Signature

1
public abstract void GetBarsAsync(TimeFrame timeFrame, Action<Bars> callback)

Parameters

Name Type Description
timeFrame TimeFrame The bars time frame
callback Action The callback that will be called after getting the bars

Return Value

void

Declaring Type

cAlgo.API.Internals.MarketData

Examples

1
 MarketDepth md = MarketData.GetMarketDepth(Symbol);
 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
 using cAlgo.API;
 using cAlgo.API.Internals;
 namespace cAlgo
 {
     // This sample indicator shows how to get a symbol and time frame market data
     [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class MarketDataSample : Indicator
     {
         private Bars _bars;
         private Ticks _ticks;
         private MarketDepth _marketDepth;
         [Parameter("Use Current Symbol", DefaultValue = true)]
         public bool UseCurrentSymbol { get; set; }
         [Parameter("Other Symbol Name", DefaultValue = "GBPUSD")]
         public string OtherSymbolName { get; set; }
         [Parameter("Use Current TimeFrame", DefaultValue = true)]
         public bool UseCurrentTimeFrame { get; set; }
         [Parameter("Other TimeFrame", DefaultValue = "Daily")]
         public TimeFrame OtherTimeFrame { get; set; }
         protected override void Initialize()
         {
             var symbol = UseCurrentSymbol ? Symbol : Symbols.GetSymbol(OtherSymbolName);
             var timeframe = UseCurrentTimeFrame ? TimeFrame : OtherTimeFrame;
             // You can use GetBarsAsync instead of GetBars
             _bars = MarketData.GetBars(timeframe, symbol.Name);
             // You can use GetTicksAsync instead of GetTicks
             _ticks = MarketData.GetTicks(symbol.Name);
             _marketDepth = MarketData.GetMarketDepth(symbol.Name);
         }
         public override void Calculate(int index)
         {
         }
     }
 }

GetBarsAsync (2 of 2)

Summary

The asynchronous method to get the specific bars for the specific timeframe for the specific symbol.

Signature

1
public abstract void GetBarsAsync(TimeFrame timeFrame, string symbolName, Action<Bars> callback)

Parameters

Name Type Description
timeFrame TimeFrame The bars time frame
symbolName string The bars symbol name
callback Action The callback that will be called after getting the bars

Return Value

void

Declaring Type

cAlgo.API.Internals.MarketData

Examples

1
 MarketDepth md = MarketData.GetMarketDepth(Symbol);
 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
 using cAlgo.API;
 using cAlgo.API.Internals;
 namespace cAlgo
 {
     // This sample indicator shows how to get a symbol and time frame market data
     [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class MarketDataSample : Indicator
     {
         private Bars _bars;
         private Ticks _ticks;
         private MarketDepth _marketDepth;
         [Parameter("Use Current Symbol", DefaultValue = true)]
         public bool UseCurrentSymbol { get; set; }
         [Parameter("Other Symbol Name", DefaultValue = "GBPUSD")]
         public string OtherSymbolName { get; set; }
         [Parameter("Use Current TimeFrame", DefaultValue = true)]
         public bool UseCurrentTimeFrame { get; set; }
         [Parameter("Other TimeFrame", DefaultValue = "Daily")]
         public TimeFrame OtherTimeFrame { get; set; }
         protected override void Initialize()
         {
             var symbol = UseCurrentSymbol ? Symbol : Symbols.GetSymbol(OtherSymbolName);
             var timeframe = UseCurrentTimeFrame ? TimeFrame : OtherTimeFrame;
             // You can use GetBarsAsync instead of GetBars
             _bars = MarketData.GetBars(timeframe, symbol.Name);
             // You can use GetTicksAsync instead of GetTicks
             _ticks = MarketData.GetTicks(symbol.Name);
             _marketDepth = MarketData.GetMarketDepth(symbol.Name);
         }
         public override void Calculate(int index)
         {
         }
     }
 }

Last update: September 26, 2022

Comments