Bot fundamentals \ Variables

The concept of Variables is one of the most important concepts in software programming and an essential part of almost any trading robot.

So, what is a variable?

Let’s say you are helping your friend move out of his house. The thing is, he is not good at packing. He has asked you to help him pack his stuff. Now, as you pack, you can think of the boxes as variables.


You can put anything you want inside, and you can replace it later with something of the same category. Then you’ll label the boxes to know what these boxes are holding in. That way, when your friend looks for the pictures of his puppy dog ‘Max’, he’ll know where to find them. This is called the Name of the variable.

Variables works the same way as this metaphor. They are a storage location with assigned names that hold data that you can use and change later. You can replace the content of a box with something else, and you can change the data stored in a variable (it’s value). That’s why they are called variables.

Creating variables

Creating variables is easy in Binary Bot and DBot. Once you created a variable, you can access if from any part of the your strategy.

So, let’s create a variable and assign it a value with DBot.

..and Binary Bot.

It’s important that you name variables meaningfully rather than undescriptive or random.

It’s like you were making donuts and you had three jars labeled x, y and z. You wouldn’t know which one’s your flour, which one’s your sugar, and which one’s your salt. Mixing up your variable names, or in this case jars, could lead to many issues… or some salty donuts.

So using meaningful names will help you easily identify the use of that variable later on in your strategy.

Assigning values to variable

Much like boxes, variables can hold a whole variety of different categories. In programming these things would be known as Data Types.

A variables data type determines the type of data that it can hold hence the name data type.

Programming languages have many different data types such as numeric, strings, boolean, etc. We won’t go into details of exactly what these data types do in this course, but remember - data types tell you what kind of values variables hold.

Binary Bot and DBot identify data types implicitly, when you assign values to variables. There are only 3 data types available: text, numbers, and boolean. In the below example, current stake is number and Text message is text.

Binary bot


Deriv (Investments) Europe Ltd (W Business Centre, Level 3, Triq Dun Karm, Birkirkara BKR 9033, Malta) is licensed in Malta and regulated by the Malta Financial Services Authority under the Investment Services Act to provide investment services in the European Union (licence no. IS/70156). It is also authorised and subject to limited regulation by the Financial Conduct Authority in the UK. Details about the extent of our authorisation and regulation by the Financial Conduct Authority are available from us on request.

Deriv (MX) Ltd, Millennium House, Level 1, Victoria Road, Douglas IM2 4RW, Isle of Man, is licensed and regulated in Great Britain by the Gambling Commission under account no. 39172 and by the Gambling Supervision Commission in the Isle of Man.

Deriv (Europe) Limited, W Business Centre, Level 3, Triq Dun Karm, Birkirkara BKR 9033, Malta, is licensed and regulated for synthetic indices by the Malta Gaming Authority (licence no. MGA/B2C/102/2000), by the Gambling Commission for clients in Great Britain (account no. 39495), and by the Revenue Commissioners for clients in Ireland (licence no. 1010285).

Deriv Investments (Europe) Ltd is authorised to deal on its own account and is both the manufacturer and distributor of its products.

This information is intended for Retail & Professional clients.

CFDs offered by Deriv Investments (Europe) Ltd are considered complex derivatives and may not be suitable for retail clients.They may be affected by changes in currency exchange rates; If you invest in this product you may lose some or all of the money you invest; The value of your investment may go down as well as up.
CFDs offered by Deriv Investments (Europe) ltd also come with a high risk of losing money rapidly due to leverage. 63% of retail investor accounts lose money when trading CFDs with Deriv Investments (Europe) ltd. You should consider whether you understand how CFDs work and whether you can afford to take the high risk of losing your money.

+18 Icon Please trade responsibly. For more information about responsible trading please click here.