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

Importing an element from a public variable

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

    Importing an element from a public variable

    NT Team,

    I've a situation where an indicator produces a generic integer list as a public variable, another indicator calls this public variable and sets a generic integer list private variable to equal the public variable. The indicator then works with the elements of the private variable.

    Is it possible to call the integer in [0] of the generic list public variable and set a private integer variable to equal the integer in [0] of the public variable?

    Thanks and regards
    Shannon

    #2
    Hi Shansen,

    I am not sure what is the exact issue you are having here. I use lists often and there are no problems. This should be relatively easy to do. Perhaps if you send a code snippet I may be able to help better.

    Generally speaking myList[0] retrieves the first or zero value so

    int myIntValue = myList[0];

    should work for you unless I am missing the nature of the issue here. Hope this helps.

    Comment


      #3
      Zeos6,

      Thanks for your reply.

      I agree with your point, and this approach works as expected. However, as this element is called from another indicator, I have tried to ensure the other indicator is "run" to ensure the public variable is correct before calling the variable (as in the commented out portion in the properties section of the code below). The issue is with this commented out code.
      Code:
          #region Variables
            private int iCurrentPeak;  
          #endregion
          
          protected override void Initialize()
          {
            iCurrentPeak = (int)SPTs(false, sTMA).ICurrentPeaks[0];               
          }
      
          #region Properties
      //    [Browsable(false)]  
      //    [XmlIgnore()]    
      //    public List<int> ICurrentPeaks
      //    {
      //      get { Update(); return iCurrentPeaks; } 
      //    }    
          #endregion


      Any ideas would be much appreciated.

      Regards
      Shannon

      Comment


        #4
        Hi Shannon,

        One way you can achieve what you are after is using event driven programming with a single cast delegate and an event handler. I will try to put together a code sample for you.
        I also had a thought that this could be done in a simpler manner. Why not create a bool variable in the indicator you need to execute first, say bool indicator1Flag, and expose that bool variable to the second indicator. Then use a simple

        if(!indicator1Flag) return; at the start of indicator 2 code.

        The real issue is whether you need the 2nd indicator to force the first indicator to run.
        Last edited by Zeos6; 06-16-2011, 08:13 AM.

        Comment


          #5
          Zeos6 & NT Team,

          Please confirm my understanding of the update() method:

          Indicator "A" publishes several public variables (in the below example ICurrentPeaks represents one of the public variables). Indicator "B" calls these variables from "A" and uses the Update() method in its properties section, as below.
          Code:
          public List<int> ICurrentPeaks
          {
            get { Update(); return iCurrentPeaks; } 
          }
          Does the Update() method effectively update ALL public variables published by indicator "A"?

          Regards
          Shannon

          Comment


            #6
            Shannon, you will need Update() in each public variable you're accessing/want updated.
            AustinNinjaTrader Customer Service

            Comment


              #7
              Hi Shannon,

              My understanding is that Update() forces synchronization. I am not sure whether it will do what you want because it is near impossible to sequence thread execution or processing execution which is what I believe you are looking for (unless I am really missing the boat here). I am concerned that using Update() may not guarantee that indicator 1 was executed before it is accessed by indicator 2 which is what I believe you are looking for. In any case try it and see if it works for you.

              If you need to ensure that indicator 1 is executed first before it is accessed by indicator 2, I would push a flag from indicator 1 to 2 (and use Update() on the flag variable) and then use an if statement to ensue that the public variable in indicator 2 is accessed only if the flag from indicator 1 is true. Let me know how it goes. If that does not work then we're into delegates, but I am rying to avoid the complexity. Hope this helps.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by alifarahani, Today, 09:40 AM
              0 responses
              1 view
              0 likes
              Last Post alifarahani  
              Started by Gerik, Today, 09:40 AM
              0 responses
              1 view
              0 likes
              Last Post Gerik
              by Gerik
               
              Started by RookieTrader, Today, 09:37 AM
              0 responses
              5 views
              0 likes
              Last Post RookieTrader  
              Started by KennyK, 05-29-2017, 02:02 AM
              3 responses
              1,282 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by AttiM, 02-14-2024, 05:20 PM
              11 responses
              184 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X