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 bobwest with 2 posts (0 thanks)
    3. looks_3 sam028 with 2 posts (1 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 2,593 views
    2. thumb_up 2 thanks given
    3. group 4 followers
    1. forum 9 posts
    2. attach_file 0 attachments




 
Search this Thread
  #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?
Topstep Acquires The Futures Desk -- Prop Firm Consolida …
Funded Trading Evaluation Firms
The 50/50 Paradox: Peace and Invasion Each at 20% -- Ira …
Prediction Markets & Event Contracts
Iran Peace Expired NO: Ceasefire on Life Support, OPEC a …
Prediction Markets & Event Contracts
TradingView Opens Volume Footprint Data to Pine Script - …
TradingView
The Backwardation Signal: How the CL Futures Curve Tells …
Commodities
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #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: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,860


what are you trying to do ?


Follow me on X 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,174 since Jan 2013
Thanks Given: 57,989
Thanks Received: 26,406


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,756 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,632


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 X 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,174 since Jan 2013
Thanks Given: 57,989
Thanks Received: 26,406


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,756 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,632


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 X 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


© 2026 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 - Downloads - Top
no new posts