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

[amibroker] IF for arrays?



PureBytes Links

Trading Reference Links

I have code that I share with other users. Some users have eSignal, some
Yahoo.

One of the indicators in this AFL need the COMPQ loaded as a foreign symbol.
I wrote the following AFL to use eSignal symbols if available, then use
Yahoo symbols if eSignal version is not available.

I load the $COMPQ which returns True if it exists and false if not. This is
fine. Then based on that result I load ^IXIC if the $COMPQ load was false.

The problem: IIF() always executes both parts of the test so the 2nd symbol
is always loaded regardless of whether the first symbol loaded or not. (See
2nd section of code)

I can't use: 
   if(cond) load symbol A ELSE load symbol B
Because the if() statement is not for arrays.

I wonder if loading the 2nd choice first and then testing would work? Would
this leave the first symbol loaded if the 2nd did not exist or would it
revert back to the selected symbol?

Suggestions?
----------------------
// Define symbol names

EnableTextOutput(False);
//First and second choices for the Nasdaq Composite Index
COMP = "$COMPQ"; 
COMP_alt = "^IXIC";
 
//Load available symbol for COMP
whichEquity = IIf(SetForeign(COMP,True,False),True,False);
whichEquity = IIf(whichEquity,False,SetForeign(COMP_alt,True,False));
AlertIf(whichEquity==0,"","Cannot find " + COMP + " or " + COMP_alt + "
symbols");
 
//Code using COMP goes here
 
RestorePriceArrays();
 
//First and second choices for the Nasdaq100 Index
NDX = "$NDX"; 
NDX_alt = "^NDX";
EnableTextOutput(True);

//Load available symbol for NDX -- same as above for COMP
whichEquity = IIf(SetForeign(NDX,True,False),True,False);
whichEquity = IIf(whichEquity,False,SetForeign(NDX_alt,True,False));
AlertIf(whichEquity==0,"","Cannot find " + NDX + " or " + NDX_alt + "
symbols");
 
//Next block of code uses NDX...
--
Terry



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.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/