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

RE: [amibroker] Substuting ";" with "," in a TWS trade file



PureBytes Links

Trading Reference Links

Thank you so much for your help Ed,

Putting your code and what i had so far together i came up with the function
below. Appears to work fine, can it be improved?

Having set the TWS to automatically export trades to a file i can now
StrExtract values easily and use them in my Interpretation window and to
chart the actual trades on my charts. This way i can do away with all my
StaticValue code which was getting very awkward to work with - also my
trades are now in permanent files.

Thanks for all the help!
best regards,
herman.

procedure ConvertSCSVtoCSV( Infilename, OutFileName )
	{
	InputPath = "C:\\Program Files\\AmiBroker\\TWSTrades\\"+Infilename; 	//
Semi-colon separated values
	OutputPath = "C:\\Program Files\\AmiBroker\\TWSTrades\\"+OutFileName; 	//
Comma separated values
	fdelete( OutPutPath );
	fh1 = fopen( InputPath, "r");
	fh2 = fopen( OutputPath, "a");
	if( fh1 AND fh2)
		{
  	 	while( ! feof( fh1 ) )
   		{
     	 	Line1 = fgets( fh1 );
			Line2 = "";
			Len = StrLen(Line1);
			for(p=1; p<=Len; p++)
				{
				Char = StrMid(Line1,p,1);
				if( Char == ";" ) Char = ",";
				Line2 = Line2 + Char;
				}
			fputs( Line2, fh2);
 			}
		fclose(fh1);
		fclose(fh2);
		}
	else
		{
   		printf("ERROR: file can not be opened");
		}
	}

ConvertSCSVtoCSV( "TWSTrades.txt", "TWSTrades.csv" );

-----Original Message-----
From: ed nl [mailto:ed2000nl@xxxxxxx]
Sent: Friday, April 08, 2005 4:56 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: Re: [amibroker] Substuting ";" with "," in a TWS trade file


hi herman,

this is the closest I get using AFL. It does not seem to be possible to read
and write to the same file (correct me if I'm wrong). So you have to make a
change to the line and write it to another file. Also I run this from a
chart window ..... Seems to me an external tool would be easier so you can
change a whole directory at once.,

rgds, Ed


// open file
fh = fopen(fileName, "r");
fh2 = fopen(fileName2, "w");


if(fh) {

   while( !feof(fh ))  {

   // read the file line by line
   ss = fgets(fh);

   // string length
   sl = StrLen(ss);

   // storage array
   newString = "";

      for (i=0; i<sl; i++) {

         if (StrMid(ss,i,1) == ";") {

            newString = newString + ",";

         } else {

            newString = newString + StrMid(ss,i,1);

         }


      }

      // write newString to file
      fputs(newString,fh2);

   }

}

fclose(fh);
fclose(fh2);

----- Original Message -----
From: Herman van den Bergen
To: amibroker@xxxxxxxxxxxxxxx
Sent: Friday, April 08, 2005 10:32 AM
Subject: RE: [amibroker] Substuting ";" with "," in a TWS trade file


Thanks everyone for the replies!

My mind wasn't to clear last night and I was looking for a quick and easy
solution; yes I'll use the afl str functions. I'll also email to AB-sugggest
that the delimiter be made optional in the StrExtract(), like StrExtract(
list, item, Delimiter="," )

I have been using StaticVariables to plot real trades on my charts but I
think reading the actual TWS tradelist and plotting those values will be
better and easier.

best regards,
herman
-----Original Message-----
From: Michael.S.G. [mailto:OzFalconAB@xxxxxxxx]
Sent: Friday, April 08, 2005 1:56 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: Re: [amibroker] Substuting ";" with "," in a TWS trade file


Herman,
    How do you want to do it?

I have a JScript file that does just what you are after.

Or (Prefered method) do as Ara said. Use StrFind etc
to locate each sub section.

eg (not real code)
Line = Readline from file....
for I = 1 to StrLen(Line)
Loc = StrFind(Line); //Find 1st occurance left to right
Part(I) = StrLeft(Line,Loc); //Allocate x part.
RightNum = StrLen(Line) - Loc; //Calc remaining  str len.
Line = StrRight(RightNum);
Next I;

Or something like that  (Have to check the RightNum assignment - I think
it's not quite right*)
Anyway gota go - Just popped home for 5min and out again. ;-)

*Umm yeah - The for loop will continue after the string has been
dismembered. You'd have to fix that.

Atb
    Michael.

Herman van den Bergen wrote:

> would anyone have code or know how to substitute semi-colons in a file
> with commas?
>
> The TWS outputs trade records in semi-colon separated text file, like so:
>
> RIMM;SLD;50;72.56;13:32:59;20050407;ISLAND;U84507;;;534;
> RIMM;BOT;100;73.04;13:37:49;20050407;ISLAND;U84507;;;534;
> RIMM;SLD;50;73.44;13:41:56;20050407;ISLAND;U84507;;;534;
> RIMM;SLD;50;73.44;13:41:56;20050407;ISLAND;U84507;;;534;
>
> I want to read the files with afl which would be so much easier if the
> semi-colons were commas.
>
> many thanks for any help you can give!
>
> herman
>
>
> 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 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/
>
>     * 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/>.
>
>



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 other support material please check also:
http://www.amibroker.com/support.html





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 other support material please check also:
http://www.amibroker.com/support.html






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

To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx

Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.




------------------------ Yahoo! Groups Sponsor --------------------~--> 
In low income neighborhoods, 84% do not own computers.
At Network for Good, help bridge the Digital Divide!
http://us.click.yahoo.com/EpW3eD/3MnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

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

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