Creating Models with Dynamic Parameters
Introduction
This guide provides step-by-step instructions on creating a model that utilizes dynamic values as parameters. By leveraging the argument syntax, users can pass customized parameters to their models. This documentation explains the syntax format and usage guidelines to help you effectively utilize this feature.
Syntax Format
To pass parameters to your model, use the following syntax format:
This format allows you to define parameters and specify default values for them. The "optional" flag indicates that passing a parameter is not mandatory, and the default value will be used if no parameter is provided.
Example Usage
Let's examine the example below and break it down:
In this example, the lines of code demonstrate how to use the argument syntax effectively.
Line #1: Declaration of the parameter
Syntax:
argument optional weight = 10
Explanation: This line declares the parameter named "weight." The "optional" flag indicates that passing a parameter for "weight" is not mandatory. If no parameter is provided, the default value of "10" will be used.
Line #2: Assigning the variable to a function
Syntax:
x = SPY.close -> rsi(weight)
Explanation: This line assigns the variable "x" to the result of the "rsi()" function, utilizing the "weight" parameter.
Line #3: Export statement
Syntax:
export x
Explanation: This line ensures that the model can be used and exported. Only the exported variable "x" will be visible to users when the model is published.
Saving the Resource
Save the resource with the name "passParametersOptional." This name will help users find and identify the model in the library easily.
Utilizing the Model
Once the model is added to the library, users can utilize it by clicking on the Insert URL
button.
In this case, since the argument is optional
, we can remove the parameter and the model will still run:
Alternatively, if there is no optional
flag for the argument, then the model with throw an error if the user didn't pass any parameter:
Last updated