Hello friends,
I am Anant. I am posting in this forum for the first time. Most of my posts are in Karthik Marar's threads "Experiments in Technical Analysis" and "System Implementation Excercise". For long time I have not posted in Traderji though I am regularly going through the messages in the forum.
I had asked Uma to post the updater AFL. But Uma insisted that I should do it and explain the AFL and its usage. So, Iam doing it now. The AFL is attached with this message as 'updater.txt'. You can download it into your Ami Broker Folder under Formulas-Custom folder and rename it to 'updater.afl'. The AFL itself is very simple and short.
Coming to the working of the AFL, I will explain it line by line. Experts can directly start using it as they will understand the functioning of the AFL.
Take the first two lines of the AFL:
Code:
[COLOR="Blue"]BuyDate = ParamDate("Buy Date", "28-05-2009");
Dt = DateNum();[/COLOR]
The first line is for selecting the Date on which the stocks were purchased. The default date is 28-05-2009 as this was the date from which Uma is tracking the stock list. You can select any date you want. I will explain later how to select the date when describe how to use the AFL later. The second line is just to get the dates of the quotes in your database and convert them to a number. Ami Broker converts dates to number as follows:
Date Number = (Year - 1900) * 10000 + (Month number) * 100 + Date.
Therefore 28-05-2009 becomes 109 * 10000 + 5 * 100 + 28 = 1090528.
Now take the next 8 lines:
Code:
[COLOR="blue"]BarNum = 0;
for(i = BarCount - 1; i > 0; i--)
{
if(Dt[i] == BuyDate)
{
BarNum = i;
break;
}
}[/COLOR]
This portion finds out where in the databse is the data pertaining to the buying date. For this what it does is start counting from the latest data point and count backwards. For each data point it examines the date of that point and compares with the selected buying date (selected in line 1 above). If the dates match it takes that point and stops counting and goes to next part of the code. Ami broker stores the data for each stock for each day as a bar and its position in database is referred to as BarIndex. The bar numbers start with zero for the oldest data point and continue further towards the latest by increasing the number by 1 for each subsequent bar. Total number of data points available for a stock is called the BarCount.
Now the next portion of the code:
Code:
[COLOR="blue"]BuyingPrice = IIf(H[BarNum - 1] > H[BarNum], H[BarNum], IIf(H[BarNum - 1] < L[BarNum], L[BarNum], H[BarNum - 1]));
PL = C - BuyingPrice;[/COLOR]
Here we are determining the buying price for the stock. As we have located the data point for the date of purchase and saved the position as BarNum, we now use the data for this BarNum to determine the price. As Savantji has explained the buying price is the previuos day's high. Therefore the program selects the high of previous day (the day before buying) as the buying price. But if on the actual day of buying the High is lower than the previous day's high then it selcts High of buying day as purchase price. If the low of buying day is higher than previous day's High then the low of buying day is taken as purchase price.
Using this purchase price the program determines the Profit/loss by subtracting the purchase price from the day's close. This is stored as PL
Now the remainder of the program code simply prepares the report:
Code:
[COLOR="blue"]Filter = 1;
SetOption("NoDefaultColumns", True);
AddColumn(DateTime(), "Date", formatDateTime, colorDefault, colorDefault, 120);
AddTextColumn(Name(), "Symbol", 12, colorDefault, colorDefault, 120 );
AddColumn(BuyingPrice, "Buy Price", 6.2);
AddColumn(C, "Today's Close", 6.2);
AddColumn(PL, "P / L per share", 6.2, IIf(PL < 0, colorRed, IIf(PL > 0, colorGreen, colorDefault)), colorDefault, 72);
AddColumn(PL * 100 / BuyingPrice, "P / L %", 6.2, IIf(PL < 0, colorRed, IIf(PL > 0, colorGreen, colorDefault)), colorDefault, 72);[/COLOR]
The statement
Filter = 1 defines the criterion based on which the report should be prepared. Filter = 1 selects all stocks.
the '
SetOption' statement declares that there are no default columns in the report and only the column defined in the program are reported.
The remaining '
AddColumn' statements define the column we want to see in the report, the order in which the columns are presented and the format of the column contents.
That's all about the logic of the AFL and its working internals.
The instructions for its usage are in the next post.
Regards
-Anant