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

How to sum a list

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

    How to sum a list

    Hi

    I was wondering whether someone could help me with something.

    I have compiled 2 lists:

    1. The first lists organises the data in 2 columns
    2. the second list calculates 2 variables from the first list
    Is there any way to sum the columns in the second list?

    Doing it as follows works but it is going to take forever with larger datasets:

    seqsumC1=seqRows[0].C1+seqRows[1].C1+seqRows[2].C1+seqRows[3].C1+seqRows[4].C1;
    I have tried the SUM() route but get the following error message

    : 'System.Collections.Generic.List<...>' does not contain a definition for 'C1' and no extension method 'C1' accepting a first argument of type 'System.Collections.Generic.List<...>' could be found (are you missing a using directive or an assembly reference?)
    If someone could point me in the right direction i would be very grateful
    Code:


    for (int idx = 0; idx < (int)center; idx++)


    dataRows.Add(new LadderRow(Close[(int)center+idx],Close[(int)center-idx]));

    for (int idx = 0; idx < (int)center; idx++)


    seqRows.Add(new LadderRow(dataRows[idx].C2+dataRows[idx].C1,dataRows[idx].C2-dataRows[idx].C1));

    seqsumC1=SUM(seqRows.C1, (int)center)[0];

    //seqsumC1=seqRows[0].C1+seqRows[1].C1+seqRows[2].C1+seqRows[3].C1+seqRows[4].C1;

    #2
    Hello fevs7,

    Thank you for your note.

    Without the full code we’re unable to test on our end.

    If you’d like, could you please upload a copy of the strategy so that we can test.

    To export a NinjaScript from NinjaTrader 8 do the following:
    From the Control Center window select Tools -> Export -> NinjaScript...
    Click Add>Select the indicator>OK>Export.
    Then attach that file you saved; under My Docs>NT8>Bin>Custom>Select the downloaded .zip file.

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Best to do a loop again?
      eDanny
      NinjaTrader Ecosystem Vendor - Integrity Traders

      Comment


        #4
        Originally posted by NinjaTrader_AlanP View Post

        If you’d like, could you please upload a copy of the strategy so that we can test.
        Hi Alan

        Here is the Code

        Cheers
        Attached Files
        Last edited by fevs7; 01-24-2017, 09:46 PM.

        Comment


          #5
          Originally posted by eDanny View Post
          Best to do a loop again?
          Hi eDanny

          I have considered that but cannot seem to get it to work from the examples I found online. If you have an example of a sumloop for a list in ninjatrader that would be awesome.

          Best

          Comment


            #6
            I haven't tried this in the editor so it's just rough

            try this 'using.Linq' :

            Code:
             
             
            for (int idx = 0; idx < (int)center; idx++)
             
                dataRows.Add(new LadderRow(Close[(int)center+idx],Close[(int)center-idx]));
             
             if (dataRows.IsNullOrEmpty()) //always check for null
                     return;
             
            double sum0 = dataRows.Sum(x => (x.C1 + x.C2));   
             
            double sum1 = dataRows.Sum(x => (x.C1 - x.C2));
            You can dispel completely with the second seqRows list.
            Last edited by Sim22; 01-25-2017, 03:03 AM.

            Comment


              #7
              Originally posted by Sim22 View Post

              try this 'using.LinQ' :
              And that solves it!

              It seems I was missing the "using System.Linq;" bit

              Thanks for that

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by chbruno, Today, 04:10 PM
              0 responses
              1 view
              0 likes
              Last Post chbruno
              by chbruno
               
              Started by josh18955, 03-25-2023, 11:16 AM
              6 responses
              436 views
              0 likes
              Last Post Delerium  
              Started by FAQtrader, Today, 03:35 PM
              0 responses
              6 views
              0 likes
              Last Post FAQtrader  
              Started by rocketman7, Today, 09:41 AM
              5 responses
              19 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by frslvr, 04-11-2024, 07:26 AM
              9 responses
              127 views
              1 like
              Last Post caryc123  
              Working...
              X