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

[amibroker] Re: String Manipulations



PureBytes Links

Trading Reference Links

Would the following (untested) code do the job?

global SymList = "";
global ShrList = "";
global DatList = "";

procedure addPosition(posString) {
  local sym = StrExtract(posString, 0);
  local shr = StrExtract(posString, 1);
  local dat = StrExtract(posString, 2);

  if (StrLen(SymList) > 0) {
    SymList += ",";
  }

  SymList += sym;

  if (StrLen(ShrList) > 0) {
    ShrList += ",";
  }

  ShrList += shr;

  if (StrLen(DatList) > 0) {
    DatList += ",";
  }

  DatList += dat;
}

H1 = "SPY,500,06/04/2008";
H2 = "DIA,100,09/02/2008";
H3 = "QQQQ,300,08/04/2008";

addPosition(H1);
addPosition(H2);
addPosition(H3);

... At this point, I believe that your lists are as you wanted them.

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "Ken Close" <ken45140@xxx> 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.
>




------------------------------------

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/