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

[amibroker] Procedures and Functions



PureBytes Links

Trading Reference Links

I am trying to do some repetitive string manipulations, and keep getting errors when trying to use a function.
 
Can you help me out with this simplified code to exemplify what I am trying to do.
 
Lets say I have a series of strings like this:
 
 
T1 = "DODFX 06/10/2007 50.78 ";
T2 = "JORNX 07/13/2007 11.84";

The contents are obvious, and I would like to set up some code which cycles through these strings and extracts the relevant data.

In Logic, Loop through each string, extract Sym, Date, Purchase Price, calculate some stats, Print a line of results in an Explore grid.

I tried code like this:

function GetData(VarA)
{
Sym1 = StrMid(VarA,1,5);
BuyDate1 = StrMid(VarA,7,10);
BuyPrice1 = StrToNum(StrMid(VarA,19,5));
P1 = Foreign(Sym1,"C");
D1 = LastValue(P1) - BuyPrice1;
Pct1 = 100 * (P1 - BuyPrice1)/BuyPrice1;
return Sym1;
}
 
then this:
 
 
function PrintLine(Sym1,BuyDate1,BuyPrice1,P1,D1)
{
AddTextColumn(Sym1,"Symbol",1.0);
AddTextColumn(BuyDate1,"BuyDate",1.0);
AddColumn(BuyPrice1,"BuyPrice",1.2);
AddColumn(P1,"CurPrice",1.2);
AddColumn(D1,"Gain",1.2);
AddColumn(Pct1,"PcntGain",1.2);
}
 
for( i = 1; i < 3; i++ )
{
if (i == 1) XX = T1;
if (i == 2) XX = T2;
YY = GetData(XX);
_TRACE(Sym1);
PrintLine(Sym1,BuyDate1,BuyPrice1,P1,D1);
}
 
However, I can not get past the first step of recognizing the first variable, Sym1 (Error: Sym1 has not been initialized).
 
I thought once I call the function, that the pass through the function establishes the variables contained within the function.  IOW, the first call to GetData(VarA) establishes the Variable "Sym1".  This does not seem to be the case.
 
So what might I do differently?  At least to get the GetData function to operate properly.  I have several other questions but would appreciate getting at least this far.
 
Thanks for any help.
 
Ken
__._,_.___

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





SPONSORED LINKS
Investment management software Investment property software Investment software
Investment tracking software Return on investment software

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___