Bot fundamentals / variables

Hi Deriv Community,

Here is introducing you to 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.

image

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

DBot

We hope this information helps.

Contact Us | Online Trading | Deriv.com 1

Online trading with Deriv | Simple. Flexible. Reliable.

Trading platforms designed with you in mind.