The Loop block generates and outputs a user-specified number of empty discrete event messages, one after another, to facilitate designs that require loops.
Example The Loop block starts a three-interation loop (as specified through its times input port) when the Generator block sends a discrete event message through the Loop block's enter port. For each iteration, the Loop block outputs the loop counter through its index port and sends an empty discrete event message through its loop output port. For the last interation, the Loop block also sends an empty discrete event message through its Exit output port.
Note The Loop block outputs the counter through the index port before the discrete event message is generated and output.
It is important to note that the Loop block does not allow any "actor" block (i.e., a block that can take tangible actions such as placing an order) to take an action while it is performing the loop.
Example Loop block fails to decrement an order price.
In this example, the Loop block is designed to loop up to three times, and at each iteration it decrements the price input of the Order block by one price increment. At a glance, it might seem that the Order block will generate three change requests to incrementally move its child orders down the market. However, the Loop block does not allow the Order block to take any actions during the loop. It is only after the loop has completed that the Order block can take an action using the final resulting price input.
The following sequence of events occurs when this algorithm is started:
One way you could solve the timing problem is to use a Discrete Order block instead of an Order block and send a discrete event message throught Loop block's loop port to the msg input port of the Discrete Order block. Using the loop output allows the downstream action to send an order before starting the next loop iteration, shown in the following example.
Example Use the Loop block to create a stack of Buy orders in the market
To customize the block, update the Block Properties.
|Name to display beneath the block on the ADL canvas