AddDataSeries("SPY",BarsPeriodType.Day,1,22);
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Setting a number of days in AddDataSeries
Collapse
X
-
Setting a number of days in AddDataSeries
I am trying to get the value of a 22 Period Daily Moving average. I am using the following to add the series:
Code:Tags: None
-
Hello swcookie,
The error would be correct, there is no overload pattern like this. You can find the accepted patterns in the help guide here: https://ninjatrader.com/support/help...=adddataseries
The closest to what you are asking for would be the overload that includes a number of bars to load. You could calculate the number of bars you want that would equate to 22 days and then add that. For a daily series you would just need to use 22 for 22 Bars of daily data.
Code:AddDataSeries(string instrumentName, BarsPeriod barsPeriod, int barsToLoad, string tradingHoursName, bool? isResetOnNewTradingDay)
Code:AddDataSeries(string instrumentName, BarsPeriodType periodType, int period)
I look forward to being of further assistance.JesseNinjaTrader Customer Service
-
I am having a little trouble with the overload pattern. This is what I am using:
Code:AddDataSeries("SPY",BarsPeriodType.Day,22,"Use instrument settings",true);
Comment
-
Hello swcooke,
Thanks for the reply.
The method is expecting you to make a new BarPeriod object and enter the name of the session template you want to use:
AddDataSeries("SPY", new BarsPeriod { BarsPeriodType = BarsPeriodType.Day, Value = 1 }, 22, "US Equities RTH", true);
To find the default trading hours template an instrument is using, go to Tools>Instruments>Search the instrument>Open the instrument configuration menu>look at the Trading Hours field.
Please let me know if I can assist further.Chris L.NinjaTrader Customer Service
Comment
-
Thanks for that. I am trying to calculate the 22 period MA 1 time at the beginning of the script so that the script can use its' value. Here is what I have but it does not match the 22 period MA that I add to a chart as just a basic indicator:
Code:else if (State == State.Configure) { AddDataSeries("SPY", new BarsPeriod { BarsPeriodType = BarsPeriodType.Day, Value = 1 }, 22, "US Equities RTH", true); } else if (State == State.DataLoaded) { Print("Value is " + SMA(BarsArray[1], 22)[0]); //this does not match what an SMA Indicator is returning for the last bar }
Comment
-
Hello swcooke,
Thank you for the reply.
In this case, you need to move your logic out of OnStateChange to OnBarUpdate. You cannot access price or indicator values in DataLoaded.
Additionally, if you access the indicator on the first bar or once, that would either be before the BarsRequiredToPlot or would just be the first value for your indicator. The SMA changes over time so to get the same values you see on the chart, you would have to check its value for each OnBarUpdate call.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by BIOK.NT, Today, 09:10 AM
|
0 responses
1 view
0 likes
|
Last Post
![]()
by BIOK.NT
Today, 09:10 AM
|
||
Started by MatthewLesko, 03-23-2025, 07:38 AM
|
4 responses
31 views
0 likes
|
Last Post
![]()
by MatthewLesko
Today, 09:09 AM
|
||
Started by gyilaoliver, Today, 08:28 AM
|
7 responses
15 views
0 likes
|
Last Post
![]()
by gyilaoliver
Today, 09:05 AM
|
||
Started by Darkslide_Tom, 03-23-2025, 11:08 PM
|
3 responses
17 views
0 likes
|
Last Post
|
||
Started by rtwave, 03-13-2025, 04:09 PM
|
4 responses
29 views
0 likes
|
Last Post
|
Comment