How does one create a counter

This is the place to discuss EdgeRater Chart Script

Moderator: Chris White

Post Reply
bsegura
Posts: 32
Joined: Tue Jan 12, 2021 11:56 am

How does one create a counter

Post by bsegura »

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
Chris White
Posts: 200
Joined: Mon Nov 29, 2010 9:21 pm

Re: How does one create a counter

Post by Chris White »

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.
Post Reply