Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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
-
Hello TAJTrades,
Thanks for the note.
There was nothing changed between the most current update and the last one. What is going wrong with the BarsRequest specifically? Are you able to run a simple Addon that does a BarsRequest and see if it will work there?
I look forward to your reply.Chris L.NinjaTrader Customer Service
-
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.Chris L.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by DJ888, 04-16-2024, 06:09 PM
|
6 responses
18 views
0 likes
|
Last Post
by DJ888
Today, 05:12 PM
|
||
Started by Jon17, Today, 04:33 PM
|
0 responses
1 view
0 likes
|
Last Post
by Jon17
Today, 04:33 PM
|
||
Started by Javierw.ok, Today, 04:12 PM
|
0 responses
6 views
0 likes
|
Last Post
by Javierw.ok
Today, 04:12 PM
|
||
Started by timmbbo, Today, 08:59 AM
|
2 responses
10 views
0 likes
|
Last Post
by bltdavid
Today, 04:10 PM
|
||
Started by alifarahani, Today, 09:40 AM
|
6 responses
41 views
0 likes
|
Last Post
by alifarahani
Today, 03:18 PM
|
Comment