Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
BarsRequest
Collapse
X
-
BarsRequest
I have been using BarsRequest for months in an Indicator and had zero issues. On Sunday I updated to 16 and it totally crapped out. I went thru the Help guide to see if there were any changes. I might have overlooked something but I did not see anything. What changed and how do I fix it?Tags: None
-
First off, I am using BarsRequest in an Indicator not an Addon.
Details:
I am using this indicator on a 405 Minute RTH chart for the ES with 20 bars loaded. Prior to upgrading to NT8 16 it would print out the Close each 30 minute segment of the Daily bar to the Output Window. Now it does nothing. No Error Messages or prints within the BarsRequest.
here is the code in question:
PHP Code:else if (State == State.DataLoaded) { si = new SessionIterator(Bars); // Instantiate a new <ChartControl>.BarsArray collection System.Collections.ObjectModel.ObservableCollection<ChartBars> myChartBars = ChartControl.BarsArray; // Get each Bar on the Daily RTH Chart foreach(ChartBars bars in myChartBars) { for (int index = 0; index < bars.Bars.Count; index++) { si.GetNextSession(bars.Bars.GetTime(index), true); // Get Sesion Begin and End DateTime DateTime endDate = si.ActualSessionEnd; DateTime beginDate = si.ActualSessionBegin; Print(string.Format("beginDate: {0} endDate {1}", beginDate, endDate)); // create a new bars request. This will determine the insturment and range for the bars to be requested BarsRequest barsRequest = new BarsRequest(Cbi.Instrument.GetInstrument(Instrument.FullName.ToString()), beginDate, endDate); // Parametrize your request. // Create 30 Minute Bars barsRequest.BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 30 }; barsRequest.TradingHours = TradingHours.Get(Bars.TradingHours.Name); barsRequest.MergePolicy = MergePolicy.MergeBackAdjusted; Print(string.Format("barsRequest has been parameterized {0}", barsRequest.ToString() )); Print("Begin BarsRequest"); // Request the bars barsRequest.Request(new Action<BarsRequest, ErrorCode, string>((requestedBars, errorCode, errorMessage) => { // ************************************************************************************************************ // Nothing Prints to the Output Window inside of Request. It used to!! // ************************************************************************************************************ NinjaTrader.Code.Output.Process(string.Format("barsRequest.Bars.Count: {0}", barsRequest.Bars.Count), PrintTo.OutputTab1); if(requestedBars == null) NinjaTrader.Code.Output.Process(("requestedBars is null"), PrintTo.OutputTab1); // Handle any errors in requesting bars here if (errorCode != ErrorCode.NoError) { NinjaTrader.Code.Output.Process(string.Format("Error on requesting bars: {0}, {1}", errorCode, errorMessage), PrintTo.OutputTab1); return; } // If Tick Data does not exist create a warning and then return; if( requestedBars.Bars.Count < 1) { string errorString = "Error: Indicator Script " + Name + "\r\nData does NOT exist for " + endDate.ToShortDateString(); Log(errorString, LogLevel.Alert); return; } // Output the bars we requested. for (int i = 0; i < requestedBars.Bars.Count; i++) { NinjaTrader.Code.Output.Process(string.Format("{0} Close {1} ", requestedBars.Bars.GetTime(i),requestedBars.Bars.GetClose(i)), PrintTo.OutputTab1); } })); barsRequest.Dispose(); } } }
Something happened when I updated to 16. Either something change with NT or the Update jumped the rails. I do not know which.
I have also attached the .cs file if you want to try running it.
Thanks for your help.Attached Files
Comment
-
Hello TAJTrades,
Thank you for the reply.
I was able to get the example from the help guide to work with an indicator. I noticed implementation differences between your script and the one I created, so I will post the script here. Please use this to compare and contrast what the problem might be in your script.
Please let me know if I can assist further.Attached FilesLast edited by NinjaTrader_ChrisL; 04-24-2023, 02:12 PM. Reason: I removed an unused reference in the sample.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
566 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
330 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
547 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
548 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment