NexusFi: Find Your Edge


Home Menu

 





Missing Declarations


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one cutzpr with 4 posts (0 thanks)
    2. looks_two sam028 with 2 posts (1 thanks)
    3. looks_3 bobwest with 2 posts (0 thanks)
    4. looks_4 rleplae with 1 posts (1 thanks)
    1. trending_up 1,572 views
    2. thumb_up 2 thanks given
    3. group 4 followers
    1. forum 9 posts
    2. attach_file 0 attachments




 
Search this Thread

Missing Declarations

  #1 (permalink)
 
cutzpr's Avatar
 cutzpr 
United States
 
Experience: None
Platform: TWS,Ninja Trader
Trading: Forex, Futures, Stocks
Posts: 35 since Apr 2012
Thanks Given: 10
Thanks Received: 10

I'm new to c# and NJ script.

I am trying use different methods to work with arrays, take for instance the max, min and length of an array. I see that there are methods such as
 
Code
                            
array.max  
array.min
array.length 
which are found in system.int32 and System.array. How do I add these references to NJ. I would guess they are automatically included.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Exit Strategy
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
ZombieSqueeze
Platforms and Indicators
 
  #3 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


what are you trying to do ?

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 
bobwest's Avatar
 bobwest 
Western Florida
Site Moderator
 
Experience: Advanced
Platform: Sierra Chart
Trading: ES, YM
Frequency: Several times daily
Duration: Minutes
Posts: 8,162 since Jan 2013
Thanks Given: 57,341
Thanks Received: 26,267


cutzpr View Post
I'm new to c# and NJ script.

I am trying use different methods to work with arrays, take for instance the max, min and length of an array. I see that there are methods such as
 
Code
                            
array.max  
array.min
array.length 
which are found in system.int32 and System.array. How do I add these references to NJ. I would guess they are automatically included.

By "NJ" do you mean "NT" (NinjaTrader)?

When you run the NT New Indicator wizard, it will write out a stub indicator that you can modify, and it will put these "using" declarations into the code, which is how references to different namespaces are added in C#:

#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion

If you ever need to reference anything else, you put in the appropriate "using" statement.

If you're not familiar with C# development, I would do some work to get familiar with developing code there, and then dig through some of the code for the standard NT indicators, plus the Help file on NinjaScript, to see what classes are provided and how things are implemented.

Good luck.

Bob.

Reply With Quote
  #5 (permalink)
 
cutzpr's Avatar
 cutzpr 
United States
 
Experience: None
Platform: TWS,Ninja Trader
Trading: Forex, Futures, Stocks
Posts: 35 since Apr 2012
Thanks Given: 10
Thanks Received: 10

I tried to add System.Int32 and System.Array in the declarations but they are unavailable in the NJ editor. Please take a look at the image to see what I am talking about.

I should also add I am using NT 8



Started this thread Reply With Quote
  #6 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


cutzpr View Post
I tried to add System.Int32 and System.Array in the declarations but they are unavailable in the NJ editor. Please take a look at the image to see what I am talking about.

I should also add I am using NT 8



You don't need additional libraries.
To declare an array just add the square brackets ([]) after the object type:
 
Code
                            
int[] numbers = new int[5];

Print(
"len: " numbers.Length

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
Thanked by:
  #7 (permalink)
 
bobwest's Avatar
 bobwest 
Western Florida
Site Moderator
 
Experience: Advanced
Platform: Sierra Chart
Trading: ES, YM
Frequency: Several times daily
Duration: Minutes
Posts: 8,162 since Jan 2013
Thanks Given: 57,341
Thanks Received: 26,267


cutzpr View Post
I tried to add System.Int32 and System.Array in the declarations but they are unavailable in the NJ editor. Please take a look at the image to see what I am talking about.

I should also add I am using NT 8

Obviously, I should have asked before offering advice, since I have not gotten into NT8 yet and am not familiar with its editor. Apologies for that.

However, in general I assume you can just type in any appropriate using statement in the NT8 editor and it should compile.

I see that @sam028 has already given the answer, which I wasn't thinking of because I was focused on the "usings".... Duh.

Bob.

Reply With Quote
  #8 (permalink)
 
cutzpr's Avatar
 cutzpr 
United States
 
Experience: None
Platform: TWS,Ninja Trader
Trading: Forex, Futures, Stocks
Posts: 35 since Apr 2012
Thanks Given: 10
Thanks Received: 10


sam028 View Post
You don't need additional libraries.
To declare an array just add the square brackets ([]) after the object type:
 
Code
                            
int[] numbers = new int[5];

Print(
"len: " numbers.Length

I wanted to find the length of a given array/series and also be able to get the array position with the highest number and lowest number without have to use a loop to go through the entire series.

Started this thread Reply With Quote
  #9 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


cutzpr View Post
I wanted to find the length of a given array/series and also be able to get the array position with the highest number and lowest number without have to use a loop to go through the entire series.

You can try something like this:

 
Code
                            
int[] numbers = new int[5];

...
Print(
"len: " numbers.Length
int indexAtMax numbers.ToList().IndexOf(numbers.Max());
int indexAtMin numbers.ToList().IndexOf(numbers.Min()); 

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
  #10 (permalink)
 
cutzpr's Avatar
 cutzpr 
United States
 
Experience: None
Platform: TWS,Ninja Trader
Trading: Forex, Futures, Stocks
Posts: 35 since Apr 2012
Thanks Given: 10
Thanks Received: 10



sam028 View Post
You can try something like this:

 
Code
                            
int[] numbers = new int[5];

...
Print(
"len: " numbers.Length
int indexAtMax numbers.ToList().IndexOf(numbers.Max());
int indexAtMin numbers.ToList().IndexOf(numbers.Min()); 

Thanks @sam028. For some reason the . Length was not working for me.

Started this thread Reply With Quote




Last Updated on January 24, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts