Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

List size changed automatically, what's wrong?

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

    List size changed automatically, what's wrong?

    Hi Folks,

    I am implementing an indicator on NT7 platform. This indicator does some calculation then assign it a BarType to indicate it is Up or Down. Inside the Indicator program, I try to maintain the last 4 groups of the bars.

    When the coming bar is the same color as 1st bar cluster, it will be added into the 1st cluster automatically. However, if the bar is a different color, it will wait the 2nd bar close to make the decision. If the 2nd bar is also different to the color of 1st cluster (aka 2nd bar is the same color as its previous one), then I shift 3rd cluster to the 4th, the 2nd cluster to the 3rd, 1st cluster to the 2nd, 1st cluster is cleared before the two new bars are added.

    I have debugged to make sure the bars in the 1st cluster are all correct. However, something very strange happened. Though I have only 1 place to manipulate the values of those clusters, it is assigned somewhere else. I have tracked the debug message and captured the output window together with the source code.

    Please help me on this. It is really strange. I suspect I missed something important in the big picture. But I have no idea what it is.

    Thank you very much!!!


    Best Regards
    David
    Attached Files
    Last edited by sinpeople; 08-22-2020, 08:17 AM.

    #2
    Hmm, I looked at your code ...

    I noticed something that seemed a bit odd to me.

    After you Clear() the cluster, you reassign the object reference to
    the next lower cluster. Seems strange, why do that?

    Here is the code, I removed your comments and Prints, and
    added some new comments,

    Code:
    _4thCluster.Clear();
    _4thCluster = _3rdCluster;  // 4th now refers to same as 3rd
    _3rdCluster.Clear();
    _3rdCluster = _2ndCluster;  // 3rd now refers to same as 2nd
    _2ndCluster.Clear();
    _2ndCluster = _1stCluster;  // 2nd now refers to same as 1st
    _1stCluster.Clear();
    _1stCluster.Add(_undecidedBar);
    _undecidedBar = null;
    _1stCluster.Add(_bar);

    At the end of first execution of this code, the 2nd and 1st have the same reference.
    PHP Code:
    +------------+
    |  Orig 4th  |
    +------------+
    |  Orig 3rd  |  <-- _4thCluster
    +------------+
    |  Orig 2nd  |  <-- _3ndCluster
    +------------+
    |  Orig 1st  |  <-- _2ndCluster and _1stCluster
    +------------+ 
    

    At the end of second execution, you can see how they start to bunch up,
    PHP Code:
    +------------+
    | Orig 4th   |
    +------------+
    | Orig 3rd   |
    +------------+
    | Orig 2nd   | <-- _4thCluster
    +------------+
    | Orig 1st   | <-- _3rdCluster and _2ndCluster and _1stCluster
    +------------+ 
    


    I would venture to say you don't intend for this 'bunching up' effect to happen.

    Perhaps you mean to change the list reference inside each cluster object,
    rather than changing the cluster object to reference the next cluster object?

    That is, did you mean to,
    change the cluster's _barCluster list object to reference the next cluster's _barCluster list object?
    Last edited by bltdavid; 08-22-2020, 10:17 AM.

    Comment


      #3
      Originally posted by bltdavid View Post
      That is, did you mean to,
      change the cluster's _barCluster list object to reference the next cluster's _barCluster list object?
      Also,
      You may to want to copy the list contents, versus change the list references -- otherwise you
      might be shifting the 'bunching up' effect from the cluster references into the list references.

      Good luck!

      Comment


        #4
        Hello David,

        I think bltdavid is right. You may be assigning the reference to the list and not values of the list.

        When assigning a List object held in one variable to another, try using .ToArray and copying the values to an array.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 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
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X