×

Sign up and get MultiCharts free

Use its powerful simulation mode with data included out of the box. Just fill out the form and start honing your trading skills with a few clicks.

Changes - MultiCharts

Changes

Jump to navigation Jump to search

If

421 bytes added, 10:53, 19 February 2012
no edit summary
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.
[[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 ====
<syntaxhighlight>If E Then I1 Else I2</syntaxhighlight>
<syntaxhighlight>If E Then Begin
I1; I2;
End
Else Begin
I3; I4;
End;</syntaxhighlight>
Where: [[ :'''E]] ''' - a true/false expression.:'''I''' - conditional instructions.
== Notes ==* [[IBegin]] - and [[End]] statements are used to group instructions for conditional instructions 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 (;).
==== Example ==Examples ==If [[the condition ''UpTrend]] '' is false then sell:
<syntaxhighlight>If UpTrend=False Then Sell Next Bar Market;</syntaxhighlight>
If [[''UpTrend]] '' is true then buy, otherwise sell short:
<syntaxhighlight>If UpTrend = True Then Buy Next Bar Market Else SellShort Next Bar Market;</syntaxhighlight>
If [[''UpTrend]] '' is true then buy, otherwise sell short:
<syntaxhighlight>If UpTrend = True Then Begin Buy Next Bar Market;
End
Else Begin
SellShort Next Bar Market;
End;</syntaxhighlight>
Another example of using multiple [[Begin]] and [[End]] statements would be:
<syntaxhighlight>
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");
</syntaxhighlight>
[[Category:Comparisons and Loops]]

Navigation menu