MarketData.GetBars - Loading the same timeframe twice
MarketData.GetBars - Loading the same timeframe twice
29 Sep 2023, 01:00
Hi,
Quick question on MarketData.GetBars(…). If I were to run the following code:
TimeFrame tf = TimeFrame.Parse("Hour");
DataSeries bars1 = MarketData.GetBars(tf).ClosePrices;
DataSeries bars2 = MarketData.GetBars(tf).ClosePrices;
MovingAverage ma1 = Indicators.MovingAverage(bars1, 50, MovingAverageType.Simple);
MovingAverage ma2 = Indicators.MovingAverage(bars2, 100, MovingAverageType.Simple);
Would this essentially load the same data into memory twice? Or would references be managed behind the scenes in some way?
Its not that I want to do this, but if it is the case, I wanted to avoid loading multiple times when setting up indicators individually from configuration.
Many thanks
Replies
jonlangdon
29 Sep 2023, 11:39
( Updated at: 29 Sep 2023, 11:43 )
RE: MarketData.GetBars - Loading the same timeframe twice
PanagiotisChar said:
Hi there,
I guess it will be loaded only once but why do you need to do that? Why don't you just use bars1?
Hi, thanks for that.
It's not really that I wanted to do it on purpose, more just for understanding and to avoid unnecessarily loading multiple instances of the same thing.
In a case where I'm setting the time frame of an indicator from configuration like below, as an example:
[Parameter(DefaultValue = "m5", Group = "TimeFrames")]
public TimeFrame MaTimeframe { get; set; }
[Parameter(DefaultValue = "m10", Group = "TimeFrames")]
public TimeFrame BbTimeframe { get; set; }
// ...
DataSeries maBars = MarketData.GetBars(MaTimeframe).ClosePrices;
MovingAverage ma = Indicators.MovingAverage(maBars, 50, MovingAverageType.Simple);
DataSeries bbBars = MarketData.GetBars(BbTimeframe).ClosePrices;
BollingerBands bb = Indicators.BollingerBands(bbBars, 20, 2, MovingAverageType.Simple);
This would allow for time frames to be changed independently for each indicator, but could lead to a case where both time frames where the same.
@jonlangdon
PanagiotisChar
29 Sep 2023, 05:20
Hi there,
I guess it will be loaded only once but why do you need to do that? Why don't you just use bars1?
@PanagiotisChar