This should be a simple question but seems complicated for me. I would like to get closing price of my watchlist as of a particular date and 1 week and 3/6 months ago.
Below is my code using lookup to get the price of particular. My logic is get the relevant dates and lookup the price of the relevant dates. My Amibroker is 6.40. Have I missed any critical functions? Would anyone give me some direction or guidance.
type o//Get price of particular date and weeks and months before the particular date
//Calculate the price changes of those period
//Set the relevant Dates, 1 Week; 3 Months and 6 Months from the Input Daate
InputDate = "10-03-2022";
Date1wBack = DateTimeAdd (_DT(InputDate), -1, inWeekly);
Date3mBack = DateTimeAdd (_DT(InputDate), -3, inMonthly);
Date6mBack = DateTimeAdd (_DT(InputDate), -6, inMonthly);
//Lookup Price of the Particular Dates. If no price for a particular date, take price of the nearest predecesor
PriceInputDate = Lookup(C, _DT(InputDate), -1);
Price1wBack = Lookup (C, (Date1wBack), -1);
Price3mBack = Lookup (C, (Date3mBack), -1);
Price6mBack = Lookup (C, (Date6mBack), -1);
//Explore the information
AddTextColumn (Name(), "Ticker", 1);
AddTextColumn (DateTimeFormat("%d/%m/%y", _DT(InputDate)), "Date");
AddColumn (PriceInputDate, "Close Price");
AddTextColumn (DateTimeFormat("%d/%m/%y", Date1wBack), "1 Week");
AddColumn (Price1wBack, "Close Price");
AddTextColumn (DateTimeFormat("%d/%m/%y", Date3mBack), "3 months");
AddColumn (Price3mBack, "Close Price");
AddTextColumn (DateTimeFormat("%d/%m/%y", Date6mBack), "6 months");
AddColumn (Price6mBack, "Close Price");
r paste code here
In the Filter, I select the my WatchList or S&P 100 and from Dates Range 1 Jan 2021 to 14 Mar 2022. No results from running Explore or Scan. Even I changed the InputDate to 1 Mar 2022, it also shows no result. There must something wrong with the concept of date in the form of String or Numeric, which I do not understand. There is no error in the codes. Any indication of my errors?
I have not included Filter in AFL Editor just for the flexible to apply it all various Watchlists respectively, To run Exploration, I have select Watchlist Filter, such as S&P500, but still has no result. Do I need to apply any other setting before I run the Exploration?
Thanks Henri. Your suggested coding is the most popular one. The Lookup mode -1 is to get the nearest predecesor, which will handle the problem of trading holidays.
I have verified the codes. No error shown. That makes me wonder what's wrong with my codes or steps on running Exploration.
Dates are always complicated in all kind of programming. But I didn't find any useful resources in the Guide or Knowledge Base.
I don't understand why (some) newbies have to start discussion and question everything that has been advised by documentation (by original developer) or experienced AB users?
Filter setting of Analysis "Apply to:" is not equal to AFL Filter variable!
Once again to get Exploration result list you have to add Filter line to your exploration code.
@fxshrat@bepe Thanks for your help. It clarified my issues. I am not aware the difference of Filter in ALF Editor and the Analysis Filter settings. As a Newbie, Filter is Filter, not sure it makes such differences AFL. That is the different between the Newbie and experienced users. Thanks again.