Usually, every command statement is written on a separate line and ended with a semicolon ( ; ). Some kinds of statements, namely If conditions, For loops and While loops, require additional command statements that are used inside the condition or loop execution block. In many cases, you will want to perform more than one action inside a condition or loop execution block.

If you want to execute more than one command statement inside an If condition, For loop or While loop, you need to write a block statement.

Note             You have probably noticed that the execution section as a whole is a block statement, too. In contrast to normal block statements, the execution section is ended with a full stop ( . ) though.

Syntax

Begin
   Statement1;
   Statement2;
   ...
   StatementN;
End;

Begin

Starts the block statement

Statement1

Statement2

StatementN

Any single command statements that should be executed inside the block.

Write them like you would do outside of the block. Every statement has to be ended with a semicolon ( ; ).

End

Ends the block statement. You have to close the block statement with a semicolon ( ; ).

Example

For the calculation of the Accumulation Swing Index, block statements are used inside an If condition statement. You can see in this example that block statements can also be used inside of other block statements.

If IsValid(Source.Open) And IsValid(Source.High) And IsValid(Source.Low) And IsValid(Source.Close) Then
   Begin
          swingIndex = #swing_index(Source, limitMove);
          If IsValid(swingIndex) Then
          Begin
                 If Not IsValid(sumResult[1]) Then
                       sumResult = swingIndex
                 Else
                       sumResult = sumResult[1] + swingIndex;
                 DrawLine("ASI", sumResult);
          End
          Else
                 sumResult = sumResult[1];
   End;