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

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, 01: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:

    Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


    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 hurleydood, 09-12-2019, 10:45 AM
        15 responses
        1,097 views
        0 likes
        Last Post Leeroy_Jenkins  
        Started by danieldunn2024, Today, 03:06 AM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by cre8able, Yesterday, 04:16 PM
        1 response
        16 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cre8able, Yesterday, 04:22 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by stafe, 04-15-2024, 08:34 PM
        5 responses
        28 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X