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
Parsing variables from one indicator to another
Collapse
X
-
Bertrand,
Thanks for pointing me towards the SampleDataSeries example.
In the example, the two DataSeries "primarySeries" and "secondarySeries" each retained a single piece of information, via "Set" statements, from the relevant bar objects (i.e. Close[0] - Open[0]).
The indicator I am trying to draw from contains six public DataSeries and six IntSeries I wish to utilize from within the strategy. Do I need to declare 12 variables in the strategy to hold each of the elements I require, and 24 variables where I have a third bar object?
Suggestions on how to attack this problem are more than welcome.
Regards
Shannon
Comment
-
Shannon, this is just an example getting two synched calculations for two different time frames to align when called in the multiseries strategy context. Just call your indicator on the needed bars object and then sync the datseries object holding the return values to the primary one used on the strategy as per the sample.BertrandNinjaTrader Customer Service
Comment
-
Bertrand,
I'm sorry, I'm a little slow on the uptake here. I don't quite understand your post.
In the below code the custom indicator I'm trying to call "LiveSPTs" has six public DataSeries and six public IntSeries as "results". Previously this information was access (though critically not synced) along the lines of LiveSPTs(10).CurrentTroughLow[0], Live SPTs(10).CurrentPeakHigh[1], etc.
Put simply, I don't know how to "set" the secondarySeries in such a fashion allow retrieval or or subsequent calculation of the six DataSeries or six IntSeries contained therein.
Again, any assistance would be appreciated.
Regards
Shannon
Code:#region Vairables // Declar DataSeries objects private DataSeries primarySeries; private DataSeries secondarySeries; #endregion protected override void Initialize() { // BARS OBJECT 0 - The chart the strategy was applied to. // Sync a DataSeries object to the primary bar object primarySeries = new DataSeries(this); // BARS OBJECT 1 - Longer-term CASH Bars object Add("^SP500",PeriodType.Minute,macroPeriod); CalculateOnBarClose = false; } protected override void OnBarUpdate() { // Sync another DataSeries object to the secondary bar object if (secondarySeries == null) { secondarySeries = new DataSeries(SMA(BarsArray[1],10)); } // Execute on the first tick of secondary bar updates only if (BarsInProgress == 1 && FirstTickOfBar) { secondarySeries.Set (LiveSPTs(10)[0]); [B]????[/B] } if (BarsInProgress != 0) return; .... }
Comment
-
Shannon,
I am not sure what you mean by "allow retrieval or subsequent calculation of the six DataSeries or six IntSeries". From a strategy, you can't set the indicators Data/IntSeries. You can only access them. To do so all you have to do is call the particular series you want to access.
LiveSPT(10).SomeSeries[0]Josh P.NinjaTrader Customer Service
Comment
-
Josh,
Thanks for the reply. I should have been more complete in my explanation.
I am able to recall the Data/IntSeries of the custom indicator in question “LiveSPTs” (e.g. LiveSPTs(10).IPriorPeakHigh[0] ). The issue I have is this indicator is run in a multi-time frame strategy on the secondary bar object. I am having trouble syncing the secondary bar object to the primary bar object and then recalling the above mentioned Data/IntSeries of the indicator.
Referring to the code in my prior post, is the section below sufficient to sync the secondary bar object (secondarySeries) to the primary bar object (primarySeries)?
Code:// Sync another DataSeries object to the secondary bar object if (secondarySeries == null) { secondarySeries = new DataSeries(SMA(BarsArray[1],10)); }
Alternatively, referring to the code in my prior post, is a section similar to below required to “Set” the secondarySeries before the secondary bar object (secondarySeries) is synced to the primary bar object (primarySeries).
Code:// Execute on the first tick of secondary bar updates only if (BarsInProgress == 1 && FirstTickOfBar) { secondarySeries.Set (LiveSPTs(10)[0]); ???? }
Shannon
Comment
-
Shannon, the first snippet would sync it to the provided BarsArray, hence it does not matter which indicator you use, but it must point to proper BarsArray for the sync to take place.
Once this is done, you can work with the dataseries and fill it with your custom indicator values.BertrandNinjaTrader Customer Service
Comment
-
Originally posted by Shansen View Post...In the same fashion IntSeries or DataSeries can be made public and parsed, can a array be parsed?...
But, here is a but: As far as I can see, arrays are copied when accessed. Usually I don't like this approach, because I find it not efficient for most of my applications. For that reason I store the concerning data in a generic list and define a public property for this list:
public List<DataType> MyList
{
get { return myList; }
set { myList = value; }
}
myList is declared somewhere in the variable section:
public List<DataType> myList = new List<DataType>();
Regards
Ralph
Comment
-
Ralph,
Thanks for the reply.
I should have been more specific, the array to be parsed would be multi-dimentional. Also, is it still possible to sync the parsed array in the same fashion as DataSeries and IntSeries in a multi-time frame strategy?
Again, thanks
Shannon
Comment
-
Shannon,
I would imagine you should be able to pass it just fine as long as you make your public object multi-dimensional too. You could try doing the Update() for this too. Update() forces an OnBarUpdate() to try and sync it so it shouldn't matter that it isn't a DataSeries. Of course this is beyond the scope of what I can provide support for so I have not tested this, but in theory I believe it should work.Josh P.NinjaTrader Customer Service
Comment
-
Originally posted by Shansen View Post...the array to be parsed would be multi-dimentional...
Regards
Ralph
Comment
-
Originally posted by Ralph View PostYes Shannon, there is no big difference. You define a public property as array and can access its elements from the outside of that class like any other element.
But, here is a but: As far as I can see, arrays are copied when accessed. Usually I don't like this approach, because I find it not efficient for most of my applications. For that reason I store the concerning data in a generic list and define a public property for this list: .....
I'm currently attempting to implement your idea of using Lists. I've hit a minor snag simply working with Lists (as opposed to ArrayLists) in the indicator.
Any recommendations on effectively cloning a List. Arraylists have the method .Clone which makes it easy but this does not work with Lists. Is the answer to work with Arraylists within an indicator then convert the ArrayList to a Public List for parsing?
Regards
Shannon
Comment
-
Hi Shannon,
avoid coversion between containers as much as possible. You clone a list by construction:
public List(IEnumerable<T> collection)
Just pass your old list variable during construction of the new one. That works for every container implementing the IEnumerable-Interface. For example, you could pass an array list too.
Regards
Ralph
Comment
-
Ralph,
With your help the code was working.... but I've done something that's broken it all. The created Lists appear to be fine within one indicator but return as null when parsed to another indicator. The latter (receiving) indicator attempts to access the public IPeaks and ITroughs Lists via the code:
Code:#region Variables private List<int> Peaks = new List<int>(); private List<int> Troughs = new List<int>(); #endregion protected override void OnBarUpdate() ... Peaks = LiveSPTs([I]argument[/I]).IPeaks; Troughs = LiveSPTs([I]argument[/I]).ITroughs; ...
Code:#region Using declarations using System.Collections.Generic; #endregion public class LiveSPTs : Indicator { #region Variables // Lists private List<int> iPeaks = new List<int>(); private List<int> iTroughs = new List<int>(); #endregion protected override void Initialize() { // Initialise Variables for (int x = 0; x < 15; x++) { iPeaks.Add(2); iTroughs.Add(1); } } protected override void OnBarUpdate() { if (CurrentBar < 100) return; // Stuff happens followed by iPeaks List being set the same as a Peaks List iPeaks = Peaks.GetRange(0, Peaks.Count); // Other stuff happens followed by iTroughs List being set the same as Troughs List iTroughs = Troughs.GetRange(0, Troughs.Count); // Test all is well in iPeaks and iTroughs Lists Print (""); Print (Time.ToString()); string sPeaks = ""; for (int i = 0; i < iPeaks.Count; i++) sPeaks = sPeaks + Time[CurrentBar - iPeaks[i]].ToString() + ", "; Print ("Peaks " + CPs); string sTroughs = ""; for (int i = 0; i < iTroughs.Count; i++) sTroughs = sTroughs + Time[CurrentBar - iTroughs[i]].ToString() + ", "; Print ("CTs " + CTs); } #region Properties [Browsable(false)]// this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()]// this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public List<int> IPeaks { get { return iPeaks; } } [Browsable(false)] [XmlIgnore()] public List<int> ITroughs { get { return iTroughs; } } #endregion } }
Regards
Shannon
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by adeelshahzad, Today, 03:54 AM
|
3 responses
16 views
0 likes
|
Last Post Today, 09:43 AM | ||
Started by yertle, Today, 08:38 AM
|
4 responses
13 views
0 likes
|
Last Post
by yertle
Today, 09:38 AM
|
||
Started by bill2023, Yesterday, 08:51 AM
|
6 responses
27 views
0 likes
|
Last Post Today, 09:37 AM | ||
Started by NinjaTrader_ChelseaB, 01-08-2017, 06:59 PM
|
80 responses
19,667 views
5 likes
|
Last Post Today, 09:29 AM | ||
Started by dappa, Today, 09:18 AM
|
1 response
6 views
0 likes
|
Last Post Today, 09:25 AM |
Comment