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!
See more
See less

Partner 728x90

Collapse

Parsing variables from one indicator to another

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Shannon, for this I would suggest then doing it on the first tick of the next bar, this way you can be sure the previous one is actually closed. To do this just put your code in if (FirstTickOfBar) ....
    BertrandNinjaTrader Customer Service

    Comment


      #17
      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


        #18
        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


          #19
          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


            #20
            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


              #21
              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));
               }
              Thus allowing the use of the indicator LiveSPTs(secondarySeries,10).IPriorPeakHigh[0] to recall information SYNCED to the primary bar object (primarySeries)?
              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]); ????
               }
              Thanks again
              Shannon

              Comment


                #22
                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


                  #23
                  All,

                  Is it possible to parse an array from one indicator to another or to a strategy?

                  In the same fashion IntSeries or DataSeries can be made public and parsed, can a array be parsed? If so how?

                  As always, thanks
                  Shannon

                  Comment


                    #24
                    Originally posted by Shansen View Post
                    ...In the same fashion IntSeries or DataSeries can be made public and parsed, can a array be parsed?...
                    Yes 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:

                    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


                      #25
                      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


                        #26
                        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


                          #27
                          Originally posted by Shansen View Post
                          ...the array to be parsed would be multi-dimentional...
                          Please consider that passing an array by a property will propably copy the content of the array. That is desired only if you intent to modify the copy without modifying the source data-structure. In all other cases that's not efficient. <DataType> in my example could be any data structure (i.e. a class or a structure), which implements as much dimensions as you desire.

                          Regards
                          Ralph

                          Comment


                            #28
                            Originally posted by Ralph View Post
                            Yes 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: .....
                            Ralph,

                            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


                              #29
                              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


                                #30
                                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;
                                  ...
                                The below code creates private iPeaks iTroughs Lists and the public IPeaks ITroughs Lists:

                                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
                                  }
                                }
                                I know it's something small I'm missing. Any assistance would be appreciated.

                                Regards
                                Shannon

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by BarzTrading, Today, 07:25 AM
                                2 responses
                                15 views
                                1 like
                                Last Post BarzTrading  
                                Started by devatechnologies, 04-14-2024, 02:58 PM
                                3 responses
                                19 views
                                0 likes
                                Last Post NinjaTrader_BrandonH  
                                Started by tkaboris, Today, 08:01 AM
                                0 responses
                                3 views
                                0 likes
                                Last Post tkaboris  
                                Started by EB Worx, 04-04-2023, 02:34 AM
                                7 responses
                                162 views
                                0 likes
                                Last Post VFI26
                                by VFI26
                                 
                                Started by Mizzouman1, Today, 07:35 AM
                                1 response
                                10 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Working...
                                X