Module 1: Starting to Program
Module 2: Indicators and Functions
Module 3: Variables
Module 4: Inputs
Module 5: Exit Techniques
Module 6: Stop Orders and Limit Orders
Module 7 Using Multiple DataStreams in a Strategy
Final Strategy Coding Project
Module 8: Plot Studies and Their Uses
Module 9: Writing to Files
Module 10: How to Code Your Own Indicators and Functions

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