You would also need to add the comma handling, as was done in the
sample that I gave.
If you wanted to combine the two approaches, you could just have the
loop call the addPosition procedure, else move the addPosition
procedure logic into your loop.
VarSetText("H1", "SPY,500,06/04/2008");
...
totalSymbolCount = ...;
for (i = 1; i <= totalSymbolCount; i++) {
addPosition(VarGetText("H" + i));
}
Using a procedure helps get rid of the clutter from your primary
logic, at the expense of an additional function call. Similarly, it is
probably faster to use direct variable referencing rather than
VarGetText/VarSetText and a loop. But, if you anticipate many "H"
values, the dynamic variables will keep things more succinct and
easier to maintain.
Mike
--- In [email protected], Dennis Brown <[EMAIL PROTECTED]> wrote:
>
> Hi Ken,
>
> The problem is that you defined H1 as a regular variable and the
code
> is looking for a static variable named H1. Therefore, the static
> variables are empty. For your test here, just use VarGetText(...
> Or make your variables into static variables:
> StaticVarSetText("H1", "SPY,500,06/04/2008");
> etc.
>
> BR,
> Dennis
>
> On Sep 19, 2008, at 4:51 PM, Ken Close wrote:
>
> > Dennis:
> >
> > I feel I have a lot to learn from dynamic variables here (asked
once
> > before), but right now I can not make this concept work.
> > Code below is my modifcation of your concept and it does not crash
> > but only prints the commas between the strings.
> > List becomes H1 on the first pass through the loop, then, SymList
is
> > SymList (empty on first pass) + the first (0) item in H1, or the
> > first symbol. At a minimum, the Symlist will eventually be
> > ",SPY,etc) as there is no logic to skip the first comma---unless I
> > am reading it wrong. Same issue on each of the other ShrList and
> > DatList.
> > So, not sure what I am missing, nor have I been successful in
adding
> > anything to correct the problem.
> > Any suggestions?
> > Many thanks for responding.
> > Ken
> > ==============================
> > My code using your concept"
> > H1 = "SPY,500,06/04/2008";
> > H2 = "DIA,100,09/02/2008";
> > H3 = "QQQQ,300,08/04/2008";
> > H4 = "BEARX,1204,05/21/2007";
> > TotalSymbolCount = 4;
> > SymList = "";
> > ShrList = "";
> > DatList = "";
> > for( i=1; i < totalSymbolCount; i++ )
> > {
> > list = StaticVarGetText( "H" + NumToStr(i, 1.0, 0));
> > SymList = SymList + "," + StrExtract( list , 0);
> > ShrList = ShrList + "," + StrExtract( list, 1);
> > DatList = DatList + "," + StrExtract( list, 2);
> > }
> > Title = Symlist + "\n" +
> > ShrList + "\n" +
> > DatList;
> >
> >
> > ===============================
> >
> > From: [email protected] [mailto:[EMAIL PROTECTED]
> > On Behalf Of Dennis Brown
> > Sent: Friday, September 19, 2008 1:47 PM
> > To: [email protected]
> > Subject: Re: [amibroker] String Manipulations
> >
> > Ken,
> >
> > This is quite easy by using the StrExtract( list, item) function.
I
> > am doing some similar things in the AFL I am writing for the AFL
> > Glossary project.
> >
> > Typing this off the top of my head to give you the basic idea:
> >
> > For( i=1; i < totalSymbolCount; i++ )
> > {
> > list = VarGetText( "H" + NumToStr(i, 1.0, 0);
> > SymList = SymList + "," + StrExtract( list , 0);
> > ShrList = ShrList + "," + StrExtract( list, 1);
> > DatList = DatList + "," + StrExtract( list, 2);
> > }
> >
> > BR,
> > Dennis
> >
> > On Sep 19, 2008, at 12:53 PM, Ken Close wrote:
> >
> >> I have tried various constructions to achieve the following, but
> >> the code gets complex and has no good way of detecting end of
string.
> >>
> >> I would like to take a series of strings, H1, H2, H3, and create
> >> lists of the elements, as such
> >>
> >> H1 = "SPY,500,06/04/2008";
> >> H2 = "DIA,100,09/02/2008";
> >> H3 = "QQQQ,300,08/04/2008";
> >>
> >> and turn them into these three lists
> >>
> >> SymList = "SPY,DIA,"QQQQ";
> >> ShrList = "500,100,300";
> >> DatList = "06/04/2008,09/02/2008,08/04/2008";
> >>
> >> Hx strings would be hard coded into the overall afl although one
> >> could set up a variety of paramtxt statements to enter them.
> >>
> >> Seems like it would be somewhat easy (and maybe it is), but I get
> >> bogged down in switch/case statements, or complex if/else
statements.
> >>
> >> Anyone see a more simple way to arrange the strings.
> >>
> >> My ultimate goal is to have a list of "holdings" and some simple
> >> statistics displayed.
> >> AA window with a Watchlist seems obvious--yes?--but I need to
have
> >> multiple positions of the same symbol, and I do not think you can
> >> put multiples of the same symbol in a watchlist--same symbol with
> >> different shares purchased on different dates-- (is there a way?
).
> >>
> >> I next tried dynamic variables, in order to manipulate symbols
and
> >> their associated price statistics, but that bombed.
> >>
> >> So now I am attempting to display my list of holdings in a Gfx
> >> title statement.
> >> I successfully have it displayed, but using long strings, like
> >> above for the SymList, ShrList, and DatList. This gets
> >> unmanageable when the number of symbols gets large and you try,
by
> >> eye, to coordinate the dates and shares.
> >>
> >> Thus, I was hoping to list a three element string reprenting each
> >> holding and then rearrage them into long string lists.
> >>
> >> any ideas?
> >>
> >> thanks.
> >>
> >>
>