If

From MultiCharts
Revision as of 12:44, 18 January 2012 by 194.84.116.138 (talk) (Created page with "Used in combination with Then to form a conditional statement that executes specific instructions if a logical expression is true, and with Else to form a conditional ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Used in combination with Then to form a conditional statement that executes specific instructions if a logical expression is true, and with Else to form a conditional statement that executes specific instructions if a logical expression is false.

The conditional execution statement must contain both If and Then; Else is optional.

Begin and End statements are used to group instructions for conditional execution; a Begin must always be followed by an End.

Begin should not be followed by a semicolon (;), code lines within an instruction group should end with a semicolon (;), and only the last instance of End within the same conditional execution statement should be followed by a semicolon (;).

Usage

If E Then I1 Else I2

or:

If E Then Begin 
I1;
I2;
End
Else Begin
I3;
I4;
End;

Where: E - a true/false expression

I - conditional instructions

Example

If UpTrend is false then sell:

If UpTrend=False Then Sell Next Bar Market;

If UpTrend is true then buy, otherwise sell short:

If UpTrend Then Buy Next Bar Market Else SellShort Next Bar Market;

If UpTrend is true then buy, otherwise sell short:

If UpTrend Then Begin
Buy Next Bar Market;
End
Else Begin
SellShort Next Bar Market;
End;