PureBytes Links
Trading Reference Links
|
You are also going to have to modify this statement so that it can
handle prices above 99.99 and below 10.00 (3-digit and 5-digit prices
instead of just 4). There are also funds priced below $1.00, and one
day you might want to use the function to reference BRK.A
BuyPrice1 = StrToNum(StrMid(VarA,19,5));
--- In amibroker@xxxxxxxxxxxxxxx, "Ron Rowland" <rowland@xxx> wrote:
>
> Ken,
> A function only returns one variable - the one identified in the
> return statement. If you want to return more than one variable,
then
> you need to identify them as "global" inside your function,
otherwise
> the defualt is "local".
>
> Adding the following line after the "{" in the function should help.
> global BuyDate1, BuyPrice1;
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Ken Close" <ken45140@> wrote:
> >
> > 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
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> 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/
|