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

[amibroker] Re: if-else control statement vs IIF function



PureBytes Links

Trading Reference Links

Tomasz,
the theoretical explanation is clear, the example is a bit confusing:
We may equally plot 10-bar MA exclusively for MSFT with the use of 
IIF statement
k=IIf(Name()=="MSFT",MA(C,10),-1E10);
Plot(C,"",1,64);
Plot(K,"",4,1);
Title=Name()+", CLOSE="+WriteVal(C)+WriteIf(Name()=="MSFT",", 
10MA="+WriteVal(K),"");
Another example perhaps ?
Dimitris Tsokakis
--- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <amibroker@xxxx> 
wrote:
> 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
>         {
>            result[ i ] = FalseArray[ i ];
>         }
>    }
> }
> 
> IIFreimplemented works exactly like built-in IIF.
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> Best regards,
> Tomasz Janeczko
> amibroker.com


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get A Free Psychic Reading! Your Online Answer To Life's Important Questions.
http://us.click.yahoo.com/Lj3uPC/Me7FAA/ySSFAA/GHeqlB/TM
---------------------------------------------------------------------~->

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 http://docs.yahoo.com/info/terms/