Sequence

Sequence #

The sequence tool binds multiple tools together, making them depend on each other’s execution results. This tool may be used to create complex conditions and fallback mechanisms. For example, it may be used to check a certain candle value when the current execution time does not match any curfew schedules, or send a request to a custom tool before checking the results of an SMA tool.

The sequence tool can be backtested. More information about strategy backtesting can be found here.

Configuration #

{
	"type": "sequence",
	"context_id": "sequence-id-123",
	"description": "a simple tool",
	"tools": [
		{
			"type": "placeholder",
			"permit": true
		},
		{
			"type": "placeholder",
			"permit": true
		},
		{
			"type": "placeholder",
			"permit": true
		}
	],
	"operator": "or",
	"mode": "partial-serial"
}
  • type - string
    The type of the tool configuration.

    Tool configuration types are described in detail here.

  • context_id - string (optional; default: unused)
    The ID of the tool that is used when inserting data into the context store.

    The context data store and its IDs are described in detail here.

  • description - string (optional; default: unused)
    The description of the tool and its purpose.

  • tools - array of objects
    The array of tools to execute. At least two tools must be specified.

    The array of tools adheres to the same structuring rules as the array of the top-level tools. These rules are described in detail here.

  • operator - string (enum)
    The type of operator to use when building a tool execution chain. Possible values:

    • or
      When this operator is active, the execution chain is terminated only when one of the inner tools produces a positive result (an indication that further execution is permitted).

      Note that the sequence tool produces a positive result only when at least one of the inner tools does so.

    • and
      When this operator is active, the execution chain is terminated only when one of the inner tools produces a negative result (either an error or an indication that further execution is not permitted).

      Note that the sequence tool produces a positive result only when all the inner tools do so.

  • mode - string (enum)
    The execution mode of the inner tools’ array. Possible values:

    • full-serial
      When this mode is active, all tools are executed one after the other until the very end, regardless of the status of the execution chain. This means that all tools generate their respective reports, even when their results become irrelevant due to the early termination of the execution chain. The examples below illustrate how this mode works with both operators:

      • Example 1 (or):
        The list of inner tools:

        • tool1(error)
        • tool2(success)
        • tool3(success)

        The list of reports of all executed inner tools:

        • report-tool1(error)
        • report-tool2(success)
        • report-tool3(success)

        When using the or operator, the first tool that produces a positive result (an indication that further execution is permitted) terminates the sequence execution chain. In the example above, the second tool (i.e., tool2) is the one that triggers the termination of the sequence chain, which renders the results of tool3 irrelevant. Nevertheless, the report of tool3 is included in the final report of the sequence tool.

      • Example 2: (and):
        The list of inner tools:

        • tool1(success)
        • tool2(error)
        • tool3(success)

        The list of reports of all executed inner tools:

        • report-tool1(success)
        • report-tool2(error)
        • report-tool3(success)

        When using the and operator, the first tool that produces a negative result (either an error or an indication that further execution is not permitted) terminates the sequence execution chain. In the example above, the second tool (i.e., tool2) is the one that terminates the sequence chain, which renders the results of tool3 irrelevant. Nevertheless, the report of tool3 is included in the final report of the sequence tool.

    • partial-serial
      When this mode is active, all tools are executed one after the other until one of them triggers the termination of the execution chain. This means that only tools that finish their execution before the early termination generate their reports. The examples below illustrate how this mode works with both operators:

      • Example 1 (or):
        The list of inner tools:

        • tool1(error)
        • tool2(success)
        • tool3(success)

        The list of reports of all executed inner tools:

        • report-tool1(error)
        • report-tool2(success)

        When using the or operator, the first tool that produces a positive result (an indication that further execution is permitted) terminates the sequence execution chain. In the example above, the second tool (i.e., tool2) is the one that terminates the sequence chain, which means that tool3 is not executed and thus cannot generate its report.

      • Example 2 (and):
        The list of inner tools:

        • tool1(success)
        • tool2(error)
        • tool3(success)

        The list of reports of all executed inner tools:

        • report-tool1(success)
        • report-tool2(error)

        When using the and operator, the first tool that produces a negative result (either an error or an indication that further execution is not permitted) terminates the sequence execution chain. In the example above, the second tool (i.e., tool2) is the one that terminates the sequence chain, which means that tool3 is not executed and thus cannot generate its report.

Report #

{
	"type": "sequence",
	"permit": true,
	"tools": [
		{
			"type":"placeholder",
			"permit": true
		},
		{
			"type":"placeholder",
			"permit": true
		},
		{
			"type":"placeholder",
			"permit": true
		}
	]
}
  • type - string
    The type of the tool report.

    Tool report types are described in detail here.

  • permit - boolean
    The property that determines whether the tool gave its permission to continue strategy execution or not.

    The tool execution flow is described in detail here.

  • tools - array of objects
    The array of tool reports. Note that the number of reports may be smaller than the number of tools when the execution termination is triggered and the active mode is partial-serial.

    The array of tool reports adheres to the same structuring rules as the array of the top-level tool reports. These rules are described in detail here.

If an error occurs during the sequence tool’s execution, only type and error properties are added to the report. The error property is described in detail here.

Context #

The objects that the sequence tool inserts into the context store are as follows:

  • tools.<context-id>.permit - boolean
    The object that determines whether the tool gave its permission to continue strategy execution or not.
If an error occurs during the sequence tool’s execution, only the tools.<context-id>.error object is inserted into the context store. This context data object is described in detail here.