1. I need to get ATR value on or before First call to OnBarUpdate
For the same purpose i tried to use the BarsRequest, but is it not returning as expected. It always returns Null Bars.
Please help how to get ATR even before or on first call of BarsRequest.
2. Moreover wish to make a BarsType, and needs to take Value starting from 0 (Zero), but it is not allowed might be minimum range is set to 1. How can i modify that attribute?
BarsRequest barsRequest = new BarsRequest(bars.Instrument, DateTime.Now.AddDays(-4), DateTime.Now.AddDays(-1)); barsRequest.BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1 }; barsRequest.TradingHours = NinjaTrader.Data.TradingHours.Get("Default 24 x 7"); barsRequest.Request(new Action<BarsRequest, ErrorCode, string>((retBars, errorCode, errorMessage) => { Print("Error: " + errorCode.ToString()); if (errorCode != ErrorCode.NoError) // Handle any errors in requesting bars here return; if(retBars.Bars == null) Print("Null Bars"); else Print("Bars are there"); Print(retBars.Bars.Count); for (int i = 0; i < retBars.Bars.Count; i++) { // Output the bars NinjaTrader.Code.Output.Process(string.Format("Time: {0} Open: {1} High: {2} Low: {3} Close: {4} Volume: {5}", retBars.Bars.GetTime(i), retBars.Bars.GetOpen(i), retBars.Bars.GetHigh(i), retBars.Bars.GetLow(i), retBars.Bars.GetClose(i), retBars.Bars.GetVolume(i)), PrintTo.OutputTab1); } Series<double> cls = new Series<double>(retBars.Bars, MaximumBarsLookBack.Infinite); Indicators.ATR t = new Indicators.ATR(); double atrVal = t.ATR(cls, 100)[0]; Print("ATR: " + atrVal); })); barsRequest.Dispose();
Comment