TakeProfit logo CommunityPlatform

Input parameters


Input parameters provide a convenient way to change indicator's algorithm parameters without the need of changing it's source code. For example, here is a simple indicator that calculates SMA with two parameters src and length:

# indie:lang_version = 4
from indie import indicator, param, source
from indie.algorithms import Sma

@indicator('Example')
@param.source('src', default=source.CLOSE, title='Source')
@param.int('length', default=12, min=1, title='Length')
def Main(self, src, length):
    sma = Sma.new(src, length)
    return sma[0]

After this indicator will be added to a chart, the values for the length and source parameters can be easily changed in indicator's Settings dialog:

Figure 7.1. The Settings dialog of indicator.
Figure 7.1. The Settings dialog of indicator.

How to add a parameter to an indicator

There are a few simple steps for adding an input parameter to indicator:

  • Add one of the @param.* decorators (e.g. @param.int) to the Main entry point of the indicator.
  • Pass values for the two required arguments to the decorator:
    • id — which is a string unique identifier of the parameter (the very first argument of any @param.* decorator),
    • default — which is a default value of the parameter.
  • Pass values to optional arguments of the decorator if needed (this depends on the decorator type, they could differ). In the example above there are optional arguments title and min.
  • Add a parameter to Main function (after the self parameter) with the name which is equal to the id of the parameter.

Available parameter types

Indie supports several types of input parameters, they are: