Variable Operation Block
Variable Operation Block - This is an action block that allows you to create and manipulate variables for your trading bot on Kryll.
Basics reminder
In computing, a variable is a memory space where a value can be stored and manipulated. It can be used to represent a quantity or state, and its value can change during program execution. In the context of a trading bot, a variable can be used to store information such as the current price of an asset, the Return on Investment (RoI) of your strategy, or any other type of data relevant to your trading strategy.
Block configuration
In the Kryll environment, the 'Variable Operation' block serves exactly this purpose: it allows you to define and manipulate variables that can store and represent various types of data relevant to your trading strategy.
The Variable Operation block has two operating modes:
- The Assignment mode, which allows you to create a variable by giving it a name and initializing it to a defined value.
- The Operation mode, which allows you to assign a variable the result of an operation between two operands.
1 - Assignment mode
The "Assignment" mode of the 'Variable Operation' block allows you to initialize or reset a variable and assign it a defined value. This is convenient for resetting a counter to 0, or for assigning the current price to a variable.
To use this mode add the block to your strategy (the action type will be "Assign" by default).
Note: in Kryll, an undefined variable is necessarily initialized to 0.
Select the variable initialization value from the available options (current price, free numeric value, current RoI of the strategy, etc.).
Finally, enter the name of the variable (existing or new) to which you want to assign the result of the operation.
2 - Operation mode
The "Operation" mode of the 'Variable Operation' block expands the possibilities offered by the "Assignment" mode, allowing you to manipulate the values of your variables using arithmetic operations (addition, subtraction, multiplication, division).
To use this mode add the block to your strategy and select the mode Store the result of the operation.
Select your first operand (first element of your calculation) from the options:
- The current price
- A free numeric value
- The current RoI of the strategy
- The current RoI excluding the savings set aside by the "Piggy" block
- A variable you have defined in your strategy, which you can select through a drop-down list
- The price of the last transaction
Select an arithmetic operator among addition, subtraction, multiplication and division.
Select your second Operand (second element of your calculation) from the proposed options: current price, free numeric value, current RoI of the strategy, current RoI of the strategy without taking into account the savings set aside by the "Piggy" block, a variable, the price of the last transaction.
Finally, enter the name of the variable (existing or new) to which you want to assign the result of the operation.
Naming tips for variables
When creating variables in the 'Variable Operation' block, it is important to follow some naming conventions to ensure efficient management and better readability of your code. We recommend the use of the 'Camel Case' convention (for example, myVariableName) or 'Snake Case' (for example, my_variable_name). These naming conventions help make your variable names more descriptive and easier to read.
It is also important to note that Kryll ignores uppercase and lowercase in variable names. Therefore, 'toto', 'ToTo' and 'tOtO' would all be treated as the same variable by Kryll. This can be useful to avoid bugs, but it is always recommended to be consistent in the use of uppercase and lowercase for better readability of your code.
Advanced use
With the Variable Operation block, you can perform complex operations using several blocks together. Indeed, you can use several of these blocks to perform chain operations, where the result of one operation is used as an operand for another operation.
For example, you can create a variable that tracks the evolution of an asset's price over a given period of time. To do this, initialize a variable with the current price of the asset, then use the Operation mode to subtract the current price from the variable with each new candle. The result will be a variable that reflects the evolution of the asset's price in $ for example.
Tip
When developing your trading strategy, it can be extremely useful to take a look under the hood to understand how variables interact. Thanks to the developer mode of the Info block, you can easily do this.
By checking the option "developer only", the block gives you the possibility to consult the list of custom variables that your strategy has used so far, as well as their current value. To access this feature, simply activate the "List used variables" option. This will provide you with valuable insights into the variables at play, helping you further refine your strategy.
Did you know?
But that's not all, by combining the Variable Operation block and the Variable Test block, you have the opportunity to implement a multitude of new actions in your strategy and thus optimize your Bot even more. Find out how to set up loops similar to while or for in your bot, how to calculate your win ratio, or how to set up dynamic risk management based on RoI in this article dedicated to Kryll variables.
Happy Trading,
Website: https://kryll.io
Twitter: @Kryll_io
Telegram EN: https://t.me/kryll_io
Telegram FR: https://t.me/kryll_fr
Telegram ES: https://t.me/kryll_es
Discord: https://discord.gg/PDcHd8K
Reddit: https://reddit.com/r/Kryll_io
Facebook: https://www.facebook.com/kryll.io
Support: support@kryll.io