MultiCharts | PowerLanguage Tutorials | CH3: Input and Variable

Input and Variable

Input and variable can be thought as a container (Ex: bottle) that stores the desired value (Ex: 5 liters).
But before using this container, you need to declare it first. The declaration tells the compiler the type of the value to be stored and compiler, according to the type, allocates the required memory size.

Therefore, the using of input and variables can be divided into two phases:

  • The 1st phase – declaration: Declare the name of input or variable, give default values or initial values respectively which defines Type. Type can be Numerical, String or TrueFalse.
  • The 2nd phase – usage: Specify the name of the input or variable in the code. When the program executes to the input or variable name, it uses the stored value.

Type

Type represents the meaning and operation of the value.
There are three types: Numerical, String and TrueFalse.

Numerical

Use the number to represent the Numerical type.
The expression 1+1 program will know to perform addition, and the result is the number: 2.

Numerical can be divided into NumericSimple and NumericSeries.

In the signal script or indicator script, the default value of input declaration determines the type is NumericSimple or NumericSeries.
In the signal script or indicator script, the initial value of variable declaration determines the type is NumericSimple or NumericSeries.

NumericSimpleThe value of NumericSimple is a constant that doesn’t change between bars, so it doesn’t has historical value.
NumericSimple is also a reserved word used in function scripts to declare that the input is of type NumericSimple.
NumericSeriesThe value of NumericSeries will change between bars, Ex: Close(closing price), so it has historical values.
Use N bars ago or [N] to obtain the historical value of the previous N bars, EX: Close 2 bars ago or Close[2].
NumericSeries is also a reserved word used in function scripts to declare that the input is of type NumericSeries.
NumericSimpleNumericSeries

String

Use two double quotation marks ("") to enclose the content to represent the String type.
The "12" represents the String type and the expression "12"+"34" program will know to perform addition of two string, and the result is the String: "1234".
String can be divided into StringSimple and StringSeries.

In the signal script or indicator script, the default value of input declaration determines the type is StringSimple or StringSeries.
In the signal script or indicator script, the initial value of variable declaration determines the type is StringSimple or StringSeries.

StringSimpleThe value of StringSimple is a constant that doesn’t change between bars, so it doesn’t has historical value.
StringSimple is also a reserved word used in function scripts to declare that the input is of type StringSimple.
StringSeriesThe value of StringSeries will change between bars, so it has historical values.
Use N bars ago or [N] to obtain the historical value of the previous N bars.
StringSeries is also a reserved word used in function scripts to declare that the input is of type StringSeries.
StringSimpleStringSeries

TrueFalse

Use the reserved words true and false to represent TrueFalse types, true represents logical true, and false represents logical false.
TrueFalse can be divided into TrueFalseSimple and TrueFalseSeries.

In the signal script or indicator script, the default value of input declaration determines the type is TrueFalseSimple or TrueFalseSeries.
In the signal script or indicator script, the initial value of variable declaration determines the type is TrueFalseSimple or TrueFalseSeries.

TrueFalseSimpleThe value of TrueFalseSimple is a constant that doesn’t change between bars, so it doesn’t has historical value.
TrueFalseSimple is also a reserved word used in function scripts to declare that the input is of type TrueFalseSimple.
TrueFalseSeriesThe value of TrueFalseSeries will change between bars, so it has historical values.
Use N bars ago or [N] to obtain the historical value of the previous N bars.
TrueFalseSeries is also a reserved word used in function scripts to declare that the input is of type TrueFalseSeries.
TrueFalseSimpleTrueFalseSeries

Input

Below is the declaration syntax in the signal script and indicator script. The declaration syntax of the function script see function.

Declaration Syntax

Input: InputName1(DefaultValue1), InputName2(DefaultValue2), etc;

inputs: declare input.
InputName: The name of the input. The name is not case-sensitive and cannot start with a number or a period.
DefaultValue: The default value of the input. The default value determines the Type. Type can be Numerical, String or TrueFalse.
Note: A semicolon should be added at the end of the input declaration. If it is not added, a compilation error will occur.

You can set the default value of the input of the signal script or indicator script from the MultiCharts.
If no new default value is set from MultiCharts, the DefaultValue defined in the script will be set.

The new default value set form MultiCharts can be applied directly by executing it without recompilling it.

The input value can only be set and changed through the default value. After setting, the input value cannot be changed through the code in the script.

Example

Input: Length(20);
Input: Price(Close), Name("Last Close");
Input: Draw_Line(True);

Variable

Below is the declaration syntax in the signal script and indicator script. The declaration syntax of the function script see function.

Declaration syntax

Variable: [IntraBarPersist]VariableName1(InitialValue1[,DataN]), [IntraBarPersist] 
VariableName2(InitialValue2[,DataN]),etc.

variables: declare variable.
VariableName – The name of the variable. The name can be composed of letters, underscores, numbers, and periods. The name is not case-sensitive in English. The name cannot start with a number or a period.
InitialValue – The initial value of the variable. The initial value determines the Type. The Type can be Numeric, String or TrueFalse.
Note: A semicolon should be added at the end of the variable declaration. If it is not added, a compilation error will occur.

You can not set the initial value of variable from MultiCharts similar to the input does.
The variable value can be set through the initial value and also can be changed through the code in the script (assigned other values).

Example

Variable: IntraBarPersist Max(100);
Variable: Min_Price(Close,Data2);
Variable: Overnight(False),Name("Intra-Day");

Reference

https://www.multicharts.com/trading-software/index.php?title=Input

https://www.multicharts.com/trading-software/index.php?title=Variable

Leave a Reply