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

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 techgetgame, Yesterday, 11:42 PM
        0 responses
        8 views
        0 likes
        Last Post techgetgame  
        Started by sephichapdson, Yesterday, 11:36 PM
        0 responses
        2 views
        0 likes
        Last Post sephichapdson  
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,615 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Yesterday, 05:56 PM
        0 responses
        10 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        20 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Working...
        X