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

[amibroker] Re: Compacting IF statements and variable assignments



PureBytes Links

Trading Reference Links

If the rank values are all as regular as the ones shown, then a
single-line formula would do it as already indicated. However, if they
aren't all regular and can't easily be calculated by a single
equation, then a switch/case statement should be more efficient than a
pile of "if" statements, although not a lot shorter to write:

Buy = False;
switch (A) {
    case 0:
        Buy = Rank < 0; break;
    case 1:
        Buy = Rank >=0  AND  Rank < 60; break;
     ...
    case 100:
        Buy = etc...; break;
    }

Regards,
GP


--- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@xxx> wrote:
>
> Hello, hoping someone can put in their two cents on how to compact IF 
> statements and variable assignments.    In the below partial code
> snippet, I set up 100 variables for optimization.  Then, depending on
> the optimization, I want to set the "final" variable to the  optimized
> variable. But this entails me manually writing out 100 IF statements. 
> Is there some function or coding strategy that can be used to compact
> all of the  below?       A            = Optimize("A",    0,      0,   
> 100,     1);    Tier0        = Rank < 0;
> Tier1        = Rank >=0  AND  Rank < 60;
> Tier2        = Rank  >=30 AND Rank < 60;
> Tier3        = Rank >=60 AND  Rank < 90;
> Tier4        = Rank  >=90 AND Rank < 120;
> .
> .  ETC.
> .
> Tier100      = Rank...  ETC.
> 
> 
> if(A == 0)  Tier = Tier0;
> if(A == 1)  Tier = Tier1;
> if(A == 2)  Tier = Tier2;
> if(A == 3)  Tier = Tier3;
> if(A == 4)  Tier = Tier4;
> .
> .  ETC.
> .
> if(A ==100)  Tier = Tier100;
> 
> 
> Buy = Tier;
>



------------------------------------

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

*********************
TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com
*********************

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html

*********************************
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/