Go Back   NinjaTrader Support Forum > NinjaTrader 7 > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 06-19-2017, 10:32 AM   #1
ballboy11
Senior Member
 
Join Date: Jan 2016
Posts: 115
Thanks: 0
Thanked 3 times in 3 posts
Default 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 at 11:00 AM.
ballboy11 is offline  
Reply With Quote
Old 06-19-2017, 11:09 AM   #2
NinjaTrader_ChrisL
NinjaTrader Customer Service
 
NinjaTrader_ChrisL's Avatar
 
Join Date: Apr 2017
Location: Denver, CO
Posts: 140
Thanks: 0
Thanked 21 times in 21 posts
Default

Hello,
Thank you for the post.
I am processing your request and will be back with you shortly.
I look forward to assisting further.
NinjaTrader_ChrisL is offline  
Reply With Quote
Old 06-19-2017, 12:17 PM   #3
NinjaTrader_ChrisL
NinjaTrader Customer Service
 
NinjaTrader_ChrisL's Avatar
 
Join Date: Apr 2017
Location: Denver, CO
Posts: 140
Thanks: 0
Thanked 21 times in 21 posts
Default

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.
NinjaTrader_ChrisL is offline  
Reply With Quote
Old 06-19-2017, 12:30 PM   #4
ballboy11
Senior Member
 
Join Date: Jan 2016
Posts: 115
Thanks: 0
Thanked 3 times in 3 posts
Default 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
ballboy11 is offline  
Reply With Quote
Old 06-19-2017, 12:49 PM   #5
NinjaTrader_ChrisL
NinjaTrader Customer Service
 
NinjaTrader_ChrisL's Avatar
 
Join Date: Apr 2017
Location: Denver, CO
Posts: 140
Thanks: 0
Thanked 21 times in 21 posts
Default

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:
https://docs.microsoft.com/en-us/dot...ng-to-a-number
Please let me know if I may be of any further assistance.
NinjaTrader_ChrisL is offline  
Reply With Quote
Old 06-19-2017, 03:06 PM   #6
ballboy11
Senior Member
 
Join Date: Jan 2016
Posts: 115
Thanks: 0
Thanked 3 times in 3 posts
Default 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
ballboy11 is offline  
Reply With Quote
Old 06-20-2017, 12:30 PM   #7
NinjaTrader_ChrisL
NinjaTrader Customer Service
 
NinjaTrader_ChrisL's Avatar
 
Join Date: Apr 2017
Location: Denver, CO
Posts: 140
Thanks: 0
Thanked 21 times in 21 posts
Default

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.
NinjaTrader_ChrisL is offline  
Reply With Quote
Old 06-21-2017, 07:56 AM   #8
NinjaTrader_ChrisL
NinjaTrader Customer Service
 
NinjaTrader_ChrisL's Avatar
 
Join Date: Apr 2017
Location: Denver, CO
Posts: 140
Thanks: 0
Thanked 21 times in 21 posts
Default

Good Morning,
May I confirm you saw my previous post below?
NinjaTrader_ChrisL is offline  
Reply With Quote
Old 06-21-2017, 09:48 AM   #9
ballboy11
Senior Member
 
Join Date: Jan 2016
Posts: 115
Thanks: 0
Thanked 3 times in 3 posts
Default My apologies

Yes I thought I confrimed with you. I figured it out finally. Thank you for your help
ballboy11 is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
linq and generic in c# support8@intexom.org Indicator Development 1 05-05-2017 06:57 AM
using System.Xml.Linq TAJTrades General Development 4 02-20-2014 05:01 PM
How to compile VS Form.cs&LINQ Dataclasses into strategy aascotty General Development 1 02-10-2010 04:37 PM
using System.Linq; AndreiFX General Development 3 01-25-2010 01:57 AM
Can I use LINQ (C# 3.0 & .NET 3.0)? Brian1 General Development 6 04-19-2008 04:24 AM


All times are GMT -6. The time now is 04:04 PM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content. Visit the CFTC resources for education regarding the industry and signs of fraud.