# Basic Indicator Configs & Debugging

{% hint style="info" %}
Please note that this is an experimental example and the functions used may change before the final release into production.
{% endhint %}

### 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.

```javascript
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.

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

<div align="left" data-full-width="false"><figure><img src="https://744089625-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FT4FaQyAXPQOikN4qrBdX%2Fuploads%2FNtdVKbMs300FvyyJB6WD%2FScreen%20Shot%202023-07-07%20at%2012.50.07%20PM.png?alt=media&#x26;token=9febc0be-444c-43ea-86a6-56e28dcd99f6" alt="Debug values visible beneath bot controls" width="370"><figcaption><p>Debug values are visible on the bot config panel beneath the bot controls.</p></figcaption></figure></div>

#### 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.

```javascript
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.

```javascript
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:

```javascript
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hawkalpha.gitbook.io/what-is-hawkalpha/example/basic-indicator-configs-and-debugging.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
