Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Correct but inaccessible List values are only visible in NinjaScript Output?

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

    Correct but inaccessible List values are only visible in NinjaScript Output?

    Good day,
    I have a List which correctly populates data after some operations.
    I also take these values at a double value which I see is correct...

    The usual C# commands for passing these correctly ordered and correctly calcuated values aren't working for me??? IDK what the best practices are?

    Only by printing to NinjaScript Output can I verify from indpendent test calculations that this list holds the correct values...




    Code:
    for (int i = 0; i < 256; i++)
    {
        barArrayList.Add(historicalPriceDensity[i]); 
    }
    
    [double CorrectLIST =0;
    for (int i = 0; i < barArrayList.Count; i++)
    {
        if (barArrayList[i] < bottomValue)
            barArrayList[i] = bottomValue;
        else if (barArrayList[i] > topValue)
            barArrayList[i] = topValue;
    
    CorrectLIST = barArrayList[i];
            
    }  
    
    Print("Correct List Values from the Double : " + CorrectLIST);
    
     Print("Correct List Values from the List :");
        foreach (double value in barArrayList)
        {
            Print(value.ToString("F3")); // Print each value with 3 decimal places
        }

    So I am able to see that the list barArrayList and the double CorrectLIST are holding the values I expect from my other calculators...

    However whenever I try to record these CORRECTLIST values into a series the typical C# functions like .Add or .Set even .Insert do not work for me...

    What is the best practice for populating a series with these Correct values I have ???
    Last edited by DynamicTest; 07-01-2024, 11:29 AM.

    #2
    Hello DynamicTest,

    I wanted to gather some additional details as its not clear from the sample where the problem is happening. I see you have a print that says correct list values, is that where you said that you are seeing in the output the correct list values? If so where are you trying to use the list that it is no longer correct?

    What you have now would be the correct way to use a C# list, you create an instance of the list and then use the Add method to add values to the list or use the indexing like you have.to update or get values from the list. The foreach loop you are using would be how to iterate the list without indexing, you could also use a for loop if indexing is needed.

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello DynamicTest,

      I wanted to gather some additional details as its not clear from the sample where the problem is happening. I see you have a print that says correct list values, is that where you said that you are seeing in the output the correct list values? If so where are you trying to use the list that it is no longer correct?

      What you have now would be the correct way to use a C# list, you create an instance of the list and then use the Add method to add values to the list or use the indexing like you have.to update or get values from the list. The foreach loop you are using would be how to iterate the list without indexing, you could also use a for loop if indexing is needed.
      Im sorry I was trying to use the correct language to show why this error was odd but I failed to edit my original post

      Comment


        #4
        Yes the reason I am seeking to know the proper procedure is because while I easily retrieve the proper List values and I can pass those proper list values to a double


        Code:
        double correctListValue=0;
        for (int i = 0; i < DynamicNoisePeriod; i++)
        {
            barArrayList.Add(historicalPriceDensity[i]);
        
        correctListValue = barArrayList[i];
        
        
        }
        
         Print(" Correct List Values from Double : " + correctListValue );
            foreach (double value in barArrayList)
            {
                Print(value.ToString("F6")); // Print each value with 2 decimal places
            }

        So you see while I debug I have all the correct values printing into the NinjaScript Output

        Unfortunately

        I have failures passing the values of this double OR the values from the List into a series with the typical C# commands mySeries.Insert(); mySeries.Add(); mySeries.Set() ; mySeries.Insert();

        TLDR;
        What is the best practice for going from a LIST to a SERIES???

        Comment


          #5
          I would not bother the experts here save for the unexpected errors caused me to doubt the best practice for the latest version... Thank You

          Comment


            #6
            Hello DynamicTest,

            I think I understand what is happening, you are trying to expose the list as a series is that correct?

            If so a series does not work like a list, the series is a direct result of the bars on the chart. The series will match the number of bars and is how you can use a barsAgo to get values for a specific bar. To expose a List of values for a given bar you would need to make a Series<List<double>>

            Once you do that you could assign 1 list per bar to the series


            Code:
            CorrectListOutput[0] = new List<double>();
            
            for (int i = 0; i < DynamicNoisePeriod; i++)
            {
               CorrectListOutput[0].Add(historicalPriceDensity[i]); // Add the NoiseATR value to the barArrayList
            }
            
            for (int i = 0; i < CorrectListOutput[0].Count; i++)
            {
               if (CorrectListOutput[0][i] < bottomValue)
                  CorrectListOutput[0][i] = bottomValue;
               else if (CorrectListOutput[0][i] > topValue)
                  CorrectListOutput[0][i] = topValue;
            
            }
            
            Print("Correct List Values:");
            foreach (double value in CorrectListOutput[0])
            {
                Print(value.ToString("F3")); // Print each value with 3 decimal places
            }
            ​​

            Comment


              #7
              I imagine you or another expert has used the values from lists after you created the list...
              What is your preferred method for accessing the values stored in the List???

              I have no preference myself, although Microsoft seems to favor certain List or Array functions for different cases... ???

              Comment


                #8
                Originally posted by NinjaTrader_Jesse View Post
                Hello DynamicTest,

                I think I understand what is happening, you are trying to expose the list as a series is that correct?

                If so a series does not work like a list, the series is a direct result of the bars on the chart. The series will match the number of bars and is how you can use a barsAgo to get values for a specific bar. To expose a List of values for a given bar you would need to make a Series<List<double>>

                Once you do that you could assign 1 list per bar to the series


                Code:
                CorrectListOutput[0] = new List<double>();
                
                for (int i = 0; i < DynamicNoisePeriod; i++)
                {
                CorrectListOutput[0].Add(historicalPriceDensity[i]); // Add the NoiseATR value to the barArrayList
                }
                
                for (int i = 0; i < CorrectListOutput[0].Count; i++)
                {
                if (CorrectListOutput[0][i] < bottomValue)
                CorrectListOutput[0][i] = bottomValue;
                else if (CorrectListOutput[0][i] > topValue)
                CorrectListOutput[0][i] = topValue;
                
                }
                
                Print("Correct List Values:");
                foreach (double value in CorrectListOutput[0])
                {
                Print(value.ToString("F3")); // Print each value with 3 decimal places
                }
                ​​
                Yes sir I absolutely need to take the values from the List to the series so that I can use the List values which are happening in the order of the Bars on the chart (and not any other ascending order)

                Now that I have the correct values in the correct order from other operation I need to use those values in a series!!!

                Comment


                  #9
                  Hello DynamicTest,

                  That depends on where the list is needed. If you just need the list inside this one script and need to access its values later a variable like you have would be suggested. If you define the variable inside OnBarUpdate that list will exist for 1 bar, if that variable is defined as a private variable it will retain a value over multiple bars. If the list needs to be exposed to other scripts then what I provided in my last reply is how to do that, you would end up with 1 list per bar. If the intention is to expose a single list to other scripts and not have 1 list per bar then a public List property would be needed for that.

                  Comment


                    #10
                    Originally posted by NinjaTrader_Jesse View Post
                    Hello DynamicTest,

                    That depends on where the list is needed. If you just need the list inside this one script and need to access its values later a variable like you have would be suggested. If you define the variable inside OnBarUpdate that list will exist for 1 bar, if that variable is defined as a private variable it will retain a value over multiple bars. If the list needs to be exposed to other scripts then what I provided in my last reply is how to do that, you would end up with 1 list per bar. If the intention is to expose a single list to other scripts and not have 1 list per bar then a public List property would be needed for that.
                    Oh my this sounds very resource intensive... Is there a reference for the applicable best practice...
                    I have never been told to make a single seperate list for every single bar....

                    There is a normilization function later and there were statistical calulations performed upstream from the debugging issue we are at now...

                    tldr;
                    Can I see a resource, reference, or example??? This is certainly not something i would have ever thought from the manuals...

                    Comment


                      #11
                      Hello DynamicTest,

                      It would help to know what your end goal is for the list. Are you ultimately going to be storing values while bars process to a single list? Is that list to be used in another script like a strategy?

                      Comment

                      Latest Posts

                      Collapse

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