Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Disposing Array <List>

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

    Disposing Array <List>

    I have a script where I store swing highs/lows in an array list, in order to use them to do calculations in the future. I know that I should be disposing the array list, but I am not sure where. I am using it in an indicator.

    Any ideas

    The basic idea of the code is something like this

    private ArrayList swinghighs = new ArrayList();

    if (High[0] > SwingHigh)
    swinghighs.Insert(0, High[0];
    bool swing_broken = true;
    ....

    if (Low[0] < swinghighs[0] && swing_broken == true)
    Print ( High Retested)

    PS - Does anyone know how I can store more information in the ArrayList, for example the time the high was made, or the SMA(5) at the time? Do i need to insert that information into an array and then insert the array into the list? I would think there is an easier way.

    Thank you kindly programming masters of the universe ;-)

    #2
    You can just set the ArrayList to null, swinghighs = null; and the garbage collector will clean it up. You can put that whenever you are done with it, or in OnTermination().

    As for your second question. You can make a class that has members for the information you want to hold, and then use a List<T> of that class to store each instance.

    VT
    Last edited by VTtrader; 11-21-2011, 08:05 PM.

    Comment


      #3
      thanks VTrader, I will use the OnTermination (didnt know about that call) since I keep the indicator running all day and I need to get previous stored values on each bar update...

      I was thinking about making a class for the array list, but I am not sure where I would store the class file and if I could easily call if from NT? Also I've seen a few example of DLL files not sure if that is better.

      I'm going to search around for some examples but ifyou know of any please pass them along,, thanks

      Comment


        #4
        eurostoxx,

        You can put the class definition in UserDefinedMethods.
        Something like this:
        public class SwingPoints
        {
        public string SwingHL { get; set; }
        public DateTime SwingTime { get; set; }
        public double SwingPrice { get; set; }
        public double MovAvg { get; set; }

        public SwingPoints(string shl, DateTime st, double sp, double ma)
        {
        this.SwingHL = shl;
        this.SwingTime = st;
        this.SwingPrice = sp;
        this.MovAvg = ma;
        }
        }

        For your list you will want to use a List<T>, which in this case would be List<SwingPoints>.

        In your indicator you would instantiate your list like this: List<SwingPoints> mySwings = new List<SwingPoints>();

        and populate it like this:
        mySwings.Add(new SwingPoints("High", Time[0], price, maValue));

        Hope this helps.

        VT

        Comment


          #5
          wow thank you so much..thats helps tremendously, I would have never figured out to put the class definitions there

          I also appreciate the examples.. the notation saves me a lot of time fixing errors.

          You are amazing!

          Comment


            #6
            Originally posted by eurostoxx trader View Post
            wow thank you so much..thats helps tremendously, I would have never figured out to put the class definitions there

            I also appreciate the examples.. the notation saves me a lot of time fixing errors.

            You are amazing!
            one pitfall of writing custom codes in UserDefinedMethod is if you import any other codes which also uses the same, chances that the same may be overwritten, thus you will lose all your codes. So its better to crate a separate file.

            btw the main usp of the userdefinedmethod is that it is the extension of the Indicator class (which is a partial class).

            if you are using your custom classes for a particular indicator only and not serializing it then instead of a public class create a private class and put all the codes in the indicator itself.

            just my 2˘

            Comment


              #7
              cool, I think that worked too. I just added the class below the indicator class, in the indicator C# file (though above the NT do not remove stuff) and it compiled. Is that what you meant?

              I still have to test that it works but cheers for the tip. Its easier to transport indicators this way, as I am running NT on more than 1 pc, so its great

              PS NT wouldnt let me call the class private.

              Comment


                #8
                eurostoxx,

                It depends on where you put it. to use the private access modifier you would need to put it before the closing "}" for the indicator class. IOW, after the Properties region and before the following "}".

                Comment


                  #9
                  thanks guys for the help.. this is really starting to simplify my code

                  is there a way to pass variable /NT data from the indicator into my newly created class so I can do some caluclation on the class properties vs just {get;set}.. I can figure out how to do the operations to set the property but I cant pass any values from the main NT indicator into the class.

                  Thanks again

                  Example

                  public string SwingHL { get; set; } //input high or low
                  public DateTime SwingTime { get; set; }
                  public double SwingPrice { get; set; }

                  public double SwingTHpricee
                  {
                  get
                  {
                  swingTHpricee = SwingPrice + threshold_level_retest; // this varialbe is defined by the user
                  return swingTHpricee;
                  }
                  }

                  Comment


                    #10
                    Originally posted by eurostoxx trader View Post
                    thanks guys for the help.. this is really starting to simplify my code

                    is there a way to pass variable /NT data from the indicator into my newly created class so I can do some caluclation on the class properties vs just {get;set}.. I can figure out how to do the operations to set the property but I cant pass any values from the main NT indicator into the class.

                    Thanks again

                    Example

                    public string SwingHL { get; set; } //input high or low
                    public DateTime SwingTime { get; set; }
                    public double SwingPrice { get; set; }

                    public double SwingTHpricee
                    {
                    get
                    {
                    swingTHpricee = SwingPrice + threshold_level_retest; // this varialbe is defined by the user
                    return swingTHpricee;
                    }
                    }
                    To do that, you would have to nest your helper class inside the main class for the indicator.

                    Comment


                      #11
                      thanks koganam, but do you know where exactly I can nest it (above or below some specific reference in the standard code). I keep getting the following error

                      Cannot access a non-static member of outer-type "Indicator.Name vis nested type "Indicator Name.SwingPoints (the class)" error message

                      I;ve tried placing it above the properties

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      571 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      330 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      101 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      548 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      549 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X