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

[amibroker] Request for Code Review


  • Date: Thu, 11 Mar 2010 17:42:03 -0000
  • From: "longt3rm" <longt3rm@xxxxxxxxx>
  • Subject: [amibroker] Request for Code Review

PureBytes Links

Trading Reference Links

Hello,

I'm slowly grasping AFL; really slowly.  ;-)

The code below looks for a text file for the date of the current bar, if it finds the ticker, it goes long.

Would anyone have comments / suggestions on improvements? Specifically, I am wondering if traversing the bars is necessary or if there is a way to skip the "for" loop.

Thank you!!

Bill

----------------------------------------------------
/*
This is NOT a strategy but rather a learning exercise.
The purpose is to study / learn how to open an external file to test whether a ticker is contained in that file; next I will add the number of shares and price to use.
*/

function DateCheck(myTicker,filename){
//See if the filename contains myTicker
DateCheckReturn = False;
fh = fopen(filename ,"r");

if(fh)
{
	while(! feof(fh) AND ! DateCheckReturn) //Have we reached end of file OR found our ticker? 
	{
		Line = fgets(fh);
		DateCheckReturn = IIf(StrFind(Line,myTicker), True, False);
		if (DateCheckReturn)
		{
			// display information in DebugView when we find a match
			_TRACE("filename=" + filename); 
			_TRACE("myTicker=" + myTicker+ " / DateCheckReturn=" + DateCheckReturn);
		}
	}
	fclose(fh);
}
return DateCheckReturn;
}

MaxPositions = 20;
SetOption("InitialEquity",50000); 
SetOption("MaxOpenPositions", MaxPositions );

SetPositionSize(GetOption("InitialEquity")/GetOption("MaxOpenPositions"),spsValue);

aDay = Day();
aMonth = Month();
aYear = Year();
for(i=0; i<BarCount; i++)
{
//Set the base for the file name
filename = "C:\\data\\signal_";
//Set the extension for the file
fileext = ".txt";

strDate="";
strDate = StrFormat( "%4.f%02.f%02.f", aYear[i],aMonth[i],aDay[i]); //get the date of the current bar in yyyymmdd format.
filename = filename + strDate + fileext; //Will be something like  c:\data\signal_20100311.txt
Buy[i] = 1 AND DateCheck(Name(),filename);

Sell[i] = 0;
}



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

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

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:
    amibroker-digest@xxxxxxxxxxxxxxx 
    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/