WealthScript: basic syntax
67Semicolons at the end of each statement
Each WealthScript statement must end with the semicolon character (;). The semicolon lets WealthScript know that one statement is completed and another one is beginning.
Comments
Single Line Comments
Use the "//" characters to create single line comments.
Example
//This is truly the Holy Grail of Trading Systems!
Comment Blocks
Use the curly braces to create a comment block.
Example
{ This is a comment block this text will not be executed by the script }data types
integer
Stores whole number values. Values can range from -2,147,483,648 to 2,147,483,647. You can perform mathematical Operations on integer variables.float
Stores floating point values. Values can range from 1.5 x 10^-45 to 3.4 x 10^38, and will maintain 7 to 8 significant digits. You can perform mathematical Operations on float variables.string
Can store textual data of any length. You can perform string Operations on string variables.boolean
Can contain one of two logical values: true or false. You can perform logical Operations on boolean variables.var statement to declare a variable
You can declare multiple variables of the same data type with a single var statement.
Example
var MyVariable: integer;
var Var1, Var2: integer;var Var1: integer; var Var2: float;var Name, Rank, Serial_Number: string;var YesNo: boolean;assignment operator (:=)
Example
var n: integer;n := 100;var s: string;s := 'My name is Smith';var f: float;f := 3.1415;var b: boolean;b := true;
For Loop
Example
var n: integer;var x: float;x := 2;{ Repeat a single statement 10 times }for n := 1 to 10 do x := x * 2;{ Repeat a group of statements 10 times }for n := 1 to 10 dobegin x := x * 2; x := x + 5;end;{ Use the index variable in the loop }for n := 1 to 10 dobegin x := x + n * 2; x := x / n;end;
If/Then/Else Statements
You must use a begin/end statement pair to create a "code block" that encloses the statements.
Example 1
var x: integer;
x := 10;
{ This if/then will execute 3 statements }
if x * 2 = 20 then
begin
x := x * 2;
x := x - 1;
x := x / 10;
end;
Example 2
{ if/then/else with begin/end blocks, with code in the blocks }var x: integer;x := 10;if x < 10 thenbegin x := x * 2 + 1; x := x / 5;endelsebegin x := x * x; x := x / 2;end;Case Statement
Example
var n: integer;n := Round( Random * 5 ) + 1;case n of 1: ShowMessage( 'One' ); 2: ShowMessage( 'Two' ); 3: ShowMessage( 'Three' ); 4: ShowMessage( 'Four' ); else ShowMessage( 'None of the Above' );
end;
Example
var n: integer;n := Round( Random * 10 ) + 1;case n of 1, 2: begin ShowMessage( 'One, Two' ); ShowMessage( 'Buckle my Shoe' ); end; 3, 4: begin ShowMessage( 'Three, Four' ); ShowMessage( 'Trade Some More' ); end; else ShowMessage( 'Collect your Profits now!' );end;
While / Repeat Loop
While Example
var n1, n2: integer;
n1 := 10;
n2 := 50;
while ( n1 < n2 ) do
n1 := n1 + 3;
Repeat Example
var n1, n2: integer;
n1 := 10;
n2 := 50;
repeat
n1 := n1 + 3;
until ( n1 > n2 );






