New to Ninja. I want to create a generic function like moving average but I want to be able to access it for different timeframes. How would I do that?
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
Data from another timeframe
Collapse
X
-
Data from another timeframe
Hello,
New to Ninja. I want to create a generic function like moving average but I want to be able to access it for different timeframes. How would I do that?Tags: None
-
Data from another timeframe
Hello sunman4008,
Thanks for writing in to our Support team.
You can use the BarsArray method to access data series that were added via the AddDataSeries() method.
Code:protected override void OnStateChange() { if (State == State.SetDefaults) { Name = "Examples Indicator"; } else if (State == State.Configure) { // Add a 5 minute Bars object which is added to the BarArray // which will take index 1 since the primary Bars object of the strategy // will be index 0 AddDataSeries(BarsPeriodType.Minute, 5); } } protected override void OnBarUpdate() { // Ignore bar update events for the supplementary Bars object added above if (BarsInProgress == 1) return; // Pass in a Bars object as input for the simple moving average method // Evaluates if the 20 SMA of the primary Bars is greater than // the 20 SMA of the secondary Bars added above if (SMA(20)[0] > SMA(BarsArray[1], 20)[0]) EnterLong(); }
http://ninjatrader.com/support/helpG.../barsarray.htm
You can also refer to this forum post that goes over how to submit orders to different bar objects/time frames:
http://ninjatrader.com/support/forum...ead.php?t=5787
You should also keep in mind that when accessing a secondary data series it is sometimes necessary to wait for data using
Code:if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
Alan S.NinjaTrader Customer Service
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by algospoke, Yesterday, 06:40 PM
|
2 responses
24 views
0 likes
|
Last Post
by algospoke
Today, 07:04 PM
|
||
Started by ghoul, Today, 06:02 PM
|
3 responses
15 views
0 likes
|
Last Post Today, 06:43 PM | ||
Started by jeronymite, 04-12-2024, 04:26 PM
|
3 responses
46 views
0 likes
|
Last Post
by jeronymite
Yesterday, 10:10 PM
|
||
Started by Barry Milan, Yesterday, 10:35 PM
|
7 responses
23 views
0 likes
|
Last Post Today, 06:16 PM | ||
Started by AttiM, 02-14-2024, 05:20 PM
|
10 responses
181 views
0 likes
|
Last Post
by jeronymite
Today, 06:11 PM
|
Comment