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

Re: [amibroker] IF for arrays?



PureBytes Links

Trading Reference Links

Answering my own question, if() code DOES work with arrays:

//Load available symbol for COMP
whichEquity = IIf(SetForeign(COMP,True,False),True,False);
If (NOT whichEquity)
    whichEquity = IIf(whichEquity,False,SetForeign(COMP_alt,True,False));

AlertIf(NOT whichEquity,"","Tell user about missing symbols");
-- 
Terry


From: Terry <MagicTH@xxxxxxxxxxx>
Reply-To: amibroker@xxxxxxxxxxxxxxx
Date: Mon, 04 Oct 2004 15:54:22 -0600
To: Amibroker <amibroker@xxxxxxxxxxxxxxx>
Subject: [amibroker] IF for arrays?

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



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

Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html


Yahoo! Groups Sponsor
 
 ADVERTISEMENT
 <http://us.ard.yahoo.com/SIG=12902da9f/M=295196.4901138.6071305.3001176/D=g
roups/S=1705632198:HM/EXP=1097013327/A=2128215/R=0/SIG=10se96mf6/*http://com
panion.yahoo.com>  


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
<mailto:amibroker-unsubscribe@xxxxxxxxxxxxxxx?subject=Unsubscribe>
*  
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> .




------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/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/