User login

  

Type, Values and Variables

Seven data types are available in PTL:

string

A sequence of zero or more Unicode characters, enclosed in double quotes.
Examples: "a", "Hello world!", "$100"

int

A positive or negative whole number ranging from
–2,147,483,648 to 2,147,483,647.
Examples: –1, 15, 2,359,674.

 

double

A floating-point number ranging from –1.79769313486232e308 to 1.79769313486232e308, or -infinity, or infinity, or NaN (not a numeric)
Examples: –17.25, 19.20, 8,400,321.1252.

 

bool

A Boolean value – true or false.

 

datetime

An instant in time between 12:00:00 midnight, January 1, 0001  to 11:59:59 P.M., December 31, 9999.
Can be both date and time or only date or only time.
Examples: 633447267696875000

 

char

A single 2-byte Unicode character, enclosed in single quotes.
Examples: 'a', '!', '2', '¢ '

 

color

A color designation.

Values: AliceBlue, AntiqueWhite, Aqua, Aquamarine, Azure, Beige, Bisque, Black, BlanchedAlmond, Blue, BlueViolet, Brown, BurlyWood, CadetBlue, Chartreuse, Chocolate, Coral, CornflowerBlue, Cornsilk, Crimson, Cyan, DarkBlue, DarkCyan, DarkGoldenrod, DarkGray, DarkGreen, DarkKhaki, DarkMagenta, DarkOliveGreen, DarkOrange, DarkOrchid, DarkRed, DarkSalmon, DarkSeaGreen, DarkSlateBlue, DarkSlateGray, DarkTurquoise, DarkViolet, DeepPink, DeepSkyBlue, DimGray, DodgerBlue, FireBrick, FloralWhite, ForestGreen, Fuchsia, Gainsboro, GhostWhite, Gold, Goldenrod, Gray, Green, GreenYellow, Honeydew, HotPink, IndianRed, Indigo, Ivory, Khaki, Lavender, LavenderBlush, LawnGreen, LemonChiffon, LightBlue, LightCoral, LightCyan, LightGoldenrod, LightGreen, LightGrey, LightPink, LightSalmon, LightSeaGreen, LightSkyBlue, LightSlateGray, LightSteelBlue, LightYellow, Lime, LimeGreen, Linen, Magenta, Maroon, MediumAquamarine, MediumBlue, MediumOrchid, MediumPurple, MediumSeaGreen, MediumSlateBlue, MediumSpringGreen, MediumTurquoise, MediumVioletRed, MidnightBlue, MintCream, MistyRose, Moccasin, NavajoWhite, Navy, OldLace, Olive, OliveDrab, Orange, OrangeRed, Orchid, PaleGoldenrod, PaleGreen, PaleTurquoise, PaleVioletRed, PapayaWhip, PeachPuff, Peru, Pink, Plum, PowderBlue, Purple, Red, RosyBrown, RoyalBlue, SaddleBrown, Salmon, SandyBrown, SeaGreen, Seashell, Sienna, Silver, SkyBlue, SlateBlue, SlateGray, Snow, SpringGreen, SteelBlue, Teal, Thistle, Tomato, Turquoise, Violet, Wheat, White, WhiteSmoke, Yellow, YellowGreen.

Examples: color a = Red;

 

Scope of a declarations

The scope of a declaration is a region of the program within which the entity declared by the declaration can be referred to using a sample name.
In terms of scope, variables can be local, internal, external, and global.

 

Local

A local variable is declared within a function, and its scope is limited to that function. A local variable is declared without any specifiers, for example:

double LHC;  // large hadron collider
bool result = true;

 

Internal

An internal variable is a variable global within the scope of the current module. The declaration must start with the internal identifier, for example:
internal int direction = 1;

 

Global

Global variable is a variable that can be accessed from any modules. Also, global variables saved own state between function call. Declaration example:
global string welcome = "welcome";

 

Conversions

The variable of  type color can be converts to type int. The variable of  type int can be converts to type double. The variable of  type int or double, or char, or boolean can be converts to type string. About other conversions see at section .

 

Constants

A constant is an identifier for a value of any data type that is not supposed to change during the execution of the script. In terms of scope, constants can be local, internal, external, and global. The global end external constants are reserved for future use with multi-module projects.
A constants are defined with the keyword const.

 

Local

A local constant is the constant accessible from within the function where it is declared. A local constant is declared without any specifiers, for example:
    const double PI = 3.14159;
    const string Exc_LIMIT = "The limit is exceeded";

 

Internal

An internal constant is a constant global within the scope of the current module. Declaration example:
    internal const int No_TREND = 0;

 

Global

Global is a constant that can be referred to from other modules in the project. Declaration example:
     global const int A = 1;

 

External

An external constant is a constant from another module referred to in the current module. In that other module, such constant should be declared as global. Supposing that the above-illustrated constant was declared in a module named module2, it will be declared in the current module as follows:
       external from module2 const int A;

 

The constant's value must be of the same type as the declared data type. You cannot have something like
        const string S = 5;
or
        const int N = 6.25;

 


Variables Declaration and Definition

Each variable must be declared before using. Do not mix declaration with definition! Variable declaration is only next construction: [datatype] [identifier];

Example, declare local variable:
int n;

Example, definition of previous variable:
n = 5;

Of course, you can declare and define variable in one construction, BUT it's possible only when right-value is constant, example:
int n = 5;             // correct, right-value is constant
int n = sum(5, 4)    // incorrect, right-value should be constant

 

Note! To definition variable use only constant value, but not expressions. Example of correct definition:

      double A = 5.12789;
      string str = "Hello, world!";

Example of incorrect declarations and definitions:

     int sum = 5 + 7;
     double res = SomeFunction();
     int variable = 5*6+7;

 


Simple Color and DateTime initialing

You can use the simple way to set value of color variable like below:
color pabelColor = C'128,158,76';

There is color in RGB color model.

The RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green, and blue.

 

The main purpose of the RGB color model is for the sensing, representation, and display of images in electronic systems, such as televisions and computers, though it has also been used in conventional photography. Before the electronic age, the RGB color model already had a solid theory behind it, based in human perception of colors.

 

In example, the color has 128 parts from 255 Red color, 158 parts from 255 Green color and 76 parts from 255 Blue color. With RGB color model you can specify any color. It's easy!

Also, you have the simple way to set value of datetime variable like below:

datetime dt1 = D'2008.12.12 15:48:16';  // the date and full time
datetime dt2 = D'2009.02.05 10:01';        // the date and time
datetime dt3 = D'2009.01.30';                    // only the date

 The format for date and time is next: D'YYYY.MM.DD HH:II:SS'
where YYYY is year, MM is month, DD is day, HH is hours, II in minutes, SS is seconds.

Of course, you can write as in example above, because C'128,158,76'; and D'2009.02.05 10:01'; are literals, not function or variables.

 

Input Type Variables

Input type variables represent user-defined parameters of an indicator or strategy, accessed and set from the trading terminal via the Settings dialog boxes. These variables are declared like regular global variables, preceded by the keyword input. The value assigned to the variable at declaration is the default parameter value appearing in the dialog box (Value column). Each input type variable must have a descriptive name that will represent it in the dialog box (Name column), defined in parentheses after the variable declaration, for example:

input int FastSmoothPeriod = 2 ("Fast Smoothing Constant");

Constraining Numeric Variables

Input type variables can have optional constraining attributes defined for more control over user input. For numeric (int, double) variables, you can control the range of values (minimum and maximum values) the user enters, and define the increment of the parameter. For variables of type double, you can additionally specify the number of decimals displayed to the user in the dialog box.

Example

Consider the following variable declared in the Aroon indicator project:

input double UpSignalLine = 70 ("Up signal line")
min = 0 max = 100 inc = 1 dec = 2;

The descriptive name defined for the variable, Up signal line, is displayed in the Name column. In the Value column, the value assigned to the variable, 70, is displayed with two digits after the decimal point. Each click on the up and down arrows increments or decrements the parameter by 1, respectively. If the value entered by the user is less than 0, the parameter will be set equal to 0. If the value entered is greater than 100, the parameter will be set equal to 100.

Note:Specifying an increment does not prevent a user from typing in a value in between the incremented intervals.

 

Limiting a Variable to a Predefined Set of Values

Input variables of int, string, double, color data type can be limited to a predefined set of values. A variable intended to take one of the predefined values must have such values listed as semicolon-separated pairs enclosed in curly brackets. The first member of the pair is the parameter value as shown to the user in the dialog box, and the second is the actual value the variable takes.

Example

Consider the following variable declared in the 3MACrossesAdvisor strategy project:

input string ShortMAType = "SMA" ("Short Moving Average Type")
{"Simple"; "SMA"}
{"Exponential"; "EMA"}
{"Modified"; "MMA"}
{"Linear Weighted"; "LWMA"};

On the General tab of the Settings dialog box the descriptive name defined for the variable, Short Moving Average Type, is displayed in the Name column. In the Value column, a drop-down list appears containing the four possible user choices: Simple, Exponential, Modified, and Linear Weighted, with Simple listed first and selected by default. When Modified is selected as shown, the ShortMAType variable takes the value of "MMA".

12345

Comments