![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jan 2009
Posts: 110
|
All,
I'm looking to sort an array with 100 items in it, each of the items are doubles. Will the Array.Sort method work in NT? Thanks Shannon |
|
|
|
|
|
#2 |
|
Certified NinjaScript Consultant
Join Date: Sep 2006
Location: New York, USA
Posts: 681
|
Hey Shansen,
I would use an ArrayList type. you will have to add the following reference to the top of your code Code:
using System.Collections;
__________________
"The notion of impossibility only exist in the world of those who had already been imprisoned by their own fears and limitations." "You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later" PureLogikTrading |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jan 2009
Posts: 110
|
mrlogic,
Thanks for the reply. If you would be so kind, I'd like to improve my knowledge in coding within NT. From a little research, there are several differences between Arrays and Arraylists:
Any insight on your knowledge and experience would be appreciated Regards Shannon |
|
|
|
|
|
#4 |
|
Certified NinjaScript Consultant
Join Date: Sep 2006
Location: New York, USA
Posts: 681
|
In the case you present, the .Sort method is already coded for you. Additionally, future expansion is simpler since the ArrayList is a table of type object, which can hold any element type.
__________________
"The notion of impossibility only exist in the world of those who had already been imprisoned by their own fears and limitations." "You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later" PureLogikTrading |
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Hamburg / Lueneburg - Germany
Posts: 10,867
|
In addition to mrlogik's tips, you could check into this link here - http://dotnetperls.com/all-list
__________________
Bertrand, NinjaTrader Customer Service NinjaTrader is a FREE application for advanced charting, market analytics, system development and trade simulation. View schedule of upcoming online product training events. |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Jan 2009
Posts: 110
|
mrlogik & Bertrand,
Thanks for your respective replies. Showing my novice programing stature, if an array is coded in NT as: Code:
#region Variables
private double[] MyArray;
#endregion
protected override void Initialize()
{
MyArray = new double[100];
}
Thanks again Shannon Last edited by Shansen; 09-23-2009 at 06:11 AM. |
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Hamburg / Lueneburg - Germany
Posts: 10,867
|
Shannon, don't have a snippet ready, but you can check the C# section of this link - http://msdn.microsoft.com/en-us/libr...arraylist.aspx
__________________
Bertrand, NinjaTrader Customer Service NinjaTrader is a FREE application for advanced charting, market analytics, system development and trade simulation. View schedule of upcoming online product training events. |
|
|
|
|
|
#8 |
|
Certified NinjaScript Consultant
Join Date: Sep 2006
Location: New York, USA
Posts: 681
|
Code:
#region Variables
private ArrayList() myArrayList;
#endregion
protected override void Initialize()
{
myArrayList = new ArrayList();
}
__________________
"The notion of impossibility only exist in the world of those who had already been imprisoned by their own fears and limitations." "You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later" PureLogikTrading |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jan 2009
Posts: 110
|
mrlogik & Bertrand,
After more research, would the "List" class be a better direction to head? From what I've read it is more efficient and "type safe". As always any insight would be appreciated. Regards Shannon Last edited by Shansen; 09-26-2009 at 05:17 AM. |
|
|
|
|
|
#10 |
|
Certified NinjaScript Consultant
Join Date: Sep 2006
Location: New York, USA
Posts: 681
|
Shansen,
It really depends on the application, and what you're familiar with. Do you have a specific design you need to fulfill, or is this more of a generic design?
__________________
"The notion of impossibility only exist in the world of those who had already been imprisoned by their own fears and limitations." "You look closely enough, you can find everything has a ... weak spot where it can break, sooner or later" PureLogikTrading |
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Jan 2009
Posts: 110
|
mrlogik,
Funny you should ask what I'm familiar with. Both ArrayList and List are new to me. I'm looking to identify where the CurrentBar's range is significantly above average (relative to recent bars). With your help I've constructed an ArrayList, used it to store on a rolling basis the ranges of the last 100 bars (inserting the latest bar range at index 0, and removing index 101 in the ArrayList when the ArrayCount equals 101). This ArrayList is cloned to a new ArrayList, this new ArrayList is then sorted. The range listed at the 90th index of the sorted ArrayList is used to evaluate if the CurrentBar's range is in the top 10% of the most recent 100 bars. As always any suggestions are welcome. Regards Shannon |
|
|
|
|
|
#12 |
|
Senior Member
Join Date: Jan 2009
Posts: 110
|
mrlogik,
It would appear I've hit a snag... The method arraylist.sort() does not appear to work as expected? Please find below a sample of the NinjaScript. As always, any insight would be appreciated Regards Shannon Code:
#region Using declarations
using System.Collections;
#endregion
#region Variables
private ArrayList HistoricalRanges = new ArrayList();
private ArrayList SortedRanges = new ArrayList();
private double AboveAverageBarRange;
#endregion
protected override void OnBarUpdate()
{
HistoricalRanges.Insert(0, Range()[1]);
if (HistoricalRanges.Count > 100)
HistoricalRanges.RemoveAt(100);
SortedRanges = (ArrayList) HistoricalRanges.Clone();
Print ("");
Print (Time.ToString() + " Required range " + ((double) SortedRanges[Convert.ToInt32(Math.Min(SortedRanges.Count-1, 90))]));
SortedRanges.Sort();
Print (Time.ToString() + " Required range " + ((double) SortedRanges[Convert.ToInt32(Math.Min(SortedRanges.Count-1, 90))]));
}
Last edited by Shansen; 10-22-2009 at 03:52 AM. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sorting layers | eswap0 | Indicator Development | 1 | 03-21-2009 11:02 PM |
| Sorting Columns in Market Analyzer | designer | Suggestions And Feedback | 10 | 10-13-2008 04:10 AM |
| Sorting labels in parameters window | cls71 | Suggestions And Feedback | 1 | 04-16-2008 05:30 AM |
| Multiple Market Analyzers vs. Sorting | 1reason | Market Analyzer | 1 | 12-29-2007 05:01 PM |
| Parameter sorting/ordering | rtrader | Suggestions And Feedback | 3 | 04-08-2007 05:27 PM |