TSLab
TSLab.proSupportTSLab LiveTSVerse
Eng
Eng
  • TSLab trading platform
  • For newbies
    • A beginner's guide
      • Purchasing a license key for a data provider
      • An example of connecting text quotes
      • Example of connecting a data provider to a broker / exchange
      • An example of creating a script in TSLab
      • An example of creating a trading algorithm in TSLab
  • Installing TSLab
    • TSLab Installation Guide
      • System requirements
      • TSLab Installation manual
    • Update TSLab
      • Preparing for update
      • Release build
      • Nightly build
    • Restarting the TSLab program
    • TSLab Changelog
      • TSLab 2.1 Changelog
      • TSLab 2.2 Changelog
        • 2.2.26.0 - 2024/01/31
        • 2.2.25.0 - 2024/01/17
        • 2.2.24.0 - 2024/12/04
        • 2.2.23.0 - 2024/09/19
        • 2.2.22.0 - 2024/08/30
        • 2.2.21.0 - 2024/05/17
        • 2.2.20.0 - 2024/05/15
        • 2.2.19.0 - 2024/02/21
        • 2.2.18.0 - 2024/02/09
        • 2.2.17.0 - 2023/11/16
        • 2.2.16.0 - 2023/10/20
        • 2.2.15.0 - 2023/10/13
        • 2.2.14.0 - 2023/08/11
        • 2.2.13.0 - 2023/05/12
        • 2.2.12.0 - 2023/02/28
        • 2.2.11.0 - 2022/12/15
        • 2.2.10.0 - 2022/10/27
        • 2.2.9.0 - 2022/09/16
        • 2.2.7.0 - 2022/06/23
        • 2.2.5.0 - 2022/04/29
        • 2.2.3.0 - 2022/04/01
        • 2.2.2.0 - 2021/12/29
  • Data providers
    • Cryptocurrency exchanges
      • Binance Cryptocurrency Exchange
        • Registration on Binance
          • Registration on Binance Exchange website
          • Configure Binance Wallet
          • Creating a Binance API Key for TSLab
          • Binance. Transferring USDT from wallet to wallet without commission
        • Registration on TSLab [Binance]
          • Account registration on the TSLab website [Binance]
          • Creating a free Binance Data Provider for TSLab
        • Setting up a Binance Data Provider in TSLab
        • TSLab Binance Edition
          • Starting the program
          • Configuring the Binance Data provider
      • Bitget Cryptocurrency Exchange
        • Registration on the Bitget official website
        • Creating a Free Bitget Data Provider
        • Configuring the Bitget Data Provider in TSLab
      • ByBit Cryptocurrency Exchange
        • Registration on the ByBit website
        • Creating a free ByBit data provider
        • Configuring the ByBit Data Provider in TSLab
      • Deribit Cryptocurrency Exchange
        • Deribit data provider settings
        • Deribit. Frequently asked questions and useful information
        • Deribit. Possible problems and solutions
        • Deribit Margin Requirements Calculation
        • An example of a ready-made script for Deribit
      • Kucoin Cryptocurrency Exchange
        • Registration on the KuCoin official website
        • Creating an API key on the KuCoin website
        • Issuing a free license for KuCoin Data Provider
        • Setting up the KuCoin data provider in TSLab
      • OKX Cryptocurrency Exchange
        • Setting up an OKX account
          • Registration on the OKX website
          • OKX API Key creation
          • Issuing a free license for OKX Data Provider
          • Setting up the OKX data provider in TSLab
          • OKX demo account
        • TSLab OKX Edition
          • First launch of TSLab OKEx Edition
          • Configuring the OKEx data provider
          • Trading in TSLab [OKEx]
          • OKEx Demo
    • Historical Data
      • YahooFinance
      • Offline data provider in CSV format
      • An example of connecting text quotes
      • Text files with historical data
    • Interactive Brokers
      • Getting Started with Interactive Brokers Data Provider
        • Installing and configuring the Trader Workstation (TWS) terminal
        • Installing and configuring the IB Gateway terminal
      • Features of working with Interactive Brokers data provider
      • Known issues for Interactive Brokers Data Provider
      • Loading instruments in a package
  • Working with the program
    • Main menu
      • File
        • Program Settings
      • View
        • Chart
          • Features of working with the Chart in TSLab
          • Chart Controls
        • Depth of Market
        • Quotes
        • All Trades
      • Data
        • Data Providers window
        • Add online data provider
        • Add offline data provider
      • Lab
        • Scripts window
          • Script Container
      • Trading
        • Accounts window
        • Positions window
        • My trades window
        • My orders window
          • Move orders and deals to an agent
        • Autotrading Control Center window
          • Agent window
          • Agent trading settings
            • Event recalculations
            • Slippage
          • "Forget errors" of the agent
        • Orders manager
          • Linking a manually completed order to an agent
        • Agent Control Center window
      • Tools
        • Data backup and recovery
        • Notifications manager
          • Notifications Manager Filters
          • Reference List of Service Message Numbers
          • Example of setting up notifications for Gmail
        • Export to Excel
    • Common interface
      • Status bar
      • Tab
      • Workspace
      • Spreadsheets
    • Visual editor
      • Toolbar
        • Compress and Decompress Blocks
      • List of visual blocks
        • Service Elements
        • Cycles
        • TSChannel
      • The syntax of the Formula, Boolean expression and String expression blocks.
    • Autotrading Control Center
      • Agent trade settings
        • Agent trade settings - Placing orders
        • Agent trading settings - Script execution
        • Agent trading settings - Events
    • TSLab API
      • API Introduction
        • Visual Studio Installation
        • First script (API)
        • First Indicator (API)
        • Script Debugging
        • Logging
      • Writing scripts on the API
        • Trading Instrument Data
        • Working with positions
        • List of deals
        • The order queue
        • Standard Indicators and Handlers
        • Script parameters
        • Caching
        • Local and global cache
        • Multiple Tools
      • Writing indicators on the API
        • Stream indicator
        • Bar indicator
        • Pre-processed indicator
        • Indicator with multiple calculations
      • Additional features
        • The ability to create your own optimizers *
        • C ++ / CLI script
        • API Control Panel
        • Result from script
        • * Оптимизация. Пул массивов.
      • Examples
        • Get script results
        • Get script parameters
        • Get script and agent settings
        • Get position balance (net worth)
        • An example of a strategy Breakout of the Donchian channel
        • Example of a Moving Average Crossover strategy
        • Indicator example
        • How to speed up the processing of a script on the API
        • Links to examples
      • Question - Answer
        • HandlerParameter Attribute
    • Optimization
      • Insufficient load on a multicore processor
  • Examples of scripts and indicators
    • Examples of algorithms and indicators
    • Examples of implementing strategies in TSLab
      • A trading system based on indicator CCI
      • A trading system based on Standard Deviation
      • A trading system based on Aroon
      • A trading system based on ADX and DI technical indicators
      • A trading system based on the RSI indicator
      • Example of a trading strategy without parameters
  • TSLab website
    • TSLab Support Service
      • Memory dump of TSLab application
      • TSLab program log files
Powered by GitBook
LogoLogo

Мы в соцсетях

  • Группа в Telegram
  • Новости TSLab
  • Vkontakte
  • YouTube канал TSLab Live

Наши веб-сайты

  • TSLab
  • Служба поддержки
On this page
  • Cycle
  • Add position in cycle
  • Cycle And
  • Cycle Or
  • Cycle logic results
  • Cycle logic result
  • Cycle Max
  • Cycle Min
  • Cycle updatable value
  • Cycle Result
  • Cycle Results
  • Cycle Sum

Was this helpful?

Export as PDF
  1. Working with the program
  2. Visual editor
  3. List of visual blocks

Cycles

Cycle

At the top of the Cycle block there is a service connector for communication with the blocks of opening positions or updated values (simple and updatable cycle value). Thus, the entry into the cycle is indicated (the beginning of the calculation of the cycle). If this connector is not connected to anything, then the first formula (or logical formula) for which the output from the Cycle block is submitted and in which there is an appeal to the Cycle block by its name is considered to be the beginning of the calculation of the cycle.

Block Parameters

  • Maximum number - specifies the maximum number of iterations.

Block Inputs

  • Number (integer). Optional input. Any integer that can be used to control the number of iterations on each candle of the trading cycle (but not more than the specified maximum number). If nothing is submitted to the input, then the cycle always has a specified maximum number of iterations.

Block outputs

  • Number. The current iteration number is from 0 to N-1.

The end of the cycle is considered to be the blocks:

  • Add a position in the cycle

  • Cycle Result

  • Logical result of the cycle

  • Cycle Result when displaying the block on the chat

  • Cycle amount

  • Cycle And

  • Cycle Or

All the blocks that are connected between the beginning of the cycle and the end of the cycle participate in the calculation of the results of the cycle. All the blocks that are connected between the beginning of the cycle and the end of the cycle participate in the calculation of the results of the cycle and they can't be tied to another cycle. For convenience, when the "Show block number" setting is enabled in the script properties, all blocks belonging to the cycle have double numbering.

Pay attention. The binding to the cycle is interrupted with the "Result(s) of the cycle" blocks. The value of these blocks is then used beyond the cycle. The last received value from the associated block is copied to such a block. The physical meaning is the Result and the Results blocks include all the blocks that are tied to the cycle, in the cycle itself.

Add position in cycle

A pass on the bar is performed for all iteration cycles. During the passage, the positions that need to be opened are calculated. As many positions is added, as many iterations returned the result true.

Block parameters

  • Use a Virtual closure. When the parameter is enabled, IsVirtualClosed in IPosition is checked. This parameter is necessary for cases when the position closing signal is missed, so that there are no new gaps. It says that the position signal was issued by the script, but the real application has not yet passed. For example, auto-closing is expected. If the option is enabled, the Cycle will move to the next free iteration, if it is disabled, there will be no new position openings.

Block Inputs

  • Position - mandatory entry. Input data type: Position.

  • Condition - mandatory entry. Input data type: Logical value.

  • Price - optional entry. Input data type: Number. If the Price is not specified, it takes the price from the main position.

  • Amount - optional entry. Input data type: Number. If the quantity is not specified, it takes it from the main position.

Block outputs

No outputs

Physical meaning

When the block is running, in the program, two cycles are performed on each bar:

  1. The first cycle checks which positions need to be closed and closes them.

  2. In the second cycle new positions are opened, for which there are signals. (on the same bar)

If there is not enough space in the iterations of the cycle (all iterations are occupied by positions), that there is not enough space to open a position.

How does adding a position work

When the position closing code is executed, the "Add position in cycle" block may occur. If the condition that comes to the block - true, then the search is performed (by sorting through) for the free number N of the iteration that does not have any active positions on the current candle and the opening of the "Signal:N" position is performed. In this case, the “Condition” at the input to the block is a trigger for creating a position and filling in a new iteration.

Cycle And

If the Boolean values take the value true on all iterations, then, at the output of the block, the value true is returned on the bar (on recalculation). If one of the Logical Values takes the value false, the value false is returned at the output of the block.

Block Parameters

Without parameters

Block Inputs

  • Logical value

Block outputs

  • Logical value

Cycle Or

If in one of the iterations the logical value takes the value true, then the block output returns the value true on the bar (on recalculation), otherwise the value false is returned. At the input, the results of the logical values of the cycle work, for example, a logical formula.

Block Parameters

Without parameters

Block Inputs

  • Logical value

Block outputs

  • Logical value

Cycle logic results

Can be displayed on the chart. The chart will display all the iterations of the cycle. The block results can be passed to another Cycle, with the same number of iterations supported. Nested cycles are not supported.

Block Parameters

Without parameters

Block Inputs

  • Logical value. Logical values of the results of the cycle.

Block outputs

  • Logical value. A list of logical values for each iteration.

Pay Attention!

While in a cycle, when working with Formula blocks, it must be taken into account that if you write Value>CycleResult(fromValue1), the check will be performed only on the current result. Thus, the Value1 and the Value1 will be compared. While in a loop, if you write the logical results of the cycle in the Logical Formula block, the Logical Formula will return the value of the last iteration.

Cycle logic result

Outputs a logical value from the loop to the bar by the iteration number.

Block Parameters

  • Index - a logical result based on the iteration number of the cycle

  • Use last index - always use the last iteration number of the cycle

Block Inputs

  • Logical value - logical value

Block outputs

  • Logical value. A list of logical values for each iteration

Cycle Max

Runs through all the iterations of the cycle and finds the maximum value.

Block Parameters

Without parameters

Block Inputs

  • Number

Block outputs

  • Number

Cycle Min

Runs through all iterations of the cycle and finds the minimum value.

Block Parameters

Without parameters

Block Inputs

  • Number

Block outputs

  • Number

Cycle updatable value

The usual updated value in the cycle moves from the old iteration to the value of the new iteration. The updated cycle value works with an array of iteration values. The output is a list of real values. For each iteration of the cycle, its own separate, independently updated value is maintained.

Block Parameters

  • Initial - The initial value of the block.

  • Execution order - Determines the queue for calculating the Updated value in the algorithm, in the general order (by default), at the end of the algorithm (in the queue of this calculation branch) or after leaving the position.

Block Inputs

  • Number

  • Logical value

  • Logical value

Block outputs

  • Number

Pay Attention

A handmade indicator with the "Updated cycle value" block starts working if the Result block or Cycle Results block is at the end of the calculations. Other blocks are turned on immediately. You can see the inclusion in the cycle if you enable "Show the number of the cube" in the properties.

Cycle Result

Returns the value by the iteration number, and outputs the value to the bar.

Block Parameters

  • Index - indicates from which iteration it is necessary to copy the real value to output it to the bar.

  • Use the latest index

Block Inputs

  • Number - a mandatory input. A list of values of the results of the cycle. (For example, a formula, an updated value, any block that is in a cycle).

  • Number - not a mandatory input, to which the iteration number is sent, which needs to be copied to the result. If nothing is submitted, the last received value is taken.

Block outputs

  • Number

Cycle Results

Can be displayed on a chart. It can be passed to another cycle, with the same number of iterations supported. Nested cycles are not supported. A service connector for displaying the parameter to the control panel.

Block Parameters

Without parameters

Block Inputs

  • Number. Values of the results of the cycle.

Block outputs

  • An array of the value of each iteration on each bar.

Pay Attention

While in a cycle, when working with Formula blocks, it must be taken into account that if you write Value>CycleResults (fromValue1), the check will be performed only on the current result. Thus, the Value1 and the Value1 will be compared.

Cycle Sum

The result is the sum of the values of all iterations of the cycle.

Block Parameters

Without parameters

Block Inputs

  • Number. Values of the results of the cycle. (For example, a formula, an updated value, any block that is in a loop)

Block Outputs

  • Number.

Last updated 3 years ago

Was this helpful?