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

linq newbie

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

    linq newbie

    Hi I am new to linq and am trying to get a value from one of my lists

    this is the basic statement i am trying to write

    my list is the following

    string firstname,
    string lastname,
    datetime time,
    int location

    Select location from myList where Time equals current time

    int whichbar = this.myList.Where(d.,d.Time == Time[0] )


    this is the area where I am confused

    this.myList.Where(d.,d.Time == Time[0] )

    if it is not the right time I just want the first one on the list closest to the time



    i think i am getting close

    int whichbar = this.myList.Select(o => o.location).Where(o =>o.Time == Time[0]);

    my error now is cant convert to int
    Last edited by ballboy11; 06-19-2017, 11:00 AM.

    #2
    Hello,
    Thank you for the post.
    I am processing your request and will be back with you shortly.
    I look forward to assisting further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello,
      Thank you for waiting.
      Can you please provide what this is returning:
      Code:
      this.myList.Select(o => o.location).Where(o =>o.Time == Time[0]);
      Add a Print() statement in your code. Open up a new output window (Tools>Output Window) and run it.

      Like so:

      Code:
      Print(this.myList.Select(o => o.location).Where(o =>o.Time == Time[0]));
      I look forward to your reply.
      Chris L.NinjaTrader Customer Service

      Comment


        #4
        don't know if code workds

        It is trying to return a single integer value at a given time.

        I am not sure if the code is good. I am going through linq to see if I am coding correctly

        Comment


          #5
          Hello,
          Thank you for the reply.
          I need to know the data type of myList is and what you are expecting this to return:
          Code:
           this.myList.Select(o => o.location).Where(o =>o.Time == Time[0])
          I am assuming the returned value is a String. You will need to use
          Code:
          Int32.Parse()
          . To cast to an int.
          Like so:

          Code:
          int whichbar = 
          Int32.Parse(this.myList.Select(o => o.location).Where(o =>o.Time == Time[0]));
          You might need to do some custom parsing if the returned string has extraneous values that you do not want. So if the string that is returned looks like this: "foo bar 1 foo bar" and only need the "1", you will need to handle that in your code.
          Here is a publicly available guide for doing so:

          Please let me know if I may be of any further assistance.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            thanks

            I got it to work kindof but for some reason my indexs don't match.

            All I want to find the IndexOf the object within my array by timestamp

            Comment


              #7
              Thank you for the reply.
              If you are comfortable posting your code file here please do, otherwise please send me your code file to platformsupport[at]ninjatrader[dot]com with 'ATTN: Chris L' in the subject line and a reference to this thread in the body of the email.

              To find the file:

              NT 7:
              You can attach your indicator to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your Indicator > select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.

              NT 8:

              You can export your indicator by going to Tools > Export > NinjaScript Add On > Add > select your indicator > OK > Export > name the file 'NTsupport' > Save.

              The file will be located under Documents\NinjaTrader 8\bin\Custom\ExportNinjaScript. Please attach the file to your response.

              I look forward to assisting further.
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Good Morning,
                May I confirm you saw my previous post below?
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  My apologies

                  Yes I thought I confrimed with you. I figured it out finally. Thank you for your help

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by TraderBCL, Today, 04:38 AM
                  2 responses
                  11 views
                  0 likes
                  Last Post TraderBCL  
                  Started by martin70, 03-24-2023, 04:58 AM
                  14 responses
                  105 views
                  0 likes
                  Last Post martin70  
                  Started by Radano, 06-10-2021, 01:40 AM
                  19 responses
                  607 views
                  0 likes
                  Last Post Radano
                  by Radano
                   
                  Started by KenneGaray, Today, 03:48 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post KenneGaray  
                  Started by thanajo, 05-04-2021, 02:11 AM
                  4 responses
                  471 views
                  0 likes
                  Last Post tradingnasdaqprueba  
                  Working...
                  X