array coding problem

Questions about MultiCharts and user contributed studies.
andydandy
Posts: 9
Joined: 21 Oct 2009

array coding problem

Postby andydandy » 13 May 2010

hi

i am dealing with a coding problem i dont know how to resolve efficiently

what i want to do is

first: to reset all the values of the array before last time a condition was true to the minimum value.

then : to get the maximum value of the array.

i am using a for down to loop to fill the array whitch has a fixed length
and two conditions.

Code: Select all

counter = counter + 1 ;
if rsi(c,14) crosses over 50 then
counter = 0 ;

if c > average(c,1000) then
if counter = 1 then begin
for nn = 20 down to 1 begin
array[nn] = array[nn-1] ;
end;
array[nn] = c ;
end;
now the array has twenty elements some of whitch
are stored from the previous time that
the c was greater than the average when the counter equals 1 .

what i mean by that is that the array evey time the condition (c> average) will start
it will carry over values from the previous time that the condition was true.

how can i sort this mess out ?

regards

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: array coding problem

Postby TJ » 13 May 2010

hi
....
how can i sort this mess out ?

regards
start with a flow chart...
draw out all the permutations
on how the numbers are assigned.

make a grid on a piece of paper to represent your array...
draw out the number flow:
when and where do you want the numbers.

Arrays are not difficult,
but you have to begin with a clear vision
of how and where to manipulate the numbers.
So far after reading your description,
I am not sure if I follow you fully.
A diagram is the must when dealing with complex operations.

andydandy
Posts: 9
Joined: 21 Oct 2009

Re: array coding problem

Postby andydandy » 14 May 2010

i will try to explain further

when the close just became greater than the average and this represents the basic condition
every time rsi crosses over 50 (second condition)the counter reset to 1 and the value of the close is stored in array[0]...

the array has 20 elements...

in the following senario

the first time rsi crosses over 50 after c > average
array slot[0] stores the close of that bar and the rest of the 19 slots
are carying over the closing value of the bars where counter = 1 from the
previous time that the close > average.

what i want to do is
every time the first condition becomes true to reset all the array values to
a dummy value (-1) and then every time counter = 1 start filling the array
with the close...

note i dont want to resize the array(dynamic array).

then i want to get the max value of the array slots.

note that in case of the scenario aformentioned
the array will be
array[0] = c;
array[1] to array[19] = -1
max value of array = array[0]

when the second ocurrance that counter = 1 will happen while c > average
then the array will be
array[0] = c of first ocuurance
array[1] = c of second occurance
array[2] to array[19] = - 1
if array[0] > array[1] then
max value of array = array[0] else array[1]

my problem is coding the above efficiently the way a pro would have done it so the code will be precize and 100% accurate

my efforts so far require a lot of lines and i am 80% accurate..

for example i am using the maxlist to get tha max value by naming all the array slots one by one

value1 = maxlist(array[0],array[1] ......array[19]) ;

regards


Return to “MultiCharts”