General

**Formula Concepts**

**Lifetime of a formula**

A formula is created/instantiated/constructed when it is added to a chart. Upon being created, the **preMain**() function is called once for that formula and then the **main**() function is called for each available bar.. A formula is re-created (destructed and re-constructed) when the properties of the formula change (via the Edit Studies menu).

A formula is destroyed/destructed when the chart containing the formula is closed.

**Lifetime of global variables**

Global variables come to life the first time **setGlobalValue**(…) is called. The global variable will remain available in the global variable pool until **removeGlobalValue**(…) is called, or when the application is closed.

**Formula Iteration.**

The **main**() function is used to build individual bars. It is called once for each bar on a chart. Bars are iterated from right to left (or from the oldest to the newest bar). Everytime a tick occur, the **main**() function is called to iterate the most recent bar (most recent data).

**Operators **

**Arithmetic **

+ //plus

++ //increment

- //minus

-- //decrement

* //multiply

/ //divide

% //modulus

**String Operators**

+ //concatenate

+= //append

**Logical Operators**

&& //AND

|| //OR

! //NOT

**Bitwise Operators**

& //Bitwise AND

^ //Bitwise XOR

| //Bitwise OR

~ //Bitwise NOT

<< //Bitwise LEFT SHIFT

>> //Bitwise RIGHT SHIFT

**Assignment Operators**

= //IS EQUAL TO

+= //n = n + x;

-= //n = n - x;

*= //n = n * x;

/= //n = n / x;

%= //n = n % x;

&= //n = n & x;

^= //n = n ^ x;

|= //n = n | x;

<<= //n = n << x;

>>= //n = n >> x;

**Comparison Operators**

== //is Equal To

!= //is Not Equal To

> //is Greater Than

>= //is Greater Than or Equal To

< //is Less Than

<= //is Less Than or Equal To

**Reserved Words/Statements**

break

comments

continue

do…while

for

for…in

function

if…else

return

switch

var

while

with

See Also: