# Setting array = 0

Questions about MultiCharts and user contributed studies. t123knight
Posts: 50
Joined: 11 Nov 2005
Contact:

### Setting array = 0

Is there any way I can reset an array to zero without having to do it for every indicitdual cell? For example.

Array: array1[1,1]

if condition1 then begin
array[0,0]=0;
array[1,0]=0;
array[1,0]=0;
array[1,1]=0;
end;

This is fine fo this array because it is small but If I have an array that is 20x20, this is very time consuming. Is there a way I can set the whole thing to zero without having to set them all to zero individually?

Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007
Hi t123knight,

Try the sample code below:

--------------------------------

var:
_i(0), _j(0);

For _i = 0 To <Array First Size> Begin
For _j = 0 To <Array Second Size> Begin
arr[_i, _j] = 3;
End;
end; t123knight
Posts: 50
Joined: 11 Nov 2005
Contact:
Thanks so much for your help. Ok, this is what I have so far.

Array: SetT[8,3];
Var: _i(0);
Var: _j(0);

If condition1 then begin
For _i=0 to 8 begin
For _j=0 to 3 begin
SetT[_i, _j]=3;
end;
end;
end;

I'm getting an error that read "equal sign '=' expected" and the cursor stops right at the line "For _i=0 to 8 begin" on the underscore "_" Am I missing something? Also, what does the =3 designate? drwar
Posts: 218
Joined: 31 Jul 2005
This code is the equivalent to setting each element to zero. It would be good if they provided built in funtions that were optimized, to zero and array or set it to any value. That aside , You did not define condition1 . It may be looking for condition1 "=" to something in the if, then statement.

~J

[quote]Thanks so much for your help. Ok, this is what I have so far.

Array: SetT[8,3];
Var: _i(0);
Var: _j(0);

If condition1 then begin
For _i=0 to 8 begin
For _j=0 to 3 begin
SetT[_i, _j]=3;
end;
end;
end;

I'm getting an error that read "equal sign '=' expected" and the cursor stops right at the line "For _i=0 to 8 begin" on the underscore "_" Am I missing something? Also, what does the =3 designate?[/quote] t123knight
Posts: 50
Joined: 11 Nov 2005
Contact:
Thanks. I actually don't have all the code listed on my example (way too long) so I abreviated that part. Howver, the reast is accurate. fs
Try replacing the Condition line to something like:

If Condition1 = <something> then begin...

I noticed that PL doesn't always handles it correctly when you set a variable to TRUE/FALSE or 1/0 and you still have to refer to it as "If Condition1 = 1" and just using "if Condition1" doesn't always works.

- Fanus drwar
Posts: 218
Joined: 31 Jul 2005
fs
I agree, I have seen the same thing occur

J~

Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007
Thanks so much for your help. Ok, this is what I have so far.

Array: SetT[8,3];
Var: _i(0);
Var: _j(0);

If condition1 then begin
For _i=0 to 8 begin
For _j=0 to 3 begin
SetT[_i, _j]=3;
end;
end;
end;

I'm getting an error that read "equal sign '=' expected" and the cursor stops right at the line "For _i=0 to 8 begin" on the underscore "_" Am I missing something? Also, what does the =3 designate?
Hi t123knight,

Array: SetT[8,3](0);
Var: _i(0);
Var: _j(0);

If condition1 then begin
For _i=0 to 8 begin
For _j=0 to 3 begin
SetT[_i, _j]=3;
end;
end;
end;

Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007
Try replacing the Condition line to something like:

If Condition1 = <something> then begin...

I noticed that PL doesn't always handles it correctly when you set a variable to TRUE/FALSE or 1/0 and you still have to refer to it as "If Condition1 = 1" and just using "if Condition1" doesn't always works.

- Fanus
Hi Fanus,

We haven't been able to reproduce the problem you're describing. Could you please contact our customer support representatives at http://messenger.providesupport.com/mes ... pport.html to show them the issue via the remote control connection. fs
Marina

The following code doesn't compile:
var: Check(0);

If 1 = 1 then Check = 1 else Check = 0;

If Check then buy next bar at open else sell next bar at open;
The following does:
var: Check(0);

If 1 = 1 then Check = 1 else Check = 0;

If Check = 1 then buy next bar at open else sell next bar at open;
and this compiles too..
var: Check(FALSE);

If 1 = 1 then Check = TRUE else Check = FALSE;

If Check then buy next bar at open else sell next bar at open;
I am used to in other programming languages that 0/1 can be substituted for FALSE/TRUE.

Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007
This is the way it's supposed to work in EasyLanguage/PowerLanguage

Regards.