+1 888 340 6572

If

From MultiCharts

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 - the use of Else is optional.

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.

Notes

  • 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 (;). The 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 (;).

Examples

If the condition UpTrend is false then sell:

If UpTrend = False Then Sell Next Bar Market;

If UpTrend is true then buy, otherwise sell short:

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

If UpTrend is true then buy, otherwise sell short:

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

Another example of using multiple Begin and End statements would be:

Variables:
	EMA(0);
	
EMA = XAverage(Close, 20);

if Close > EMA then begin

	Print("Close is above the EMA");

end else if (Close < EMA) then begin

	Print("Close is below the EMA");

end else 

	Print("Close is equal to the EMA");