A PROPERTY is an input parameter that can be set by the user outside the script to influence the calculation within the script. It is possible to set the Property value in the Indicator / Trading-System configuration window.
There is no limit on the number of Properties that can be defined in a script. However, we recommend you define only the strictly necessary properties in order not to complicate the configuration unnecessarily.
Property <name> As <data type> <attributes> EndProperty
A property begins with Property keyword and ends with EndProperty keyword.
In the first line of property, immediately after Property keyword, the property name is defined.
After the property name, in the same line, <data type> is defined.
A property can be Numeric, Date, Time, Database, Indicator (see data types documentation).
Inside the Property and EndProperty keywords you can define the following attributes:
INFO: allows you to specify the property description. Description is displayed for example in the Indicator / Trading-System configuration window.
LIST: allows you to define a list of values for the property. Each LIST attribute corresponds to a list item. Property will appear in the configuration window as a combo-box. This attribute is NOT usable in conjunction with RANGE attribute.
List ("<item name>", <value>)
RANGE: allows you to define the property validity range. This attribute is NOT usable in conjunction with LIST attribute..
Range (<minimum value>, <maximum value>)
DEFAULT: allows you to define the property default value.
Attributes you can use in a property depend on the property data type:
- In Numeric, Date and Time properties you can use INFO, LIST (or RANGE), and DEFAULT attributes.
- In Database and Indicator properties (representing a data series) you can only use INFO attribute.
Properties must be defined at script level, that is, externally to all functions. We recommend you define all properties at the beginning of the script.
'Property will appear in the configuration window as a text box. Property Period As Numeric Info "Calculation period" Range (5, 1000) Default (21) EndProperty 'Property will appear in the configuration window as a combo-box. Property Period As Numeric Info "Calculation period" List ("Low", 20) List ("Middle", 50) List ("High", 100) Default (20) EndProperty 'Property represents the data series of an indicator or the Open / High / Low / Close data series of the underlying instrument. Property Reference As Indicator Info "Reference Indicator" EndProperty 'Property represents an instrument. Property DB As Database Info "Reference instrument" EndProperty
An Indicator property is particularly useful if you want to build an indicator on indicator. Using this property within the script you will be able to access the data series of an external indicator and use it to calculate, for example, its moving average or for any other type of calculation.
Property value is accessible within the script using its name, just like any variable. The only difference is that a Property is read only, that is, you cannot change its value within the script.
Property Period As Numeric Info "Calculation period" Range (5, 1000) Default (21) EndProperty Function Main() Dim Total As Numeric = 0 Dim i As Numeric = 0 'Period property is used in the calculation as a 'read-only' variable. For i = 0 To Period - 1 Total = Total + Close(-i) Next i Return Total / Period EndFunction