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

Re: [amibroker] Trying to duplicate Excel "IF" statement in Amibrokerusing "IIF"



PureBytes Links

Trading Reference Links

Sebastian,

Your line of code DEFINES Cond3, but you are trying to reference the 
prior value of Cond3 within the definition of condition 3, hence the 
error. I had this same difficulty coming to AB from Excel. The problem 
here is understanding the ARRAY nature of AB.

There are a couple of ways around this and one way is to use looping 
code where you define each bar one bar at a time. Then your reference to 
yesterday's value of Cond3 IS valid while trying to set today's value 
because yesterday's value has already been defined. In array processing 
no values are defined so you cannot refer to yesterday's C3. (Arrays 
don't process one bar at a time, they process all bars at once.)

The other way is to define Cond3 using only Cond1 and Cond2 as in:

    Cond3 = Flip(Cond1,Cond2); //Flip fills in all bars between conditions with same value

To display the result you will have to convert numeric values to string 
values with NumToStr(). Your other choice is to PLOT the results.

Note: your parenthesis and use of IIF statements in your example below 
is incorrect. The format you used is:
    IF(A,1,IF(B) AND IF(C),0,D);
It needs to be:
    IF(A,1,IF(B AND C),0,D));
Terry

sebastiandanconia wrote:

>In Excel I have an "IF" statement that tells what to display in a 
>cell, like this:
>
>=IF(E65>MAX(E25:E64),1,IF(AND(H64=1,E65<MIN(E45:E64)),0,H64))
>
>The "E" column is closing security prices, the "H" column displays a 1 
>or 0 telling me whether the trend is up or down, and the formula 
>continues all the way down to the last row of closing prices.  If 
>there's no change from the previous day's value in column "H", the 
>previous day's value is displayed. 
>
>I don't need AB to do anything with the result, just display the 
>result, so I think I need to use "IIF" and not "IF-ELSE" or looping.
>(??)
>
>I have Cond1 defined as being the upside breakout (MAX) and Cond2 as 
>the downside breakdown (MIN). Cond3 is the IIF statement I'm trying to 
>create, like this:
>
>Cond3=IIF(Cond1==1,1,IIF(Ref(Cond3,-1)==1 AND IIF(Cond2==1)),0,Ref
>(Cond3,-1);
>
>Then I'll use Cond3's output of 1 or 0 as a binary signal to identify 
>uptrend or downtrend.
>
>I can't get it to work for me, though.  The AFL checker tells me I'm 
>using Cond3 before it's been initialized, but I don't know how to get 
>around that.
>
>TIA for any guidance, and it's okay to laugh if I did something really 
>dumb.:)
>
>
>Luck to all,
>
>Sebastian
>  
>


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Has someone you know been affected by illness or disease?
Network for Good is THE place to support health awareness efforts!
http://us.click.yahoo.com/Rcy2bD/UOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

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/

<*> 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/