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.

indicatorsConfigs = () => {
  return {
    rsi1: RSI(),
    rsi5: RSI({ timeframe: '5Min' }),
    rsi10: RSI({ timeframe: '10Min' }),
    rsi15: RSI({ timeframe: '15Min' }),
    rsiOBV: RSI({ sourceType: 'OBV' }),
  };
};

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.

debug = {
  rsi1: 0,
  rsi5: 0,
  rsi10: 0,
  rsi15: 0,
  rsiOBV: 0,
  proxy: 0,
  steppedProxy: 0,
};

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.

rsi1Proxy = proxy([30, 100], [0.1, 0.3]);
rsiSteppedProxy = steppedProxy([30, 100], [0.1, 0.3], 10);

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.

tick = (i, bot) => {
  debug.rsi1 = i.rsi1.getLastValue();
  debug.rsi5 = i.rsi5.getLastValue();
  debug.rsi10 = i.rsi10.getLastValue();
  debug.rsi15 = i.rsi15.getLastValue();
  debug.rsiOBV = i.rsiOBV.getLastValue();
  debug.proxy = rsi1Proxy(debug.rsi1);
  debug.steppedProxy = rsiSteppedProxy(debug.rsi);


  if (debug.rsi1 < 30 && debug.rsi5 < 30 && debug.rsi10 < 30 && debug.rsi15 < 30 && debug.rsiOBV < 30) {
    bot.start();
  }


  if (bot.state.isFinished) {
    bot.reset();
  }


  if (!Number.isNaN(debug.steppedProxy)) {
    bot.updateBotProps({
      targetProfit: debug.steppedProxy,
    });
  }
};

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:

indicatorsConfigs = () => {
    return {
        rsi1: RSI(),
        rsi5: RSI({timeframe: '5Min'}),
        rsi10: RSI({timeframe: '10Min'}),
        rsi15: RSI({timeframe: '15Min'}),
        rsiOBV: RSI({sourceType: 'OBV'}), 
    }
} 

debug = {
    rsi1: 0,
    rsi5: 0,
    rsi10: 0,
    rsi15: 0,
    rsiOBV: 0,
    proxy: 0,
    steppedProxy: 0
}

rsi1Proxy = proxy([30, 100], [0.1, 0.3]);
rsiSteppedProxy = steppedProxy([30, 100], [0.1, 0.3], 10);

tick = (i, bot) => {
    debug.rsi1 = i.rsi1.getLastValue();
    debug.rsi5 = i.rsi5.getLastValue();
    debug.rsi10 = i.rsi10.getLastValue();
    debug.rsi15 = i.rsi15.getLastValue();
    debug.rsiOBV = i.rsiOBV.getLastValue();
    debug.proxy = rsi1Proxy(debug.rsi1);
    debug.steppedProxy = rsiSteppedProxy(debug.rsi);
    if(debug.rsi1 < 30 && debug.rsi5 < 30 && debug.rsi10 < 30 && debug.rsi15 < 30 debug.rsiOBV < 30){
       bot.start();
    }
    if(bot.state.isFinished){
       bot.reset();
    }
    if(!Number.isNaN(debug.steppedProxy)){
        bot.updateBotProps({
            targetProfit: debug.steppedProxy
        })   
    }
}

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