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

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



PureBytes Links

Trading Reference Links

Sebastian,

Sorry it took so long to answer. Was busy today and Comcast has been down for 5 hours.

If you want yesterday's value of Cond3 just refer to it. If you do as you did in Cond4 you have just undone what you did in Cond3. So:
Cond4 = ref(Cond3,-1);

This works fine since you already computed the value of Cond3 so, in subsequent lines of code you can refer to any array already processed.

You get an error with Cond5 because AB does not support string arrays. Just print the value like this:
NumToStr(Cond4,1.0);
It will show in the Interpretation window for each day you select.

Cond6 refers to Cond5 which is the same as Cond4 from above (and Cond5 is illegal as a string).
Also Cond6 IIf statement has problems. See my correction here. Extra parenthesis not required (will cause problems) for 2nd IIf.

Note that Cond1 == 1 is IDENTICAL to Cond1 since a positive non-zero value to an array element is considered to be TRUE. This allows flexibility, for example, when doing stops. A normal Stop = 1, Profit, Trail, nBar, and Stop Loss are assigned 2,3,4,5 (not necessarily in that order). Thus all are true and get a Sell condition, but the backtester can report to you which stop triggered by evaluating the actual value.

Cond6 = IIf(Cond1, 1, IIf(Cond4 AND Cond2, 0, Cond4));

sebastiandanconia wrote:
Okay, I've gotten to here:

Cond1=C > Ref(HHV(C,55), -1 );
Cond2=C < Ref(LLV(C,55), -1 );

Cond3=Flip(Cond1,Cond2);
Cond4=Ref(Flip(Cond1,Cond2),-1);
Cond5=NumToStr(Cond4,1.0,True);

Cond6=IIf(Cond1 == 1,1, IIf(Cond4 == 1 AND Cond2 == 1), 0, Cond5));


and get a "syntax error" from AFL checker between the last pair of 
parenthesis after "Cond5."  It looks right, doesn't it?


Luck,

Sebastian





--- In amibroker@xxxxxxxxxxxxxxx, Terry <MagicTH@xxxx> wrote:
  
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 --------------------~--> 
What would our lives be like without music, dance, and theater?
Donate or volunteer in the arts today at Network for Good!
http://us.click.yahoo.com/Tcy2bD/SOnJAA/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/
 




  


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