I am using Amibroker ver6.20.1. I would like to count the number of times a stock price dropped X% from a certain day in the next 6 months using AFL code. This will require using Ref() to reference future values.
I suppose you are looking at the Close price for the past 6 months as there is no charting software that can give future price figures. Here are the assumptions that I make for the AFL code below. 1. 6 months past Close price or 26weeksX5days/week = 130days 2. Compare X% of daily close price 3. Stock price dropped i.e. yesterday's Close price > today's Close price
// BarCount is the number of element in Close array.
// Array element start from 0 to BarCount - 1.
// Create Close_price[i] array because Amibroker does not allow Close[i] in an If statement.
// X% is set to 15%.
// Run this AFL in Exploration and select Apply To : All Symbols, From to Date : Current date of your database
Close_price=Close;
Filter = 0;
x=0.05;
j=0;
if (BarCount >= 130) { /* Scan those stocks with at least 6 months data. */
for (i = BarCount - 130; i<BarCount-1; i++){
if (Close_price[i] > Close_price[i+1] and (1-Close_price[i+1]/Close_price[i])>0.15){
Filter = 1;
j++;
}
}
AddColumn(j,"# of time drop more than 5%",1.0);
}