• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Comparing bool arrays

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

    Comparing bool arrays

    I am attempting to compare 2 bool arrays and according to StackOverflow the following code should work:

    Code:
    static bool ArraysEqual<T>(T[] a1, T[] a2)
            {
                if (ReferenceEquals(a1,a2))
                    return true;
    
                if (a1 == null || a2 == null)
                    return false;
    
                if (a1.Length != a2.Length)
                    return false;
    
                EqualityComparer<T> comparer = EqualityComparer<T>.Default;
                for (int i = 0; i < a1.Length; i++)
                {
                    if (!comparer.Equals(a1[i], a2[i])) return false;
                }
                return true;
            }
    Code:
    method call:
         bool areArraysEqual = ArraysEqual(userDefinedTrendRules, userTrendRulesMatched);
    The arrays sizes are the same and there are no null elements in either of them.

    The original question did not mention the array types and the responder did not ask which sort of implied is was not dependent upon the type.

    BTW, there were several other solutions but this one satisfied the original question.

    I know there are situations in mt test when all of the elements in the arrays are the same therefore the a true result should have been returned. All tests returned a false condition.

    Any help is appreciated.

    Also I believe there is a way to put the code into a "code" box that can be scrolled but I do not know how to do that and would appreciate someone showing me how.

    Thank you,

    Frank
    Last edited by Cheech; 03-10-2017, 12:44 PM. Reason: Put code in Code box

    #2
    Hello Frank,

    Thank you for your note.

    I would suggest adding print statements into that comparison to check if everything is being equated as true. I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:

    https://www.youtube.com/watch?v=K8v_...tu.be&t=48m45s

    If indeed you are, and would like to provide your script along with the two sets of arrays, I could test on our end and see if anything stands out. If you'd prefer to email a copy, send to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread, and the files.

    To put the code in a box in the forum you would click the advanced settings and then highlight the code and press the ## button. See screen shot.

    Please let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_AlanP View Post
      I would suggest adding print statements...
      Hi Alan:

      Thank you for your response.

      Concerning the Print statement, I already had Print statements that listed the elements in the arrays and the results of the array comparison in the code. That was how I had determined that there should have been some "true" results of the array comparison.

      Q. Is it your opinion that the code submitted should have worked? If so, I will re-verify the results here and make sure there are in fact there are situations that should have returned "true" results.

      If there are conditions that should evaluate to "true" then I will put a test case together that you can use and either send it to you via email or post it here.

      Comment


        #4
        Hi Alan:

        An update,

        Upon a re-validation I noticed that I missed setting one of the elements in an array. The array comparison code listed works fine. What a difference a bit makes. Thanks for making me revisit my testing.

        Problem solved

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CDXTrader, Today, 12:29 AM
        0 responses
        1 view
        0 likes
        Last Post CDXTrader  
        Started by TopGun13, Yesterday, 10:35 PM
        0 responses
        1 view
        0 likes
        Last Post TopGun13  
        Started by Audiofail, Yesterday, 05:40 AM
        6 responses
        18 views
        0 likes
        Last Post willwin
        by willwin
         
        Started by jerblaster23, Yesterday, 03:42 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by brian meade, Yesterday, 01:39 PM
        2 responses
        11 views
        0 likes
        Last Post brian meade  
        Working...
        X