Comment on page

# Variables and constants

You can create constants and variables in BotBrains robots. Variables and constants provide maximum flexibility for trading robots. The value of variables can be changed using special blocks, variables can be used as parameters of blocks. The value of constants can not be changed, constants can be used as settings of a trading robot.

## Constants

The value of a constant cannot be changed. The value of a constant is defined once the robot is launched - it cannot be changed afterward.
Constants may be used as robot settings. For example, you can create a "symbol" constant, which will contain the code of the symbol being traded.
An unlimited number of constants may be used in one robot.

## Variables

The value of a variable may be changed. There are special blocks for this: "Set variable simple value" and "Set variable complex value".
For example, you can create a "lots" variable, which will contain the number of traded lots. You can increase or decrease the value of this variable, thereby changing the number of traded lots.

## Variables and constants creation

To create variables or constants, go to the robot's settings. In the "Variables" and "Constants" sections, you can set the names and initial values of variables and constants: Variables and constant names may contain only latin letters, numbers, and the underscore character. Choose straightforward and understandable variable and constant names.

## Using variables and constants

### In other blocks

Using the "variable select" and "constant select" blocks, you can use variables and constants in other blocks.
The screenshot below shows an example of using the "variable select" block in the condition block: ### As block settings parameters

Variables and constants can be used as block settings. In the block settings window, each parameter has a switcher on the right that determines what will be used as the value of the block parameter.
There are 3 ways to set the value of a block parameter:
1. 1.
Simple value - the parameter value is set using the input field
2. 2.
Variable - the value of the parameter will be equal to the current value of the variable
3. 3.
Constant - the value of the parameter will be equal to the value of a constant
The screenshot below shows an example of using constants as parameters of the "Adaptive Moving Average" block: ## Constants as robot settings

Constants can be used as robot settings. That is, before starting the robot, you can change the value of a constant and thereby change robot behavior.
If a robot has some constants, all constants will be listed at the very top of the generated code: In the example above, the "symbol" constant is specified - it stores the code of the symbol being traded. If at some point we want our robot to trade a different symbol, we can simply change the value of this constant by writing a different value between the double quotes. To do this, specify a new constant value in the file with the robot code, save the file and compile it.
Every time you make changes to the file with the trading robot code, do not forget to save and compile it!
If you don't want to work with the file directly, you can simply change the constant value in the BotBrains editor and re-generate the code.