Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

Tams

Array (EasyLanguage)

Recommended Posts

This thread is about Arrays.

 

 

 

 

Array

Declares one or more names as arrays, containing multiple variable data elements; specifies the array structure, data elements type and initial value, update basis, and data number, for each of the arrays.

 

Data elements type can be numerical, string, or true/false.

 

The number of elements in an array can be fixed or dynamic (unlimited).

 

In arrays with a fixed number of elements, the elements can be arranged in single or multiple dimensions.

 

A one-dimensional 10-element array contains 10 elements,

a two-dimensional 10-element by 10-element array contains 100 elements,

a three-dimensional 10 by 10 by 10 element array contains 1000 elements,

a four-dimensional 10 by 10 by 10 by 10 element array contains 10000 elements, etc.

 

The maximum number of array dimensions in EasyLanguage is 9.

 

Each element in an array is referenced by one or more index numbers, one for each of the dimensions. Indexing starts at 0 for each of the dimensions.

 

Dynamic arrays (arrays with an unlimited number of elements) are one-dimensional, and are initialized at declaration as having only one element. Declared dynamic arrays can be resized using Array_SetMaxIndex.

 

Elements can be manipulated individually or as a group, in all or part of an array.

 

Usage

Array:<IntraBarPersist>ArrayName1[D1,D2,D3,etc.](InitialValue1<,DataN>),

<IntraBarPersist>ArrayName2[D1,D2,D3,etc.](InitialValue2<,DataN>), etc...

 

Parameters inside the angled brackets are optional

 

Parameters

IntraBarPersist - an optional parameter; specifies that the value of the array elements is to be updated on every tick

If this parameter is not specified, the value will be updated at the close of each bar.

 

ArrayName - an expression specifying the array name

The name can consist of letters, underscore characters, numbers, and periods. The name cannot begin with a number or a period and is not case-sensitive.

 

 

D - a numerical expression specifying the array size in elements, starting at 0, for each of the dimensions;

a single expression specifies a one-dimensional array,

two expressions specify a two-dimensional (D1 by D2) array,

three expressions specify a three-dimensional (D1 by D2 by D3) array, etc.

A dynamic array, with an unlimited number of elements, is specified by the empty square brackets: [] and will be a one-dimensional array.

 

InitialValue - an expression, specifying the initial value and defining the data type for all of the elements in the array

The value can be a numerical, string, or true/false expression; the type of the expression defines the data type.

 

DataN - an optional parameter; specifies the Data Number of the data series the array is to be tied to

If this parameter is not specified, the array will be tied to the default data series.

 

Examples

Declare Length and SFactor as 9-element one-dimensional numerical arrays with data elements' initial values of 0:

 

Array:

Length[8](0),

SFactor[8](0);

 

 

Declare Max_Price as a 24-element by 60-element two-dimensional numerical array, updated on every tick, tied to the series with Data #2, and with data elements' initial values equal to the value of Close function:

 

Array:IntraBarPersist Max_Price[23,59](Close,Data2);

 

 

Declare Highs2 as a dynamic numerical array with data elements' initial values of 0:

 

Array:Highs2[](0);

 

 

 

 

 

source: EasyLanguage manual

Edited by Tams

Share this post


Link to post
Share on other sites

Here you go:

 

 

Paul

 

Courtesy of Tradestation: http://www.tradestation.com

 

The Array concept it is actually very simple.

The attempt of this page is to demystify the concept with simple examples. Please feel free to edit as well as to add alternate methods to clarify the content

 

Think of an array as an Excel spreadsheet, where you have rows and columns.

It is from this approach that the following examples are designed.

 

* One Dimensional Arrays

* Multi Dimensional Arrays

* Populating Arrays

* Shuffling Array Data

* Sort new field into Array - soon

 

 

Incrementing : For Counter = 1 to Array_Size begin... end;

Decrementing : For Counter = Array_Size DownTo 1 begin... end;

One Dimensional ARRAYS

 

With one dimensional arrays you get one column with X number of rows to query.

 

Array: myArray [10] (0);

 

* the [10] defines one column with 10 rows (not to confuse but a 0 row is actually available too to make 11 )

* (0) = Numeric Data

* (Text) = would = String Data could be entered.

 

 

Multi-Dimensional Arrays

 

Multi-Dimensional arrays enable you to store vast amounts of data more similar to a spreadsheet, thus you could add a specific series of data per bar or per condition to back reference for compare.

 

Warning

More standard is the two dimensioned array, but since you can do more a warning must be stated here in using a three dimensional array

For example 3 dimensioned arrray would be myArray[10,10,10]; You should have your reasons well in order in advanced as improper dimensioning could easy take up too much memory as well as calculations time could be increased exponentially . The conceptualization of a three dimensional Array would be a spreadsheet cell hyperlinking to another completely new spreadsheet. A better example may be a pallet of boxs 10 across, 10 high and 10 deep. It starts getting very complicated at that level.

 

Two Dimensional Array

 

Array: myArray [10,10] (0);

 

the [10,10] defines 10 columns with 10 rows (or not counting the 0 row, 100 field to populate with data)

 

* (0) = Numeric Data

* (Text) = would = String Data could be entered.

 

 

So if you ask for

Value1 = myArray*[6,7]*; then you are looking for column 6, row 7's data.

 

 

Populating Arrays

 

Arrays values hold from bar to bar.

An array can be populated by a hard number as in:

myArray[4] = High;

 

or by a Counter method that you predefine variable name is arbitrary as long as the value is not higher than the declared dimensional value.

 

Var: Counter(0);

 

Counter = Counter +1;

myArray[Counter] = High;

 

 

Shuffling Array Data

 

Shuffling simply moves the first row of an array to the second and so forth leaving the Arrays first row open for a new entry.

Normally this is done in one step or procedure.

 

Single Dimension Array Shuffle

 

Array: myArray [10] (0);

Var: myArraySize(10);

Var: Counter1(0);

Var: HoldRow(0), SaveValue(0);

SaveValue = Value1; {your value or caluclation you want arrayed}

For Counter1 = 1 to myArraySize begin

holdRow = myArray[Counter1]; {save the current Value of this row for the next row }

myArray[Counter1] = SaveValue; {pass the newer Value to this row}

SaveValue = holdRow; {pass the old Value of this row for the next loop}

 

 

end;

 

Multi-Dimensioned Array Shuffle

 

The code below will shuffle a multi-dimensional array. A new row will be inserted in position 1 and roll the remaining rows back one row each.

 

Array: myArray [100,10] (0);

Var: myArraySize(100);

Array: Save[10](0); {used as holders for the shuffle}

Array: Hold[10](0); {used as holders for the shuffle}

 

Var: Z(0), X(0); {Using Single Letters as counters}

 

 

{Pass your newest set of Values to a one dimensional Array}

 

If condition1 then begin

{Sample Data}

Hold[1]= Date;

Hold[2]= Time;

Hold[3]= Open;

Hold[4]= High;

Hold[5]= Low;

Hold[6]= Close;

Hold[7]= UpTicks;

Hold[8]= Downticks;

Hold[9]= CurrentBar;

Hold[10]= close -close[1]0;

 

for Z = 1 to myArraySize begin

 

For X = 1 to 10 begin Save[X] = myArray [Z,X]; end; {pass Array Row to Save Array variable LOOP}

 

For X = 1 to 10 begin myArray [Z,X] = Hold[X]; end; {pass Hold Array variables row LOOP}

 

For X = 1 to 10 begin Hold[X] = Save[X]; end; {pass the SaveArray to Hold Array LOOP}

 

if Hold[1]= 0 then BREAK; {Get out of main LOOP if passed row /Hold Array is Empty }

 

end;

end;

Edited by Trader333

Share this post


Link to post
Share on other sites

I'm a good gal, I've made my homeworks.

 

Is it correct ?

 

Var:
count(         0 ),
count.end(   2 );

Arrays: 
Line.ID[2](  0 ),
level[2](	0 ),
Color[2]( 0 );

Level[1] = HighD(1);
Level[2] = LowD(1);

Color[1] = blue;
Color[2] = red;

for count = 1 to count.end
begin
Line.ID[count]  = TL_New( d , t , level[count], d, t , level[count]);
TL_SetColor(Line.ID, Color[count]);
end;

Share this post


Link to post
Share on other sites

a little correction but the result has a lot of lines

 

Var:
count(         0 ),
count.end(   2 );

Arrays: 
Line.ID[2](  0 ),
level[2](	0 ),
Color[2]( 0 );

Level[1] = HighD(1);
Level[2] = LowD(1);

Color[1] = blue;
Color[2] = red;

for count = 1 to count.end
begin
Line.ID[count] = TL_New( d , t , level[count], d, t , level[count]);
TL_SetColor(Line.ID[count], Color[count]);
TL_SetExtRight(Line.ID[count], true );
end;

Share this post


Link to post
Share on other sites
a little correction but the result has a lot of lines

 

wow... good job... you are trying hard.

 

maybe too hard.

I would have suggested you to start out with one array.

and you added trendline to the code as well !!!

you are taking on multiple challenges at the same time.

 

 

 

anyway, here's my notes:

 

You have the trendline starting point same as ending point...

ie. the resultant trendline will be a dot.

that's why you don't see anything unless you use the extend right option.

 

pls see attachment for detail.

array.jpg.df8c7c22c825bac7084327552c2415ee.jpg

Edited by Tams

Share this post


Link to post
Share on other sites

ThanX for your notes Mister TAMS

 

I like it hard ! :cool:

 

Starting point = ending point = OK for a day H/L

 

but

 

Date + time must start the day before

 

// Draw High and Low lines of the day before 
// version 1.0
// Author: aaa
// Date: 20090425

Var:
count(       0 ),
count.end(   2 );

Arrays: 
Line.ID[2](  	0 ),
level[2](	0 ),
Color[2]( 	0 ),
Size[2]( 	0 ),
Style[2]( 	0 );

level[1] = HighD(1);
level[2] = LowD(1);

Color[1] = blue;
Color[2] = red ;

Size[1] = 2 ;
Size[2] = 2 ;

Style[1] = 1 ;
Style[2] = 1 ;

for count = 1 to count.end
begin
Line.ID[count] = TL_New( d[1] , t[1] , level[count], d , t , level[count]);

TL_SetColor( Line.ID[count] , Color[count] );
TL_SetSize(  Line.ID[count] , Size[count]  );
TL_SetStyle( Line.ID[count] , Style[count] );	
end;

Share this post


Link to post
Share on other sites
// Draw High and Low lines of the day before 
// version 1.01
// Author: aaa
// Date: 20090425

Inputs:
Color.High(	blue 	),
Color.low(	red 	),
Size.HL(	2   	),
Style.HL(	1 	);

Var:
count(       0 ),
count.end(   2 );

Arrays: 
Line.ID[2](  	0 ),
level[2](	0 ),
Color[2]( 	0 ),
Size[2]( 	0 ),
Style[2]( 	0 );

level[1] = HighD(1);
level[2] = LowD(1);

Color[1] = Color.High;
Color[2] = Color.low;

Size[1] = Size.HL ;
Size[2] = Size.HL ;

Style[1] = Style.HL ;
Style[2] = Style.HL ;

for count = 1 to count.end
begin
Line.ID[count] = TL_New( d[1] , t[1] , level[count], d , t , level[count]);

TL_SetColor( Line.ID[count] , Color[count] );
TL_SetSize(  Line.ID[count] , Size[count]  );
TL_SetStyle( Line.ID[count] , Style[count] );	
end;

Share this post


Link to post
Share on other sites
It's a Great idea to create topics like this

Sorry, if it's not a really original indicator.... :2c:

It is only an exercice with arrays

 

it is fun just to plot lines here and there...

you'd never know, you might come up with a Nobel Prize winner by accident.

Share this post


Link to post
Share on other sites

Tams,

 

I think that I am in the wrong way

 

I have now the yesterday HL during 2 days

 

The code looks complicate and if I want lines during x days it should be very long

 

The goal is to have the Yesterday HL during x days

 

Are arrays the solution ?

 

Is a counter a solution ?

 

Inputs:
Color.HL(	blue 	),
Size.HL(	2   	),
Style.HL(	1 	);

Var:
count(       0 ),
count.end(   4 );

Arrays: 
Line.ID[4](  	0 ),
level[4](	0 ),
DaysAfter[4](	0 ),
TimeAfter[4](	0 ),
DaysBefore[4](0 ),
TimeBefore[4](0 );

level[1] = HighD(1);
level[2] = LowD(1);
level[3] = HighD(2);
level[4] = LowD(2);

DaysBefore[1] = d[1] ;
DaysBefore[2] = d[1] ;
DaysBefore[3] = d[2] ;
DaysBefore[4] = d[2] ;

TimeBefore[1] = t[1] ;
TimeBefore[2] = t[1] ;
TimeBefore[3] = t[2] ;
TimeBefore[4] = t[2] ;

DaysAfter[1] = d[1] ;
DaysAfter[2] = d[1] ;
DaysAfter[3] = d[2]  ;
DaysAfter[4] = d[2] ;

TimeAfter[1] = t[1]  ;
TimeAfter[2] = t[1] ;
TimeAfter[3] = t[2]  ;
TimeAfter[4] = t[2] ;


for count = 1 to count.end
begin
Line.ID[count] = TL_New( DaysBefore[count] , TimeBefore[count] , level[count], DaysAfter[count]  , TimeAfter[count]  , level[count]);

TL_SetColor( Line.ID[count] , Color.HL);
TL_SetSize(  Line.ID[count] , Size.HL  );
TL_SetStyle( Line.ID[count] , Style.HL );	
end;

Share this post


Link to post
Share on other sites
it is fun just to plot lines here and there...

you'd never know, you might come up with a Nobel Prize winner by accident.

 

Let's try the Tams Prize before ! ;)

Share this post


Link to post
Share on other sites
Tams,

I think that I am in the wrong way

I have now the yesterday HL during 2 days

The code looks complicate and if I want lines during x days it should be very long

The goal is to have the Yesterday HL during x days

Are arrays the solution ?

Is a counter a solution ?

 

 

if you only need 2 lines across... array might be an overkill.

edit: let me give it some thought on the alternative... will post later.

 

 

array is useful when you are dealing with a lot of data,

and that you need to access those data in a non-sequential manner.

 

the Zigzag indicator is a good example where an array is used to keep track of the trendline coordinates.

Edited by Tams

Share this post


Link to post
Share on other sites

Yes I reached my limits with arrays and I don't understand zigzag

 

I tried "my" indicator with 10 days long

 

It looks interesting especially scalping in 1 mn : the price stops always for a short break at highest last 1, 2 3 or more past days (cf picture below)

 

If you have time Could you make a correct code ?

 

Here is my terrible one

 

It works but slows down dramatically the software

 

Also the style is off

 

Inputs:
Days.Nbr(	2 	),
Color.HL(	blue 	),
Size.HL(	2   	),
Style.HL(	1 	);

Var:
count(       0 ),
count.end(   Days.Nbr * 2 );

Arrays: 
Line.ID[20](  0 ),
level[20](	0 ),
DaysAfter[20](0 ),
TimeAfter[20](0 ),
DaysBefore[20](0 ),
TimeBefore[20](0 );

level[1] = HighD(1);
level[2] = LowD(1);
level[3] = HighD(2);
level[4] = LowD(2);
level[5] = HighD(3);
level[6] = LowD(3);
level[7] = HighD(4);
level[8] = LowD(4);
level[9] = HighD(5);
level[10] = LowD(5);
level[11] = HighD(6);
level[12] = LowD(6);
level[13] = HighD(7);
level[14] = LowD(7);
level[15] = HighD(8);
level[16] = LowD(8);
level[17] = HighD(9);
level[18] = LowD(9);
level[19] = HighD(10);
level[20] = LowD(10);

DaysBefore[1] = d[1] ;
DaysBefore[2] = d[1] ;
DaysBefore[3] = d[2] ;
DaysBefore[4] = d[2] ;
DaysBefore[5] = d[3] ;
DaysBefore[6] = d[3] ;
DaysBefore[7] = d[4] ;
DaysBefore[8] = d[4] ;
DaysBefore[9] = d[5] ;
DaysBefore[10] = d[5] ;
DaysBefore[11] = d[6] ;
DaysBefore[12] = d[6] ;
DaysBefore[13] = d[7] ;
DaysBefore[14] = d[7] ;
DaysBefore[15] = d[8] ;
DaysBefore[16] = d[8] ;
DaysBefore[17] = d[9] ;
DaysBefore[18] = d[9] ;
DaysBefore[19] = d[10] ;
DaysBefore[20] = d[10] ;

TimeBefore[1] = t[1] ;
TimeBefore[2] = t[1] ;
TimeBefore[3] = t[2] ;
TimeBefore[4] = t[2] ;
TimeBefore[5] = t[3] ;
TimeBefore[6] = t[3] ;
TimeBefore[7] = t[4] ;
TimeBefore[8] = t[4] ;
TimeBefore[9] = t[5] ;
TimeBefore[10] = t[5] ;
TimeBefore[11] = t[6] ;
TimeBefore[12] = t[6] ;
TimeBefore[13] = t[7] ;
TimeBefore[14] = t[7] ;
TimeBefore[15] = t[8] ;
TimeBefore[16] = t[8] ;
TimeBefore[17] = t[9] ;
TimeBefore[18] = t[9] ;
TimeBefore[19] = t[10] ;
TimeBefore[20] = t[10] ;

DaysAfter[1] = d[1] ;
DaysAfter[2] = d[1] ;
DaysAfter[3] = d[2] ;
DaysAfter[4] = d[2] ;
DaysAfter[5] = d[3] ;
DaysAfter[6] = d[3] ;
DaysAfter[7] = d[4] ;
DaysAfter[8] = d[4] ;
DaysAfter[9] = d[5] ;
DaysAfter[10] = d[5] ;
DaysAfter[11] = d[6] ;
DaysAfter[12] = d[6] ;
DaysAfter[13] = d[7] ;
DaysAfter[14] = d[7] ;
DaysAfter[15] = d[8] ;
DaysAfter[16] = d[8] ;
DaysAfter[17] = d[9] ;
DaysAfter[18] = d[9] ;
DaysAfter[19] = d[10] ;
DaysAfter[20] = d[10] ;

TimeAfter[1] = t[1] ;
TimeAfter[2] = t[1] ;
TimeAfter[3] = t[2] ;
TimeAfter[4] = t[2] ;
TimeAfter[5] = t[3] ;
TimeAfter[6] = t[3] ;
TimeAfter[7] = t[4] ;
TimeAfter[8] = t[4] ;
TimeAfter[9] = t[5] ;
TimeAfter[10] = t[5] ;
TimeAfter[11] = t[6] ;
TimeAfter[12] = t[6] ;
TimeAfter[13] = t[7] ;
TimeAfter[14] = t[7] ;
TimeAfter[15] = t[8] ;
TimeAfter[16] = t[8] ;
TimeAfter[17] = t[9] ;
TimeAfter[18] = t[9] ;
TimeAfter[19] = t[10] ;
TimeAfter[20] = t[10] ;

for count = 1 to count.end
begin
Line.ID[count] = TL_New( DaysBefore[count] , TimeBefore[count] , level[count], DaysAfter[count]  , TimeAfter[count]  , level[count]);

TL_SetColor( Line.ID[count] , Color.HL);
TL_SetSize(  Line.ID[count] , Size.HL  );
//	TL_SetStyle( Line.ID[count] , Style.HL );	
end;

Snap1.thumb.jpg.cd9de38f0206101e6392bd7bfad922fe.jpg

Share this post


Link to post
Share on other sites
Yes I reached my limits with arrays and I don't understand zigzag

I tried "my" indicator with 10 days long

It looks interesting especially scalping in 1 mn : the price stops always for a short break at highest last 1, 2 3 or more past days (cf picture below)

If you have time Could you make a correct code ?

Here is my terrible one

It works but slows down dramatically the software

Also the style is off

 

 

I have posted a sample code at the Trendline thread:

http://www.traderslaboratory.com/forums/showpost.php?p=63601&postcount=3

 

I posted it over there because the code does not use array.

Share this post


Link to post
Share on other sites
Yes I reached my limits with arrays and I don't understand zigzag

I tried "my" indicator with 10 days long

It looks interesting especially scalping in 1 mn : the price stops always for a short break at highest last 1, 2 3 or more past days (cf picture below)

If you have time Could you make a correct code ?

Here is my terrible one

 

It works but slows down dramatically the software

 

Also the style is off

 

 

 

that's because there is an error in coding:

the code is adding a NEW trendline at every bar.

the dotted line you see is not a dotted line...

each dot is actually a trendline; if you click on the dot, you can drag the dot out and see the trendline.

Share this post


Link to post
Share on other sites

Array Keywords

 

Array

Arrays

ArraySize

ArrayStartAddr

 

Array_Compare

Array_Copy

Array_GetMaxIndex

Array_GetType

Array_SetMaxIndex

Array_SetValRange

Array_Sort

Array_Sum

Share this post


Link to post
Share on other sites
i am a little bit out of this thread, but i'd like also make a comparison

about array in easylanguage and ninjatrader.

It would it be possible to explain how array works in c# and how to conver an array from easylanguage to c#?

 

For Ninjatrader/C# you might look here:

 

Arrays (C# Programming Guide)

 

 

Regards,

 

Hal

Share this post


Link to post
Share on other sites
Array Keywords

 

Array

Arrays

ArraySize

ArrayStartAddr

 

Array_Compare

Array_Copy

Array_GetMaxIndex

Array_GetType

Array_SetMaxIndex

Array_SetValRange

Array_Sort

Array_Sum

 

Hi TAMS,

Great Thread for newbie to ARRAY like me.........very useful......many Thanks!!!

 

Now I've some questions about arrays:

1) is it possible to make an array of arrays ?

For example an array made of 2 unlimited dimension array ?

FirstArray[ ] (0);

SecondArray[ ] (0);

MyFinalarray[FirstArray, SecondArray](0);

 

2) I know that an array could be a numeric array [ (0) ] or a string array [ (text) ] or a True/false array, but waht does it mean if I find an array like this:

MyArray [10] (-1);

 

Thanks for you contribution on this study about array.

CrazyNasdaq

Share this post


Link to post
Share on other sites
Hi TAMS,

Great Thread for newbie to ARRAY like me.........very useful......many Thanks!!!

 

Now I've some questions about arrays:

1) is it possible to make an array of arrays ?

 

 

are you talking about a 3 dimensional array?

Yes, you can build it with multiple arrays,

but no, it is not part of the EasyLanguage repertoire.

 

 

 

2) I know that an array could be a numeric array [ (0) ] or a string array [ (text) ] or a True/false array, but waht does it mean if I find an array like this:

MyArray [10] (-1);

 

Thanks for you contribution on this study about array.

CrazyNasdaq

 

 

initialize the array to the value of -1.

read post #1, example included.

 

.

Edited by Tams

Share this post


Link to post
Share on other sites
are you talking about a 3 dimensional array?

Yes, you can build it with multiple arrays,

but no, it is not part of the EasyLanguage repertoire.

No, I don't think that waht I want to build is a 3 dimensional array.

I'm trying to build a Volume profile so it's a 2 dimensional array.

First dimension unlimited and unknown is the range of each day (High of the day - Low of the day) * price scale (or tick scale as you want)

 

Second dimensional array the volume of each level price (unknown )

 

So the final array is an array of the 2 first arrays each one unlimited.

The final array I think is a 2 dimensional array.

Is it possible ???

Or I must use ADE and maps collections ?

 

Thanks again

CrazyNasdaq

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.