Standard blocks: logic, math, text, lists, variables and functions

Plain-English guide to the everyday blocks for tests, numbers, text, lists, loops, variables and your own functions, with simple Bot Builder examples.

These are the everyday building blocks of every bot. They test conditions, do maths, handle text and lists, remember values, repeat steps and let you build your own functions. They sit in the Utility menu, in the groups Custom functions, Variables, Notifications (Print and Request an input), Math, Text, Logic, Lists and Loops. Action blocks go inside a root block such as Purchase conditions and run from top to bottom, while value and true/false blocks plug into sockets (the open spaces on blocks) and are worked out first, from the inside out. Words used below: a variable is a named box that holds a value for later, and a list is an ordered row of values. Counting places in lists and text starts at 1, not 0. None of these blocks trade by themselves, protect your money or predict the market.

Logic

Conditional block

  • Kind: Official (Deriv)
  • Type id: controls_if
  • Shape: Action block
  • Where it goes: Inside a root block such as 2. Purchase conditions, 3. Sell conditions or 4. Restart trading conditions (also inside a function, a loop or an if). You can use it as many times as you like.
  • What it does: Runs the blocks inside only when a test is true. With the plus icon you can add an else part for when the test is false, and more else if tests.
  • Inputs:
    • if socket: a true/false block. It must be filled.
    • then slot: the blocks to run when the test is true.
    • Plus icon: the first click adds else, the next clicks add else if (each with its own test and slot). The minus icon removes one.
  • How it works: The bot checks the first test. If it is true it runs the first slot and skips the rest. If not it checks each else if in order, and at the end it runs the else slot if there is one.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ if  < ( Last Digit ) ≥ ( 5 ) >                             │
│ then  Purchase [ Rise ▾ ]                                  │
│ else                                                       │
│       Notify [ blue ▾ ] with sound: [ Silent ▾ ]           │
│          ( "wait" )                                        │
└────────────────────────────────────────────────────────────┘

If the last digit is 5 or more the bot buys; otherwise it writes "wait" in the Journal.

  • Good to know:
    • Only a true/false block fits in the if socket. Build the test with Compare, Logic operation and the like.
    • Without an else part, a false test simply does nothing and the bot moves on.

Compare

  • Kind: Official (Deriv)
  • Type id: logic_compare
  • Shape: True/false block
  • Where it goes: Anywhere a true/false is wanted, such as the test of an if. You can use it as many times as you like.
  • What it does: Compares two values and tells you if the comparison is true.
  • Inputs:
    • Left socket: the first value. The block marks itself red and the bot will not start if this is empty.
    • Operator dropdown: =, ≠, <, ≤, >, ≥. The first choice, =, is the default.
    • Right socket: the second value. The block marks itself red and the bot will not start if this is empty.
  • Gives back: True or false.
  • How it works: The bot works out both sides and tests them with the chosen sign. The = test is relaxed: the number 5 and the text "5" count as equal.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ if  < ( Last Digit ) = ( 7 ) >                             │
│ then  Purchase [ Rise ▾ ]                                  │
└────────────────────────────────────────────────────────────┘

The bot buys only when the last digit is exactly 7.

  • Good to know:
    • ≠ means "is not equal to". ≤ means "less than or equal to".
    • Compare numbers with numbers. Comparing a word with a number is allowed but rarely what you want.

Logic operation

  • Kind: Official (Deriv)
  • Type id: logic_operation
  • Shape: True/false block
  • Where it goes: Anywhere a true/false is wanted, such as the test of an if. You can use it as many times as you like.
  • What it does: Joins two true/false tests into one. With and, both must be true. With or, one is enough.
  • Inputs:
    • Left socket: a true/false block. The block marks itself red and the bot will not start if this is empty.
    • Dropdown: and, or. Default: and.
    • Right socket: a true/false block. The block marks itself red and the bot will not start if this is empty.
  • Gives back: True or false.
  • How it works: The bot works out both sides and combines them. and gives true only if both are true. or gives true if at least one is true.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ if  < < ( Last Digit ) ≥ ( 5 ) > and                       │
│       < ( Balance: [ number ▾ ] ) > ( 20 ) > >             │
│ then  Purchase [ Rise ▾ ]                                  │
└────────────────────────────────────────────────────────────┘

The bot buys only if the last digit is 5 or more AND the balance is above 20.

  • Good to know:
    • For three tests, put one Logic operation inside another.
    • Use it to say several things must all be true before you buy.

Logic negation

  • Kind: Official (Deriv)
  • Type id: logic_negate
  • Shape: True/false block
  • Where it goes: Anywhere a true/false is wanted, such as the test of an if. You can use it as many times as you like.
  • What it does: Turns true into false and false into true.
  • Inputs:
    • Socket (after the word not): a true/false block. The block marks itself red and the bot will not start if this is empty.
  • Gives back: The opposite of what is plugged in.
  • How it works: The bot works out the block inside and flips the answer.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ if  < not < ( Last Digit ) = ( 0 ) > >                     │
│ then  Purchase [ Rise ▾ ]                                  │
└────────────────────────────────────────────────────────────┘

The bot buys when the last digit is anything except 0.

  • Good to know:
    • Often a Compare with ≠ says the same thing in a shorter way.

True-False

  • Kind: Official (Deriv)
  • Type id: logic_boolean
  • Shape: True/false block
  • Where it goes: Anywhere a true/false is wanted, such as the test of an if. You can use it as many times as you like.
  • What it does: A fixed answer: always true or always false. Handy as a switch while you test.
  • Inputs:
    • Dropdown: true, false. Default: true.
  • Gives back: True or false, as chosen.
  • How it works: The block just hands its chosen answer to the block it is plugged into.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ if  < true ▾ >                                             │
│ then  Purchase [ Rise ▾ ]                                  │
└────────────────────────────────────────────────────────────┘

The test is always true, so the bot always buys. Switch it to false to turn the step off.

  • Good to know:
    • Changing it to false is a quick way to switch a step off without deleting blocks.

Null

  • Kind: Official (Deriv)
  • Type id: logic_null
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a value is wanted, for example in a Set variable.
  • What it does: Means "nothing": an empty value. Use it to say a variable has no value yet.
  • Gives back: The empty value null.
  • How it works: The block hands the word null to the block it is plugged into.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ result ▾ ] to ( null )                               │
└────────────────────────────────────────────────────────────┘

The variable "result" is set to nothing.

  • Good to know:
    • Null is not the same as 0 or an empty text. It means that there is nothing at all.

Test value

  • Kind: Official (Deriv)
  • Type id: logic_ternary
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Picks one of two values, depending on a test. It is a one-line if.
  • Inputs:
    • test socket: a true/false block. The block marks itself red and the bot will not start if this is empty.
    • if true socket: the value to give when the test is true. The block marks itself red and the bot will not start if this is empty.
    • if false socket: the value to give when the test is false. The block marks itself red and the bot will not start if this is empty.
  • Gives back: The value from if true or the value from if false.
  • How it works: The bot works out the test. If it is true it gives the if true value, otherwise the if false value. Only the chosen side is used.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ stake ▾ ] to                                         │
│   ( test < ( Last Digit ) ≥ ( 5 ) >                        │
│     if true ( 2 )  if false ( 1 ) )                        │
└────────────────────────────────────────────────────────────┘

The variable "stake" becomes 2 when the last digit is 5 or more, and 1 otherwise.

  • Good to know:
    • The answer can be any value: a number, text or list.

Math

Number

  • Kind: Official (Deriv)
  • Type id: math_number
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a number is wanted. The menu also puts one in many sockets by default. You can use it as many times as you like.
  • What it does: A number you type in. Whole numbers and numbers with decimals both work.
  • Inputs:
    • Number box. Default: 0. Use a dot for decimals, for example 0.5.
  • Gives back: The number you typed.
  • How it works: The block hands its number to the block it is plugged into. The box refuses text that is not a plain number (a minus sign, digits and one dot are fine) and refuses numbers beyond 9,007,199,254,740,991.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ if  < ( Last Digit ) > ( 4 ) >                             │
│ then  Purchase [ Rise ▾ ]                                  │
└────────────────────────────────────────────────────────────┘

The 4 is a Number block.

  • Good to know:
    • Use . (a dot) for decimals, never a comma.
    • If a typed value is refused, the box keeps the old number.

Arithmetical operations

  • Kind: Official (Deriv)
  • Type id: math_arithmetic
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Adds, subtracts, multiplies, divides or raises one number to the power of another.
  • Inputs:
    • Left socket: a number. If it is empty the code uses 0.
    • Dropdown: +, -, *, /, ^ (power). The menu block starts on +.
    • Right socket: a number. If it is empty the code uses 0.
  • Gives back: A number.
  • How it works: The bot works out both sides and applies the sign. ^ means "to the power of": 2 ^ 3 is 2 times 2 times 2, which is 8.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ stake ▾ ] to ( ( stake ) * ( 2 ) )                   │
└────────────────────────────────────────────────────────────┘

The stake is doubled.

  • Good to know:
    • An empty socket counts as 0, which can give a surprise. Fill both sockets.
    • The sockets accept blocks that give numbers, and variables.

Operations on a given number

  • Kind: Official (Deriv)
  • Type id: math_single
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Does one operation on a single number: square root, absolute value, minus sign, natural log, log base 10, e to the power, or 10 to the power.
  • Inputs:
    • Dropdown: square root, absolute, -, ln, log10, e^, 10^. The menu block starts on square root.
    • Number socket. The block marks itself red and the bot will not start if this is empty.
  • Gives back: A number.
  • How it works: The bot works out the number and applies the chosen operation. absolute drops the minus sign (-5 becomes 5). - flips the sign. ln and log10 are logarithms.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ size ▾ ] to ( absolute ( profit ) )                  │
└────────────────────────────────────────────────────────────┘

The variable "size" holds the profit without its minus sign.

  • Good to know:
    • The square root of a negative number is not a real number. Check before you use it.
    • ln and log10 are for advanced maths and are rarely needed in a bot.

Trigonometric functions

  • Kind: Official (Deriv)
  • Type id: math_trig
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Works out sin, cos, tan, asin, acos or atan of a number. Angles are in degrees.
  • Inputs:
    • Dropdown: sin, cos, tan, asin, acos, atan. The menu block starts on sin.
    • Number socket. The block marks itself red and the bot will not start if this is empty.
  • Gives back: A number.
  • How it works: For sin, cos and tan the bot first turns your degrees into the angle the computer uses. For asin, acos and atan it turns the answer back into degrees.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ wave ▾ ] to ( sin ( 90 ) )                           │
└────────────────────────────────────────────────────────────┘

The variable "wave" becomes 1.

  • Good to know:
    • You rarely need these in a trading bot. They are here for people who build their own formulas.

Mathematical constants

  • Kind: Official (Deriv)
  • Type id: math_constant
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Gives a famous fixed number such as pi.
  • Inputs:
    • Dropdown: π, e, φ (golden ratio), sqrt(2), sqrt(½), ∞ (infinity). The menu block starts on π.
  • Gives back: A number: about 3.14159 for π, 2.71828 for e, 1.61803 for φ, 1.41421 for sqrt(2), 0.70711 for sqrt(½), or infinity.
  • How it works: The block hands the chosen constant to the block it is plugged into.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ half_turn ▾ ] to ( π )                               │
└────────────────────────────────────────────────────────────┘

The variable "half_turn" holds about 3.14159.

  • Good to know:
    • Infinity is bigger than any number, so it is handy as a starting value for a smallest-value search.

Test a number

  • Kind: Official (Deriv)
  • Type id: math_number_property
  • Shape: True/false block
  • Where it goes: Anywhere a true/false is wanted, such as the test of an if. You can use it as many times as you like.
  • What it does: Checks a property of a number: even, odd, prime, whole, positive, negative, or divisible by another number.
  • Inputs:
    • Number socket (left): the number to check. The block marks itself red and the bot will not start if this is empty.
    • Dropdown: even, odd, prime, whole, positive, negative, divisible by. The menu block starts on even.
    • Extra socket: only for divisible by, it appears after the word and holds the divisor.
  • Gives back: True or false.
  • How it works: The bot checks the property. even and odd look at the remainder after dividing by 2. prime means divisible only by 1 and itself. whole means no decimals. positive means above 0 and negative means below 0.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ if  < ( Last Digit ) is [ even ▾ ] >                       │
│ then  Purchase [ Rise ▾ ]                                  │
└────────────────────────────────────────────────────────────┘

The bot buys when the last digit is 0, 2, 4, 6 or 8.

  • Good to know:
    • odd is checked as "the remainder is 1", so a negative number such as -3 is not reported as odd.
    • A prime number is a whole number above 1 that has no divisor except 1 and itself, such as 2, 3, 5, 7.

Change variable

  • Kind: Official (Deriv)
  • Type id: math_change
  • Shape: Action block
  • Where it goes: Inside a root block such as 2. Purchase conditions, 3. Sell conditions or 4. Restart trading conditions (also inside a function, a loop or an if). You can use it as many times as you like.
  • What it does: Adds a number to a variable. Use a negative number to subtract.
  • Inputs:
    • Variable dropdown: the variable to change. The default name is item.
    • by socket: the number to add. The block marks itself red and the bot will not start if this is empty.
  • How it works: The bot adds the number to the variable and stores the result back. If the variable does not hold a number yet, it starts counting from 0.
  • Example:
┌─ 4. Restart trading conditions ────────────────────────────┐
│ change [ losses ▾ ] by ( 1 )                               │
│ Trade again                                                │
└────────────────────────────────────────────────────────────┘

The variable "losses" goes up by one and the bot trades again.

  • Good to know:
    • Make the variable first with Create in the Variables menu, and give it a start value with Set variable.
    • It is the quickest way to count things, such as the number of losses in a row.

Aggregate operations

  • Kind: Official (Deriv)
  • Type id: math_on_list
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Works out one number from a whole list of numbers: sum, min, max, average, median, mode, antimode, standard deviation or a random item.
  • Inputs:
    • Dropdown: sum, min, max, average, median, mode, antimode, standard deviation, random item. The menu block starts on sum.
    • List socket: a block that gives a list, such as a list variable or Last digits list. It must be a list-giving block.
  • Gives back: A number. For mode and antimode it gives a list of the most (or least) common values.
  • How it works: The bot runs through the list and calculates the chosen result. min is the smallest item and max the largest. average is the sum divided by the number of items. median is the middle item once sorted. mode is the most common item and antimode the least common. standard deviation tells how spread out the items are around their average.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ avg ▾ ] to ( [ average ▾ ] of list ( closes ) )      │
└────────────────────────────────────────────────────────────┘

The variable "avg" holds the average of the numbers in "closes".

  • Good to know:
    • Plugging a block that does not give a list into the socket turns the block red.
    • An empty list can give a surprising answer. Check the length first.

Rounding operation

  • Kind: Official (Deriv)
  • Type id: math_round
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Rounds a number to a whole number: round, round up or round down.
  • Inputs:
    • Dropdown: round, round up, round down. The menu block starts on round.
    • Number socket. The block marks itself red and the bot will not start if this is empty.
  • Gives back: A whole number.
  • How it works: round goes to the nearest whole number. round up always goes up (3.1 becomes 4). round down always goes down (3.9 becomes 3).
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ digits ▾ ] to ( round down ( 3.9 ) )                 │
└────────────────────────────────────────────────────────────┘

The variable "digits" becomes 3.

  • Good to know:
    • Round only the end result. Rounding in the middle of a calculation can add small errors.

Remainder after division

  • Kind: Official (Deriv)
  • Type id: math_modulo
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Gives what is left over after dividing one number by another.
  • Inputs:
    • Dividend socket (after "remainder of"): the number to divide. The block marks itself red and the bot will not start if this is empty.
    • Divisor socket (after the ÷ sign): the number to divide by. The block marks itself red and the bot will not start if this is empty.
  • Gives back: A number. For 64 ÷ 10 it gives 4.
  • How it works: The bot divides the first number by the second and gives the leftover part. 64 ÷ 10 is 6 with 4 left over, so the answer is 4.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ if  < remainder of ( rounds ) ÷ ( 3 ) = ( 0 ) >            │
│ then  Purchase [ Rise ▾ ]                                  │
└────────────────────────────────────────────────────────────┘

With a counter called "rounds", the bot buys on every third round.

  • Good to know:
    • Dividing by 0 is not a sensible question. Do not plug in 0 as the divisor.
    • A common use: the remainder of a counter divided by 3 is 0 on every third round.

Constrain within a range

  • Kind: Official (Deriv)
  • Type id: math_constrain
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Keeps a number between a lowest and a highest value. If the number is too small you get the low value. If it is too big you get the high value.
  • Inputs:
    • constrain socket: the number. The block marks itself red and the bot will not start if this is empty.
    • low socket: the lowest allowed value. The block marks itself red and the bot will not start if this is empty.
    • high socket: the highest allowed value. The block marks itself red and the bot will not start if this is empty.
  • Gives back: A number between low and high.
  • How it works: The bot first lifts the number up to low if it is smaller, then pushes it down to high if it is bigger.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ stake ▾ ] to                                         │
│   ( constrain ( stake ) low ( 1 ) high ( 10 ) )            │
└────────────────────────────────────────────────────────────┘

If the stake was 14, it becomes 10. If it was 0.5, it becomes 1.

  • Good to know:
    • A handy way to stop a growing stake from going above a ceiling you chose.
    • It does not check that low is smaller than high. Keep them in the right order.

Random integer

  • Kind: Official (Deriv)
  • Type id: math_random_int
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Gives a random whole number between two numbers. Both ends can be chosen.
  • Inputs:
    • from socket: the lowest number. The block marks itself red and the bot will not start if this is empty.
    • to socket: the highest number. The block marks itself red and the bot will not start if this is empty.
  • Gives back: A whole number from the first to the second number, both included.
  • How it works: The bot picks at random. If you put the bigger number first, the code swaps them for you.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ pick ▾ ] to ( random integer from ( 0 ) to ( 9 ) )   │
└────────────────────────────────────────────────────────────┘

The variable "pick" holds a random digit from 0 to 9.

  • Good to know:
    • The numbers are random like a dice roll. They do not predict the market.

Random fraction number

  • Kind: Official (Deriv)
  • Type id: math_random_float
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Gives a random number with decimals between 0.0 and 1.0.
  • Gives back: A number from 0 up to (but not including) 1.
  • How it works: The bot picks at random each time the block is used.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ if  < ( random fraction ) < ( 0.5 ) >                      │
│ then  Purchase [ Rise ▾ ]                                  │
└────────────────────────────────────────────────────────────┘

About half of the time the bot buys.

  • Good to know:
    • Multiply it by a number to get a bigger range, for example times 100 for 0 to 100.
    • Random does not mean smart. It does not give you an edge.

Text

Text

  • Kind: Official (Deriv)
  • Type id: text
  • Shape: Value block (gives text)
  • Where it goes: Anywhere a text is wanted. The menu also puts one in many sockets by default. You can use it as many times as you like.
  • What it does: A piece of text that you type in, such as a word or a sentence.
  • Inputs:
    • Text box. In the menu it starts as abc.
  • Gives back: The text you typed.
  • How it works: The block hands its text to the block it is plugged into. It is shown between quote marks.
  • Example:
┌─ 4. Restart trading conditions ────────────────────────────┐
│ Notify [ green ▾ ] with sound: [ Silent ▾ ]                │
│   ( "Round finished" )                                     │
└────────────────────────────────────────────────────────────┘

The Text block holds the message.

  • Good to know:
    • Numbers typed in a Text block are text, not numbers. Use the Number block for maths.

Text join

  • Kind: Official (Deriv)
  • Type id: text_join
  • Shape: Action block
  • Where it goes: Inside a root block such as 2. Purchase conditions, 3. Sell conditions or 4. Restart trading conditions (also inside a function, a loop or an if). You can use it as many times as you like.
  • What it does: Builds one text out of several pieces and stores it in a variable.
  • Inputs:
    • Variable dropdown: where to store the result. The default name is text.
    • Items: a list of slots, each holding a text or any value. The plus icon adds a slot, the minus icon on a slot removes it. The menu block starts with one.
  • How it works: The bot turns each item into text and joins them into one text with a single space between the items, then stores it in the variable.
  • Example:
┌─ 4. Restart trading conditions ────────────────────────────┐
│ set [ text ▾ ] to create text with  [ + ]                  │
│   [ - ] ( "Profit:" )                                      │
│   [ - ] ( Total profit/loss )                              │
│ Notify [ blue ▾ ] with sound: [ Silent ▾ ] ( text )        │
└────────────────────────────────────────────────────────────┘

The variable "text" becomes something like Profit: 12.5 and the Journal shows it.

  • Good to know:
    • Items are always joined with one space between them.
    • Only the item blocks that belong to this block can sit in its slot.

Text Append

  • Kind: Official (Deriv)
  • Type id: text_append
  • Shape: Action block
  • Where it goes: Inside a root block such as 2. Purchase conditions, 3. Sell conditions or 4. Restart trading conditions (also inside a function, a loop or an if). You can use it as many times as you like.
  • What it does: Adds text to the end of a text variable.
  • Inputs:
    • Variable dropdown: the variable to add to. The default name is text.
    • text socket: what to add. The block marks itself red and the bot will not start if this is empty.
  • How it works: The bot turns what you plugged in into text (numbers too) and puts it at the end of the variable.
  • Example:
┌─ 4. Restart trading conditions ────────────────────────────┐
│ to [ log ▾ ] append text ( "W " )                          │
└────────────────────────────────────────────────────────────┘

Each time this runs, a "W " is added to the variable "log".

  • Good to know:
    • Set the variable to a text first, for example an empty Text block, or the result can start with the word undefined.
    • Handy for building a short record of results.

Text String Length

  • Kind: Official (Deriv)
  • Type id: text_length
  • Shape: Value block (gives a number)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Counts the characters in a text, including spaces, digits and signs.
  • Inputs:
    • Text socket (after "length of"). The block marks itself red and the bot will not start if this is empty.
  • Gives back: A number: the number of characters. "abc" gives 3.
  • How it works: The bot counts every character in the text.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ if  < length of ( "abc" ) = ( 3 ) >                        │
│ then  Purchase [ Rise ▾ ]                                  │
└────────────────────────────────────────────────────────────┘

The text has 3 characters, so the test is true.

  • Good to know:
    • To count items in a list, use List Length instead.

Text Is empty

  • Kind: Official (Deriv)
  • Type id: text_isEmpty
  • Shape: True/false block
  • Where it goes: Anywhere a true/false is wanted, such as the test of an if. You can use it as many times as you like.
  • What it does: Checks whether a text has nothing in it.
  • Inputs:
    • Text socket (between "text" and "is empty"). The block marks itself red and the bot will not start if this is empty.
  • Gives back: True if the text has no characters, otherwise false.
  • How it works: The bot checks whether the length of the text is zero.
  • Example:
┌─ 4. Restart trading conditions ────────────────────────────┐
│ if  < text ( note ) is empty >                             │
│ then  Trade again                                          │
└────────────────────────────────────────────────────────────┘

If "note" has no text, the bot trades again.

  • Good to know:
    • A space is a character, so a text with only a space is not empty.
    • The socket takes text and variables.

Search for string

  • Kind: Official (Deriv)
  • Type id: text_indexOf
  • Shape: Value block (gives a number)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Looks for a piece of text inside a longer text and tells you where it starts.
  • Inputs:
    • in text socket: the text to search in. The block marks itself red and the bot will not start if this is empty.
    • Dropdown: first, last. Default: first. Which place to report if the piece appears more than once.
    • of text socket: the piece to look for. The block marks itself red and the bot will not start if this is empty.
  • Gives back: The position of the first letter of the match. The first letter of the text is position 1. If there is no match, it gives 0.
  • How it works: The bot searches the text from the start (first) or the end (last) and gives the position found, counted from 1.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ if  < in text ( note ) find [ first ▾ ] occurence          │
│       of text ( "win" ) > ( 0 ) >                          │
│ then  Purchase [ Rise ▾ ]                                  │
└────────────────────────────────────────────────────────────┘

The test is true when the word "win" appears somewhere in "note".

  • Good to know:
    • Test for "greater than 0" to know if the text was found.
    • The plug of this block is marked as text, so a number-only socket may refuse it. A Compare block or a Set variable accepts it.

Get character

  • Kind: Official (Deriv)
  • Type id: text_charAt
  • Shape: Value block (gives text)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Picks one letter out of a text.
  • Inputs:
    • in text socket: the text. The block marks itself red and the bot will not start if this is empty.
    • Dropdown: letter #, letter # from end, first letter, last letter, random letter. Default: letter #.
    • Number socket: appears only for letter # and letter # from end. The block marks itself red and the bot will not start if this is empty.
  • Gives back: One character as text.
  • How it works: The bot counts the letters from 1. letter # 1 is the first letter and letter # from end 1 is the last letter. random letter picks any letter by chance.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ first ▾ ] to                                         │
│   ( in text ( "945" ) get [ letter # ▾ ] ( 1 ) )           │
└────────────────────────────────────────────────────────────┘

The variable "first" becomes the text "9".

  • Good to know:
    • The result is text. "9" is not the number 9, although a Compare with = treats them as equal.

Get substring

  • Kind: Official (Deriv)
  • Type id: text_getSubstring
  • Shape: Value block (gives text)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Cuts a piece out of a text, from one position to another.
  • Inputs:
    • in text socket: the text. The block marks itself red and the bot will not start if this is empty.
    • First dropdown: letter #, letter # from end, first. Default: letter #. The two # choices show a number socket.
    • Second dropdown: letter #, letter # from end, last. Default: letter #. The two # choices show a number socket.
  • Gives back: The piece of text, with both end letters included.
  • How it works: The bot counts the letters from 1 and cuts from the first position to the second, including both. With first and last it gives the whole text.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ part ▾ ] to ( in text ( "ABCDEF" ) get substring     │
│   from [ letter # ▾ ] ( 2 ) to [ letter # ▾ ] ( 4 ) )      │
└────────────────────────────────────────────────────────────┘

The variable "part" becomes "BCD".

  • Good to know:
    • The menu block starts with the numbers 0 and 2. Counting starts at 1, so change the first number to 1 or more.

Change text case

  • Kind: Official (Deriv)
  • Type id: text_changeCase
  • Shape: Value block (gives text)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Changes the capital letters of a text: ALL CAPS, all small, or Title Case.
  • Inputs:
    • Text socket (after "Transform"). The block marks itself red and the bot will not start if this is empty.
    • Dropdown: UPPER CASE, lower case, Title Case. The menu block starts on UPPER CASE.
  • Gives back: The changed text.
  • How it works: The bot turns every letter big or small. Title Case makes the first letter of each word big and the rest small.
  • Example:
┌─ 4. Restart trading conditions ────────────────────────────┐
│ Notify [ blue ▾ ] with sound: [ Silent ▾ ]                 │
│   ( Transform ( "round done" ) to [ UPPER CASE ▾ ] )       │
└────────────────────────────────────────────────────────────┘

The Journal shows ROUND DONE.

  • Good to know:
    • Handy before you compare two texts, so that small and big letters do not matter.

Trim spaces

  • Kind: Official (Deriv)
  • Type id: text_trim
  • Shape: Value block (gives text)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Cuts away the spaces at the start, the end, or both ends of a text.
  • Inputs:
    • Dropdown: both sides, left side, right side. The menu block starts on both sides.
    • Text socket. The block marks itself red and the bot will not start if this is empty.
  • Gives back: The text without those spaces.
  • How it works: The bot removes the blank characters from the chosen side or sides. Spaces in the middle stay.
  • Example:
┌─ 4. Restart trading conditions ────────────────────────────┐
│ set [ name ▾ ] to                                          │
│   ( trim spaces from [ both sides ▾ ] of ( " abc " ) )     │
└────────────────────────────────────────────────────────────┘

The variable "name" becomes "abc".

  • Good to know:
    • Useful when a text comes from outside and may have extra spaces.

Print

  • Kind: Official (Deriv)
  • Type id: text_print
  • Shape: Action block
  • Where it goes: Inside a root block such as 2. Purchase conditions, 3. Sell conditions or 4. Restart trading conditions (also inside a function, a loop or an if). You can use it as many times as you like. In the menu it sits in Utility under Notifications.
  • What it does: Shows a pop-up box with a message. The bot stops and waits until you tap OK.
  • Inputs:
    • Message socket (after "print"). The block marks itself red and the bot will not start if this is empty.
  • How it works: The bot asks the browser to show a pop-up with your message and does nothing more until you close it.
  • Example:
┌─ 4. Restart trading conditions ────────────────────────────┐
│ print ( "Round finished" )                                 │
│ Trade again                                                │
└────────────────────────────────────────────────────────────┘

A pop-up shows "Round finished". When you tap OK, the bot trades again.

  • Good to know:
    • The pop-up freezes the bot. If you are away, the bot waits for you.
    • For a message that does not stop the bot, use Notify.

Request an input

  • Kind: Official (Deriv)
  • Type id: text_prompt_ext
  • Shape: Value block (gives text or a number, as chosen)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like. In the menu it sits in Utility under Notifications.
  • What it does: Shows a pop-up box that asks you to type something. The bot waits until you answer.
  • Inputs:
    • Type dropdown: string or number. The menu block starts on string.
    • Message socket (after "with message"): the question to show. The block marks itself red and the bot will not start if this is empty.
  • Gives back: What you typed: as text for string, or as a number for number.
  • How it works: The bot asks the browser to show the question with a typing box and does nothing more until you answer. For number, the answer is turned into a number.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ stake ▾ ] to                                         │
│   ( prompt for [ number ▾ ] with message ( "Stake?" ) )    │
└────────────────────────────────────────────────────────────┘

A box asks "Stake?". The number you type is stored in the variable "stake".

  • Good to know:
    • The bot stops until you answer. This is not good for a bot that should run on its own.
    • If you type something that is not a number while number is chosen, the result is not a number.

Text Statement

  • Kind: Official (Deriv)
  • Type id: text_statement
  • Shape: Action block (a helper that lives inside Text join)
  • Where it goes: Only inside the slot of a Text join block. You add it with the plus icon of Text join, not from the menu on its own.
  • What it does: One item of a Text join block. It holds the text or value that is joined.
  • Inputs:
    • Value socket: the text or value for this item. The minus icon on the item removes it.
  • How it works: Inside Text join, the bot turns the value of each item into text and joins the items together.
  • Example:
┌─ Text join ────────────────────────────────────────────────┐
│ set [ text ▾ ] to create text with  [ + ]                  │
│   [ - ] ( "abc" )                                          │
└────────────────────────────────────────────────────────────┘

The indented line with the minus icon is one Text Statement.

  • Good to know:
    • If you drag it out of its Text join, it jumps back in.
    • Plain Text blocks fit in its socket, but so do numbers and variables.

Lists

Create list

  • Kind: Official (Deriv)
  • Type id: lists_create_with
  • Shape: Action block
  • Where it goes: Inside a root block such as 2. Purchase conditions, 3. Sell conditions or 4. Restart trading conditions (also inside a function, a loop or an if). You can use it as many times as you like.
  • What it does: Makes a new list from items you list one by one and stores it in a variable. A list is an ordered row of values.
  • Inputs:
    • Variable dropdown: where the list is stored. The default name is list.
    • Items: a stack of slots, each with a value. The plus icon adds a slot, the minus icon removes one. The menu block starts with two.
  • How it works: The bot collects the values of the slots in order and stores them as a list in the variable. The old content of the variable is replaced.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ list ▾ ] to create list with  [ + ]                  │
│   [ - ] ( 3 )                                              │
│   [ - ] ( 5 )                                              │
└────────────────────────────────────────────────────────────┘

The variable "list" holds the list 3, 5.

  • Good to know:
    • An empty slot gives the empty value null.
    • Items may be numbers, text or even other lists.

Repeat an item

  • Kind: Official (Deriv)
  • Type id: lists_repeat
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a list is wanted (a socket of another block, or a Set variable). You can use it as many times as you like.
  • What it does: Makes a list in which one item is repeated a number of times.
  • Inputs:
    • item socket: the value to repeat. The block marks itself red and the bot will not start if this is empty.
    • times socket: how many copies. The block marks itself red and the bot will not start if this is empty. The menu block starts with 5.
  • Gives back: A list.
  • How it works: The bot makes a list with as many copies of the item as you asked for.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ zeros ▾ ] to                                         │
│   ( create list with item ( 0 ) repeated ( 5 ) times )     │
└────────────────────────────────────────────────────────────┘

The variable "zeros" holds 0, 0, 0, 0, 0.

  • Good to know:
    • Good for starting a list of counters, one for each digit.

List Length

  • Kind: Official (Deriv)
  • Type id: lists_length
  • Shape: Value block (gives a number)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Counts the items in a list.
  • Inputs:
    • List socket (after "length of"). The block marks itself red and the bot will not start if this is empty.
  • Gives back: A number: how many items the list has.
  • How it works: The bot counts the items of the list.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ if  < length of ( digits ) ≥ ( 20 ) >                      │
│ then  Purchase [ Rise ▾ ]                                  │
└────────────────────────────────────────────────────────────┘

The bot only buys once the list "digits" has 20 items or more.

  • Good to know:
    • For the number of characters in a text, use Text String Length.

Is list empty?

  • Kind: Official (Deriv)
  • Type id: lists_isEmpty
  • Shape: True/false block
  • Where it goes: Anywhere a true/false is wanted, such as the test of an if. You can use it as many times as you like.
  • What it does: Checks whether a list has no items.
  • Inputs:
    • List socket. It accepts blocks that give a list, and variables. The block marks itself red and the bot will not start if this is empty.
  • Gives back: True if the list has no items, otherwise false.
  • How it works: The bot checks if the list has length zero. A variable that holds nothing yet counts as empty.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ if  < list ( digits ) is empty >                           │
│ then  Trade again                                          │
└────────────────────────────────────────────────────────────┘

If "digits" has no items yet, the bot trades again.

  • Good to know:
    • Check this before you read an item from a list, to avoid reading from nothing.

List item position

  • Kind: Official (Deriv)
  • Type id: lists_indexOf
  • Shape: Value block (gives a number)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Finds where an item is in a list.
  • Inputs:
    • in list socket: the list. The block marks itself red and the bot will not start if this is empty.
    • Dropdown: first, last. Default: first. Which place to report if the item appears more than once.
    • item socket: the item to look for. The block marks itself red and the bot will not start if this is empty.
  • Gives back: The position of the item, counted from 1. If the item is not in the list, it gives 0.
  • How it works: The bot searches from the start (first) or from the end (last) and gives the place found.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ where ▾ ] to                                         │
│   ( in list ( digits ) find [ first ▾ ] occurence          │
│     of item ( 7 ) )                                        │
└────────────────────────────────────────────────────────────┘

The variable "where" holds the place of the first 7, or 0 if there is no 7.

  • Good to know:
    • Test for "greater than 0" to know if the item was found.

Get list item

  • Kind: Official (Deriv)
  • Type id: lists_getIndex
  • Shape: Value block (gives the item). With the remove choice it turns into an action block.
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like. With the remove choice it becomes an action block and goes inside a root block instead.
  • What it does: Reads one item from a list. It can also take the item out of the list.
  • Inputs:
    • in list socket: the list.
    • Mode dropdown: get, get and remove, remove. Default: get.
    • Place dropdown: #, # from end, first, last, random. Default: #. The two # choices show a number socket.
  • Gives back: The item. With remove it gives nothing and is an action block.
  • How it works: The bot counts the places from 1. # 1 is the first item. # from end 1 is the last item. get leaves the list as it was. get and remove gives the item and takes it out. remove only takes it out.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ newest ▾ ] to                                        │
│   ( in list ( digits ) [ get ▾ ] [ last ▾ ] )              │
└────────────────────────────────────────────────────────────┘

The variable "newest" holds the last item of "digits". The list stays as it was.

  • Good to know:
    • Taking an item from an empty list gives nothing useful. Check with Is list empty? first.
    • Switching to remove changes the block from a value block to an action block.

Set list item

  • Kind: Official (Deriv)
  • Type id: lists_setIndex
  • Shape: Action block
  • Where it goes: Inside a root block such as 2. Purchase conditions, 3. Sell conditions or 4. Restart trading conditions (also inside a function, a loop or an if). You can use it as many times as you like.
  • What it does: Changes one item of a list, or inserts a new item at a place.
  • Inputs:
    • in list socket: the list.
    • Mode dropdown: set, insert at. Default: set.
    • Place dropdown: #, # from end, first, last, random. Default: #. The two # choices show a number socket.
    • as socket: the new value.
  • How it works: The bot counts the places from 1. set replaces the item at that place. insert at puts the new value in at that place and pushes the others along.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ in list ( digits ) [ insert at ▾ ] [ first ▾ ]             │
│   as ( Last Digit )                                        │
└────────────────────────────────────────────────────────────┘

The newest last digit is put at the front of the list "digits".

  • Good to know:
    • Keep a list at a fixed length by inserting at first and removing the last item.

Get sub-list

  • Kind: Official (Deriv)
  • Type id: lists_getSublist
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a list is wanted (a socket of another block, or a Set variable). You can use it as many times as you like.
  • What it does: Makes a smaller list out of a part of a list.
  • Inputs:
    • in list socket: the list.
    • First dropdown: get sub-list from #, get sub-list from # from end, get sub-list from first. Default: from #.
    • Second dropdown: #, # from end, last. Default: #. The # choices show a number socket.
  • Gives back: A new list with the items from the first place to the second place, both included.
  • How it works: The bot counts places from 1, copies the items in the range, and gives them back as a new list. The original list is not changed.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ last5 ▾ ] to ( in list ( digits ) get sub-list       │
│   from [ # from end ▾ ] ( 5 ) to [ last ▾ ] )              │
└────────────────────────────────────────────────────────────┘

The variable "last5" holds the last 5 items of "digits".

  • Good to know:
    • Nice for taking the last few items of a long list.

Create list from text

  • Kind: Official (Deriv)
  • Type id: lists_split
  • Shape: Value block (gives a number, text, list...) (gives a list, or text in the other mode)
  • Where it goes: Anywhere a list is wanted (a socket of another block, or a Set variable). You can use it as many times as you like.
  • What it does: Turns a text into a list by cutting it at a separator, or the other way round: joins a list into one text.
  • Inputs:
    • Mode dropdown: make list from text, make text from list. Default: make list from text.
    • First socket: the text (or the list in the other mode).
    • with delimiter socket: the separator, for example a comma. The menu block starts with ,
  • Gives back: A list (make list from text) or a text (make text from list).
  • How it works: Make list from text cuts the text each time it sees the separator. Make text from list puts the separator between the items and joins them.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ nums ▾ ] to ( make list from text ( "3,5,7" )        │
│   with delimiter ( "," ) )                                 │
└────────────────────────────────────────────────────────────┘

The variable "nums" holds the list 3, 5, 7. The items are text, not numbers.

  • Good to know:
    • Items cut from a text are text. A Compare with = still treats "5" and 5 as equal.

Sort list

  • Kind: Official (Deriv)
  • Type id: lists_sort
  • Shape: Value block (gives a number, text, list...) (gives a list)
  • Where it goes: Anywhere a list is wanted (a socket of another block, or a Set variable). You can use it as many times as you like.
  • What it does: Gives the list in order, from small to big or big to small, by number or by alphabet.
  • Inputs:
    • Type dropdown: numeric, alphabetic. Default: numeric.
    • Direction dropdown: ascending, descending. Default: ascending.
    • List socket. The block marks itself red and the bot will not start if this is empty.
  • Gives back: A sorted list.
  • How it works: The bot sorts the items by number value or by alphabet, upward (ascending) or downward (descending). In the code, the original list is also put in order as text as a side effect.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ ordered ▾ ] to ( sort [ numeric ▾ ] [ ascending ▾ ]  │
│   ( digits ) )                                             │
└────────────────────────────────────────────────────────────┘

The variable "ordered" holds the numbers of "digits", smallest first.

  • Good to know:
    • If the order of your original list matters, make a copy of it first, because sorting can change it.

List Statement

  • Kind: Official (Deriv)
  • Type id: lists_statement
  • Shape: Action block (a helper that lives inside Create list)
  • Where it goes: Only inside the slot of a Create list block. You add it with the plus icon of Create list, not from the menu on its own.
  • What it does: One item of a Create list block. It holds the value of that place in the list.
  • Inputs:
    • Value socket: the value for this item. If it is empty the code uses null. The minus icon on the item removes it.
  • How it works: Inside Create list, the bot takes the value of every item, in order, and puts them into the list.
  • Example:
┌─ Create list ──────────────────────────────────────────────┐
│ set [ list ▾ ] to create list with  [ + ]                  │
│   [ - ] ( 3 )                                              │
└────────────────────────────────────────────────────────────┘

The indented line with the minus icon is one List Statement.

  • Good to know:
    • You cannot drag it out of its Create list block and use it alone. Dropped elsewhere it is removed.

Loops

Repeat (1)

  • Kind: Official (Deriv)
  • Type id: controls_repeat
  • Shape: Action block
  • Where it goes: Inside a root block or a function, like any action block. Other blocks go in its slot. Loops can sit inside other loops.
  • What it does: Runs the blocks inside it a fixed number of times that you type in.
  • Inputs:
    • Number box: how many times. Default: 10. Whole numbers from 0 up.
    • do slot: the blocks to repeat.
  • How it works: The bot runs the blocks in the slot, one round after the other, until it has done as many rounds as the number.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ repeat [ 3 ] times                                         │
│   do  Notify [ blue ▾ ] with sound: [ Silent ▾ ] ( "hi" )  │
└────────────────────────────────────────────────────────────┘

The Journal shows "hi" three times.

  • Good to know:
    • To use a variable or a calculation as the number, use Repeat (2).

Repeat (2)

  • Kind: Official (Deriv)
  • Type id: controls_repeat_ext
  • Shape: Action block
  • Where it goes: Inside a root block or a function, like any action block. Other blocks go in its slot. Loops can sit inside other loops.
  • What it does: Runs the blocks inside it as many times as a value says, so the number can come from a variable.
  • Inputs:
    • times socket: a number block. The block marks itself red and the bot will not start if this is empty.
    • do slot: the blocks to repeat.
  • How it works: The bot works out the number once, then runs the blocks in the slot that many times.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ repeat ( count ) times                                     │
│   do  change [ total ▾ ] by ( 2 )                          │
└────────────────────────────────────────────────────────────┘

If "count" is 4, the variable "total" goes up by 2 four times.

  • Good to know:
    • Take care when the loop changes the same variable that gives the number of rounds. That can change how many rounds it runs.

Repeat While/Until

  • Kind: Official (Deriv)
  • Type id: controls_whileUntil
  • Shape: Action block
  • Where it goes: Inside a root block or a function, like any action block. Other blocks go in its slot. Loops can sit inside other loops.
  • What it does: Keeps running the blocks inside while a test is true, or until a test becomes true.
  • Inputs:
    • Dropdown: while, until. Default: while.
    • Test socket: a true/false block. The block marks itself red and the bot will not start if this is empty.
    • do slot: the blocks to repeat.
  • How it works: Before every round the bot checks the test. With while it runs the slot as long as the test is true. With until it runs the slot as long as the test is false. The bot counts the rounds and stops with the error "Infinite loop detected" if a loop goes on for more than about 10,000 rounds.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ repeat [ until ▾ ] < ( total ) ≥ ( 10 ) >                  │
│   do  change [ total ▾ ] by ( 1 )                          │
└────────────────────────────────────────────────────────────┘

The variable "total" counts up by 1 until it reaches 10.

  • Good to know:
    • Make sure something inside the loop can change the test, or the loop will never end.
    • The 10,000-round guard stops a runaway loop with an error. It does not give you a loop that waits for the market.

Iterate (1)

  • Kind: Official (Deriv)
  • Type id: controls_for
  • Shape: Action block
  • Where it goes: Inside a root block or a function, like any action block. Other blocks go in its slot. Loops can sit inside other loops.
  • What it does: Counts with a variable from a start number to an end number in steps, and runs the blocks inside for each step.
  • Inputs:
    • Variable dropdown: the counter (the block's help text calls it i).
    • from socket: the start number. The block marks itself red and the bot will not start if this is empty.
    • to socket: the end number. The block marks itself red and the bot will not start if this is empty.
    • by socket: the step size. The block marks itself red and the bot will not start if this is empty.
    • do slot: the blocks to run for each step.
  • How it works: The variable starts at from and goes up (or down, if from is bigger than to) by the step each round, until it passes the end number. The end number is included. The step is always used as a positive size.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ count with [ i ▾ ] from ( 1 ) to ( 5 ) by ( 1 )            │
│   do  change [ total ▾ ] by ( i )                          │
└────────────────────────────────────────────────────────────┘

The variable "i" takes the values 1, 2, 3, 4, 5, so "total" grows by 15 in all.

  • Good to know:
    • Use it when you know the start and end. Use a For each loop when you have a list.

Iterate (2)

  • Kind: Official (Deriv)
  • Type id: controls_forEach
  • Shape: Action block
  • Where it goes: Inside a root block or a function, like any action block. Other blocks go in its slot. Loops can sit inside other loops.
  • What it does: Goes through a list one item at a time and runs the blocks inside for each item.
  • Inputs:
    • Variable dropdown: holds the current item (the block's help text calls it i).
    • list socket: a list block. The block marks itself red and the bot will not start if this is empty.
    • do slot: the blocks to run for each item.
  • How it works: For each item of the list, in order, the bot puts the item in the variable and runs the blocks in the slot.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ for each item [ i ▾ ] in list ( digits )                   │
│   do  change [ total ▾ ] by ( i )                          │
└────────────────────────────────────────────────────────────┘

The variable "total" grows by every number in "digits".

  • Good to know:
    • Do not add or remove items of the same list inside the loop. Work on a copy.

Break out/continue

  • Kind: Official (Deriv)
  • Type id: controls_flow_statements
  • Shape: Action block
  • Where it goes: Inside a loop block (Repeat, Repeat While/Until, Iterate), at any depth. Do not use it outside a loop.
  • What it does: Leaves a loop early, or skips to the next round of the loop.
  • Inputs:
    • Dropdown: break out, continue with next iteration. Default: break out.
  • How it works: break out ends the loop at once and the bot goes on with the block after the loop. continue with next iteration skips the rest of this round and starts the next round.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ repeat [ 10 ] times                                        │
│   do  if  < ( i ) = ( 5 ) >                                │
│       then  break out of loop                              │
└────────────────────────────────────────────────────────────┘

The loop ends when the test is true, even if it has not done all 10 rounds.

  • Good to know:
    • Put it inside an if so that it only fires on a condition.
    • Outside of a loop it does nothing useful and the bot may stop with an error.

Variables

Set variable

  • Kind: Official (Deriv)
  • Type id: variables_set
  • Shape: Action block
  • Where it goes: Inside a root block such as 2. Purchase conditions, 3. Sell conditions or 4. Restart trading conditions (also inside a function, a loop or an if). You can use it as many times as you like.
  • What it does: Puts a value into a variable. A variable is a named box that holds a number, text or list for later.
  • Inputs:
    • Variable dropdown: the variable to fill. Make a new one with the Create button in the Variables menu. The default name is item.
    • to socket: the value to store. If it is empty the code stores 0.
  • How it works: The bot works out the value and stores it in the box. Whatever was in the box before is replaced.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ stake ▾ ] to ( 1 )                                   │
└────────────────────────────────────────────────────────────┘

The variable "stake" now holds 1.

  • Good to know:
    • Give a variable a start value before you change it or read it.
    • In the Variables menu, type a name in the New variable name box and press Create. Set and variable blocks for it then appear in that menu.

User-defined variable

  • Kind: Official (Deriv)
  • Type id: variables_get
  • Shape: Value block (gives a number, text, list...) (can hold a number, text, list...)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like. One is made for each variable you create, and it appears in the Variables menu.
  • What it does: Hands over what is in a variable. Plug it in wherever you want to use the value.
  • Inputs:
    • Variable dropdown: which variable to read. The default name is item.
  • Gives back: The value the variable holds now.
  • How it works: The bot looks up the variable and gives its current value. If you rename a variable, the blocks that use it follow the new name.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ if  < ( stake ) > ( 5 ) >                                  │
│ then  set [ stake ▾ ] to ( 1 )                             │
└────────────────────────────────────────────────────────────┘

The block "stake" reads the variable. If it is above 5, it is reset to 1.

  • Good to know:
    • A variable that was never set holds nothing, so give it a value first.
    • Pick short, clear names such as stake or losses.

Custom functions

Function

  • Kind: Official (Deriv)
  • Type id: procedures_defnoreturn
  • Shape: Stand-alone block (a definition; it does not plug into other blocks)
  • Where it goes: Straight on the empty canvas. You can build as many functions as you like, each with its own name.
  • What it does: Defines your own named group of blocks that you can run from anywhere with a call block. Write the steps once and reuse them.
  • Inputs:
    • Name box: the name of the function. The menu block starts as do something.
    • Plus icon: adds a parameter, a named value that the caller sends in. A box asks "Specify a parameter name:". The block then reads with: followed by the names.
    • Slot: the blocks to run when the function is called.
  • How it works: Nothing runs where the function is defined. The blocks inside run each time a matching Custom function block is reached. When they finish, the bot goes on after the call block. Once you define a function, a call block with its name appears at the bottom of the Custom functions menu.
  • Example:
┌─ Function ─────────────────────────────────────────────────┐
│ function [ report ] with: total                            │
│   Notify [ blue ▾ ] with sound: [ Silent ▾ ] ( total )     │
└────────────────────────────────────────────────────────────┘

A function called "report" takes a value named "total" and writes it in the Journal.

  • Good to know:
    • Give each function a different name.
    • The block can be collapsed with the small arrow, to keep the canvas tidy.

Function that returns a value

  • Kind: Official (Deriv)
  • Type id: procedures_defreturn
  • Shape: Stand-alone block (a definition; it does not plug into other blocks)
  • Where it goes: Straight on the empty canvas. You can build as many as you like, each with its own name.
  • What it does: Like Function, but at the end it hands one value back to whoever called it, so you can use it as a value block.
  • Inputs:
    • Name box: the name of the function. The menu block starts as do something.
    • Plus icon: adds a parameter (named value the caller sends in).
    • Slot: the blocks to run. Under the slot, return socket: the value to hand back.
  • How it works: Nothing runs where the function is defined. When a matching call block is reached, the blocks run and the return value is given to the place where the call block was plugged in.
  • Example:
┌─ Function that returns a value ────────────────────────────┐
│ function [ double ] with: n                                │
│   return ( ( n ) * ( 2 ) )                                 │
└────────────────────────────────────────────────────────────┘

Calling "double" with 4 gives back 8.

  • Good to know:
    • A function without a value in the return socket gives back nothing.
    • Use Conditional return to hand a value back early.

Conditional return

  • Kind: Official (Deriv)
  • Type id: procedures_ifreturn
  • Shape: Action block
  • Where it goes: Only inside a Function or a Function that returns a value, at any depth. Elsewhere the bot switches it off.
  • What it does: Leaves the function early when a test is true, handing back a value.
  • Inputs:
    • if socket: a true/false block.
    • return socket: the value to hand back. Inside a Function with no return value it shows only the word return.
  • How it works: The bot checks the test. If it is true, the function ends at once with the return value. If it is false, the bot carries on with the next block.
  • Example:
┌─ Function that returns a value ────────────────────────────┐
│ function [ safe_div ] with: a, b                           │
│   if < ( b ) = ( 0 ) > return ( 0 )                        │
│   return ( ( a ) / ( b ) )                                 │
└────────────────────────────────────────────────────────────┘

If b is 0 the function returns 0 and never divides.

  • Good to know:
    • Outside a function the block is switched off and does nothing.

Custom function

  • Kind: Official (Deriv)
  • Type id: procedures_callnoreturn
  • Shape: Action block
  • Where it goes: Inside a root block such as 2. Purchase conditions, 3. Sell conditions or 4. Restart trading conditions (also inside a function, a loop or an if). You can use it as many times as you like.
  • What it does: Runs one of your own functions (made with the Function block). It shows the function name.
  • Inputs:
    • The name of the function, fixed by the Function block.
    • One socket for each parameter of the function. If one is empty the code sends null.
  • How it works: The bot jumps to the function, runs its blocks with the values you plugged in, then comes back and carries on with the next block. It appears at the bottom of the Custom functions menu once the function exists.
  • Example:
┌─ 4. Restart trading conditions ────────────────────────────┐
│ report ( Total profit/loss )                               │
│ Trade again                                                │
└────────────────────────────────────────────────────────────┘

The function "report" runs with the total profit and then the bot trades again.

  • Good to know:
    • Rename the function in its definition and every call block follows the new name.
    • Make the function first. The call block only appears in the menu after the function exists.

Custom function (returns a value)

  • Kind: Official (Deriv)
  • Type id: procedures_callreturn
  • Shape: Value block (gives a number, text, list...)
  • Where it goes: Anywhere a value is wanted (a socket of another block). You can use it as many times as you like.
  • What it does: Runs one of your functions that hands back a value (made with the Function that returns a value block) and gives you that value.
  • Inputs:
    • The name of the function, fixed by its definition.
    • One socket for each parameter. If one is empty the code sends null.
  • Gives back: The value that the function returns.
  • How it works: The bot jumps to the function, runs its blocks with your values, and the returned value takes the place of this block. It appears at the bottom of the Custom functions menu once the function exists.
  • Example:
┌─ 2. Purchase conditions ───────────────────────────────────┐
│ set [ stake ▾ ] to ( double ( stake ) )                    │
└────────────────────────────────────────────────────────────┘

The function "double" is called with the stake and the answer is stored back in "stake".

  • Good to know:
    • The menu shows it under the same name "Custom function". The shape tells them apart: this one has a pill shape.

Build a bot with these blocks

BRINOVS is free to open. Sign in with Deriv, open the Bot Builder, and try everything on a demo account.

Open BRINOVS

BRINOVS Digits is a free bot builder and trading page built on Deriv's Bot Builder. Trading carries risk and you can lose money. Nothing in this guide is financial advice or a promise of profit. Test every bot on a demo account first.

Guide home · Open BRINOVS