Exercises: Else Statements & Block Statements

1. Else Statement

Construct an else statement that instructs to go long if the close is above the close five bars ago, and short if its below. 

if close>close[5] then buy next bar open


sellshort next bar open;

2. Block Statement

Use a block statement to exit short and long trades after 5 bars.

If barssinceentry=5 then begin

sell next bar open;

buytocover next bar open;


3. Else-if Statement

Code an else-if statement that will go long if the close is higher than the open, and short if the close isn’t higher than the open and it’s not Tuesday.

if close>open then buy next bar open


if dayofweek(date) <> 2 then sellshort next bar open;


Login to Your Account

Signup Here
Lost Password