Hello:
I am having trouble trying to make a simple counter.
x = x[1] + 1;
in formula script I am using:
x : ref(x,1) + 1
I get an error 0165 Use of unassigned local variable 'X'
Does anyone have the correct method of getting a variable to increment per each loop
How does one create a counter
Moderator: Chris White
-
- Posts: 212
- Joined: Mon Nov 29, 2010 9:21 pm
Re: How does one create a counter
Hi,
The Scripting language is an array language rather than a procedural language and so it does not have constructs such as X = X + 1 (well, actually you can write something like that but it has a different meaning, see below).
You can create an array with incrementing numbers using:
Count(C, 0);
If you add this to a chart you will see a line increasing in value by 1 each bar from the first bar of data to the last bar of data.
In the scripting language if you tried:
X: C + 1;
You would be taking the array containing Close prices and adding 1 to every element.
The Scripting language is an array language rather than a procedural language and so it does not have constructs such as X = X + 1 (well, actually you can write something like that but it has a different meaning, see below).
You can create an array with incrementing numbers using:
Count(C, 0);
If you add this to a chart you will see a line increasing in value by 1 each bar from the first bar of data to the last bar of data.
In the scripting language if you tried:
X: C + 1;
You would be taking the array containing Close prices and adding 1 to every element.