Basic Indicator Configs & Debugging
Review an example code snippet that demonstrates how to utilize indicator configurations and implement debugging functionalities in a DCA (Dollar Cost Averaging) bot.
Please note that this is an experimental example and the functions used may change before the final release into production.
Tutorial: Utilizing Indicator Configurations and Debugging in a DCA Bot
In this tutorial, we will break down an example code snippet that demonstrates how to utilize indicator configurations and implement debugging functionalities in a DCA (Dollar Cost Averaging) bot. The code snippet consists of several functions and objects that work together to monitor indicator values and make decisions based on those values.
Step 1: Indicator Configurations
The indicatorsConfigs
function is responsible for defining the indicator configurations used in the DCA bot. For this example it returns an object that contains different instances of the RSI (Relative Strength Index) indicator with various configurations.
In this example, the indicatorsConfigs
function creates five instances of the RSI indicator with different configurations. The first instance (`rsi1`) uses the default time frame configuration of 1 minute, while the remaining instances specify different timeframes (`rsi5`, `rsi10`, `rsi15`) and a different source type (`rsiOBV`) on the 1 minute time frame.
Step 2: Debugging Object
The debug
object is used to store the debug values for various indicators and proxies. It is initialized with zero values for each property.
Step 3: Proxy Functions
The code snippet defines two proxy functions: rsi1Proxy
and rsiSteppedProxy
. These functions map values from one range to another range using the proxy
and steppedProxy
utility functions from the InitContext
class.
In this example, rsi1Proxy
maps values between the range of 30 to 100 to the range of 0.1 to 0.3. rsiSteppedProxy
is a stepped proxy function that maps values with a step size of 10%.
Step 4: Tick Function
The tick
function is called periodically to update the debug values and make decisions based on those values.
The tick
function takes two parameters: i
(the indicator configurations) and bot
(the DCA bot instance). Inside the function, it updates the debug values by calling the getLastValue
method on each indicator instance. It also updates the proxy
and steppedProxy
debug values by passing the corresponding indicator values to the proxy functions.
The function then checks if all the RSI values are below 30. If so, it calls the start
method on the bot instance to initiate the bot's execution.
If the bot's state indicates that it has finished its execution, the function calls the reset
method on the bot to reset it.
Finally, if the steppedProxy
debug value is a valid number (not NaN), the function updates the bot's properties by calling the updateBotProps
method with the targetProfit
property set to the steppedProxy
value.
Here is the complete code example:
That's it! This example demonstrates how to configure indicators, track their values, and use proxy functions in a DCA bot. By understanding and modifying this example, you can customize the behavior of your DCA bot based on different indicator values and proxy mappings.
Last updated