I would like to test for the presence of certain seasonal patterns in stock data. For example are Tuesdays up days? I tried the following, which is meant to simple count up Tuesdays, but it clearly doesn't work. Any trailheads or code examples around?
@BBands I thought you may have had a different intention. And depending on what you are looking to do with that data, I thought to mention the SUM function ( Calculates a cumulative sum of the ARRAY for the specified number of lookback periods (including today)) .
An example of gathering data on a Watch List for 2500 daily bars (~ 10 years) instead of using the CUM function (Calculates a cumulative sum of the ARRAY from the first period in the chart).
///@link https://forum.amibroker.com/t/finding-seasonal-pattterns/12940
upday = ROC( Close, 1 ) > 0;
dw = DayOfWeek();
tuesday = Cum( dw == 2 AND upday ); // TJ original calculation
TuesdayUp = dw == 2 AND upday; // identify an Up Tuesday
// lets look at about 10 years of daily bars
Periods = Param("Periods", 2500, 1, 10000, 1); // Adjustable look back period
totTuesUp = Sum(TuesdayUp, Periods);
// on a WL with different listing dates and data lengths
NumberOfTuesdays = Sum(dw == 2 AND C !=0, Periods);
pctTuesUp = (totTuesUp/NumberOfTuesdays)*100;
Filter = Status("lastbarinrange");
AddtextColumn(FullName(), "Company");
AddColumn(tuesday, "original Calculation", 1.2, colorDefault, colorRose);
AddColumn(totTuesUp, "# Tuesdays Up", 1.0);
AddColumn(pctTuesUp, "% Tuesday Up", 1.2, colorDefault, colorLightYellow);
AddColumn(NumberOfTuesdays, "# of Tuesdays", 1.0);