Array Inquire  [SOLVED]

Questions about MultiCharts and user contributed studies.
faraz
Posts: 144
Joined: 25 Feb 2011
Has thanked: 26 times
Been thanked: 57 times

Array Inquire

Postby faraz » 26 Oct 2013

Hi,

Need a little help. How to SUM Array store data? Below example works but what if the Array is very large like 200 so is there any simply way to SUM data instead of writing code to add each Array.

Code: Select all

array: AvArray[6](0);
AvArray[1]=10;
AvArray[2]=120;
AvArray[3]=14;
AvArray[4]=123;
AvArray[5]=133;
AvArray[6]=105;

For Value11= 1 to 3 begin
value1= AvArray[1]+ AvArray[2]+ AvArray[3]+ AvArray[4]+ AvArray[5]+ AvArray[6];
Print(D," ",AvArray[value11]," ",Value1);
end;


Thanks

User avatar
TJ
Posts: 7739
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1032 times
Been thanked: 2221 times

Re: Array Inquire  [SOLVED]

Postby TJ » 26 Oct 2013

Hi,
Need a little help. How to SUM Array store data? Below example works but what if the Array is very large like 200 so is there any simply way to SUM data instead of writing code to add each Array.

Code: Select all

array: AvArray[6](0);
AvArray[1]=10;
AvArray[2]=120;
AvArray[3]=14;
AvArray[4]=123;
AvArray[5]=133;
AvArray[6]=105;
For Value11= 1 to 3 begin
value1= AvArray[1]+ AvArray[2]+ AvArray[3]+ AvArray[4]+ AvArray[5]+ AvArray[6];
Print(D," ",AvArray[value11]," ",Value1);
end;
Thanks
I am not sure the purpose of your example...
but here is how you do the loop

Code: Select all

Input:
Look.back(6);

Var:
My.Sum(0);

For loop = 1 to Look.back
begin
My.Sum = My.Sum + AvArray[ loop ];
Print(D, " ", AvArray[ loop ], " ", My.Sum);
end;

Ps. Always use meaningful variable names; they do not cost any money... and will save you precious time in debugging.

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Array Inquire

Postby ABC » 26 Oct 2013

From the MC help file:

Array_Sum
Returns a sum of the values contained in a range of elements, specified by the starting and ending indexes, of the specified one-dimensional array; returns the number of true elements if the array contains true/false values; returns a value of 0 if the array contains string values.

Usage
Array_Sum(ArrayName,StartIndex,EndIndex)

Where: ArrayName - an expression specifying the name of an array
StartIndex - a numerical expression specifying the starting index for the range
EndIndex - a numerical expression specifying the ending index for the range

Example
Assign a value, indicating a sum of the values contained in the segment of Array1 that begins at the index of 4 and ends at the index of 6, to Value1 variable:

Value1=Array_Sum(Array1,4,6);

Regards,
ABC


Return to “MultiCharts”