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

    #31
    You could try to insert an Update() in your property statement.
    Not sure it helps because you fill your lists with Initialize() already, but you could give it a try.

    public List<int> IPeaks
    {
    get { Update(); return iPeaks; }
    }

    Regards
    Ralph

    Comment


      #32
      Ralph,

      You are a genius. I hope one day to have your smarts with this coding.

      Clearly your "Update();" idea worked a treat. I don't know why it worked but I am very happy it did. I will endeavour to understand more in this area.

      Again, thanks a bunch.
      Shannon

      Comment


        #33
        Good Morning Shannon,

        the reason why Update() helps and is needed is because the Indicators are processed in parallel by NT. In reality that means, a tick arrives and then NT updates every Inicator, one after the other. That means if your source indicator is updated before your destination indicator, then you get incorrect results. Update() somehow modifies the order of execution if needed.

        Regards
        Ralph

        Comment


          #34
          Ralph,

          The generic list has worked a treat in the indictor and being parsed to another indicator. Same information needs to be parsed to a strategy, which in itself is not a problem.

          It is a multi-timeframe strategy that would grab info from the indicator in question over several timeframes. Again, not a problem. However, the strategy then performs identical functions for each of the timeframes.

          I imagine a multi-dimensional array would be one way to get all the information in and identified easily by later calculations (BarsInProgress 0 on row 0, each of the list items in column 0,1,2,3, etc; BarsInProgress 1 on row 1, each of the list items in column 0,1,2,3, etc).

          There appears to be some capacity in the generic list method to accommodate this kind of structure. To your knowledge, would this be the way to go? Or something different entirely.

          As always any guidance would be appreciated.
          Regards
          Shannon

          Comment


            #35
            Hi Shannon,

            a multi-dim-array would do that, but be aware: passing an array would mean passing a copy of that array. If these arrays getting big, then this coding style is in-efficient.

            What is the difference between providing data from that "list"-indicator for a single-timefram-strategy or a multi-timeframe-strategy? I didn't understood how you would like to structure the data provided by the indicator to serve that multi-timeframe approach. How does the inidcator know what timeframes to consider?

            Regards
            Ralph

            Comment


              #36
              Ralph,

              The indicator is accessed via a strategy. The indicator public IntSeries and public DataSeries are saved as items in several arrays. The arrays are populated so that a particular timeframe's data is held in the same item number in each array. (e.g. the Peak and Trough of the secondarySeries would be held in Peak[1] and Trough[1], the tertiarySeries in Peak [2] and Trough [2])

              Code:
              #region Variables
                private int[] Peak;
                private int[] Trough;
              #endregion
              protected override void Initialize()
              {
                Peak = new int[4];
                Trough = new int[4];
              }
              
              
              protected override void OnBarUpdate()
              {
                // Sync another DataSeries object to the secondary bar object
                if (secondarySeries == null)
                {
                  secondarySeries = new DataSeries(SMA(BarsArray[1],10));
                }
                // Sync another DataSeries object to the tertiary bar object
                if (tertiarySeries == null)
                {
                  tertiarySeries = new DataSeries(SMA(BarsArray[2],10));
                }
                
                // Execute on the first tick of BarsInProgress and populate appropriate element of respective array  if (FirstTickOfBar)
                {
                  if(BarsInProgress >= 0 && BarsInProgress <= 2) 
                  {
                    if (CurrentBar < 100)
                      return;
                    Peak[BarsInProgress] = LiveSPTs.IPeak[1];
                    Trough[BarsInProgress] = LiveSPTs.ITrough[1];
              	etc...
                  }
                }
              }
              As always ideas are welcome
              Thanks
              Shannon

              Comment


                #37
                Hi Shannon,

                the indicator we are talking about is LiveSPTs? And you want to return not only single integer values with every access, but a multi-dimensional data structur which holds the values for every timeframe of IPeak and IThrough? And IPeak and IThrough are integer lists (List<int>)?

                Regards
                Ralph

                Comment


                  #38
                  Ralph,

                  The Strategy currently records and accesses, for example, the latest Peak for each time via the Peak array where:
                  Peak[0] = Current Peak from BarArray[0]
                  Peak[1] = Current Peak from BarArray[1]
                  Peak[2] = Current Peak from BarArray[2]

                  The location of peaks in terms of time (barnumber) is an integer Array. A separate Array (double) following the same concept is used to record and access the price value of each peak.

                  So, I though it would be possible to go one step further:
                  Peak[0,0]; [0,1]; [0,2]; [0,3] = Current and prior Peaks from BarArray[0]
                  Peak[1,0]; [1,1]; [1,2]; [1,3] = Current and prior Peaks from BarArray[1]
                  Peak[2,0]; [2,1]; [2,2]; [2,3] = Current and prior Peaks from BarArray[2]

                  I'm pretty sure the above would be possible, but have no concept on what else is possible in the generics and thus what should be done in terms of good programming.

                  The indicator previously had public variables IPeak and ITrough as integers (the latest peak only). It has been re-coded so that IPeak and ITrough are integer lists (List<int>), and contain up to 15 of the previous peaks / troughs (15 was arbitrarily chosen).

                  Thank you for your patience.
                  Shannon
                  Last edited by Shansen; 03-27-2010, 05:50 AM.

                  Comment


                    #39
                    Let me try a summary:

                    1) The indicators provide generic lists (List<int>) through IPeak and IThrough.
                    2) Every Indicator represents a certain timeframe. There are as many indicators instantiated as timeframes exist.
                    3) You now want to "bundle" these lists in multi-dimesional data structures, one for each of Peak and Through. For example, Peak is a multi-dimensional data structure holding a list of peak-values for each of the timeframes. Same is true for Through.

                    Is that correct?

                    Regards
                    Ralph

                    Comment


                      #40
                      Ralph,

                      1) The indicator, LiveSPTs, (singular) provides generic lists (List<int>) through IPeak and ITrough.
                      2) The single indicator, LiveSPTs, is called for each timeframe by the Strategy.
                      3) I now want to "bundle" these lists in multi-dimesional data structures, one for Peak and one for Trough. For example, Peak is a multi-dimensional data structure holding a list of peak-values for each of the timeframes. Same is true for Trough.

                      Apologies for my lack of clarity.

                      Shannon
                      Last edited by Shansen; 03-27-2010, 05:47 PM.

                      Comment


                        #41
                        Hi Shannon,

                        here is how I would apply what we have discussed so far:
                        Code:
                        [FONT=Courier New][COLOR=blue]private[/COLOR] int timeframeCount = 4;[/FONT]
                        [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] List<[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]>[] timeframeArray;[/SIZE][/FONT][/SIZE][/FONT]
                        [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]private IndiType[] indiArray;[/SIZE][/FONT]
                        [/SIZE][/FONT][FONT=Courier New]...[/FONT]
                        [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][FONT=Courier New]protected[/FONT][/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] OnBarUpdate()[/SIZE][/SIZE][/FONT]
                        [FONT=Courier New][SIZE=2][SIZE=2]{[/SIZE][/SIZE][/FONT]
                        [FONT=Courier New] if (CurrentBar == 0 && FirstTickOfBar)[/FONT]
                        [FONT=Courier New] {[/FONT]
                        [FONT=Courier New]   indiArray = [COLOR=#0000ff]new[/COLOR][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] IndiType[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]timeframeCount[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]];[/SIZE][/FONT][/SIZE][/FONT][/FONT]
                        [FONT=Courier New]   [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]timeframeArray = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] List<[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]>[timeframeCount[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]];[/SIZE][/FONT][/SIZE][/FONT][/FONT]
                        [FONT=Courier New]   for (int i = 0; i < timeframeCount; i++)[/FONT]
                        [FONT=Courier New]     indiArray[i] = LiveSPTs(BarsArray[i]);[/FONT]
                        [FONT=Courier New][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]     timeframeArray[i] = indiArray[i].IPeak;[/SIZE][/FONT][/SIZE][/FONT][/FONT]
                        [FONT=Courier New] }[/FONT]
                        [FONT=Courier New] // Application example[/FONT]
                        [FONT=Courier New] Print("BarsInProgress: " + BarsInProgress);[/FONT]
                        [FONT=Courier New] indiArray[BarsInProgress].Update();[/FONT]
                        [FONT=Courier New] Print("First IPeak list element: " + timeframeArray[BarsInProgress][0])[/FONT]
                        [FONT=Courier New] Print("Last IPeak list element: " + timeframeArray[BarsInProgress][timeframeArray[BarsInProgress].Count - 1]);[/FONT]
                        [FONT=Courier New][SIZE=2][SIZE=2]}[/SIZE][/SIZE][/FONT][SIZE=2]
                        [/SIZE]
                        This code is not tested.
                        After the rather complex setup, applications are quite convenient.
                        Before accessing the list values of an indicator, I would recommend to update the indicator first (as shown in the code example). We have discussed the reasons for that already.
                        You can use the print statements to test if the data tranfer operates properly.

                        Now it is up to you to give it a try.

                        Regards
                        Ralph

                        Comment


                          #42
                          Ralph,

                          Thanks for all your help.

                          I've found the declaration of System.Collections.Generic is required for the generic List<int>[]. However, I can not get passed the below line of code. Is another declaration required to make it work?
                          Code:
                          private IndiType[] indiArray;
                          code

                          Again, thanks
                          Shannon

                          Comment


                            #43
                            Sorry Shannon, was a little fuzzy with my explanation. IndiType is the Type/ClassName of the indicator you evaluate with the different timeframe data series. In this particular case it is LiveSPTs, therefore the correct statements are:

                            private LiveSPTs[] indiArray;
                            ...
                            indiArray = new LiveSPTs[timeframeCount];

                            Regards
                            Ralph

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by kevinenergy, 02-17-2023, 12:42 PM
                            118 responses
                            2,777 views
                            1 like
                            Last Post kevinenergy  
                            Started by briansaul, Today, 05:31 AM
                            0 responses
                            4 views
                            0 likes
                            Last Post briansaul  
                            Started by fwendolynlpxz, Today, 05:19 AM
                            0 responses
                            4 views
                            0 likes
                            Last Post fwendolynlpxz  
                            Started by traderqz, Yesterday, 12:06 AM
                            11 responses
                            28 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by PaulMohn, Today, 03:49 AM
                            0 responses
                            8 views
                            0 likes
                            Last Post PaulMohn  
                            Working...
                            X