[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] if-else control statement vs IIF function



PureBytes Links

Trading Reference Links





Hello,
 
It seems that people tend to confuse if-else and IIF. Here is 
some more explanation:
 
if-else is flow control statement. it allows you to change the 
flow of the program (skip some parts of the formula)
 
if( Name() == "MSFT" )
{
   // the special handling for MSFT
   // this part is executed only for MSFT and 
skipped for all other symbols
   Plot( MA( Close, 10 ), "MA10 for Microsoft only", 
colorGreen );
}
 
 
- in this example moving average it plotted ONLY when ticker 
is MSFT. The part in curly braces is skipped
completely if ticker is different.
 
IIF is a FUNCTION that evaluates all arguments always and just 
returns the value of 2nd or 3rd argument
depending on condition (1st argument). There is no way to skip 
any part of the formula using IIF.
 
Also IIF works on ARRAYS while if is a statement that works on 
single TRUE/FALSE value;
 
IIF in fact can be re-implemented using if-else
 
function IIFreimplemented( ConditionArray, TrueArray, 
FalseArray )
{
   for( i = 0; i < BarCount; i++ )
   {
        if( ConditionArray[ i ] 
)
        
{  
           
result[ i ] = TrueArray[ i ];
        } 

        else
        {
<FONT 
size=2>           result[ 
i ] = FalseArray[ i ];
        }
   }
}
 
IIFreimplemented works exactly like built-in IIF.
 
Best regards,Tomasz 
Janeczkoamibroker.com
Best regards,Tomasz 
Janeczkoamibroker.com






Yahoo! Groups Sponsor












Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.