计算符号在未来 6 个月内在 Amibroker AFL 中下跌 X% 的次数

Count number of times symbol dropped X% in next 6 months in Amibroker AFL

我正在使用 Amibroker ver6.20.1。我想使用 AFL 代码计算股票价格在接下来的 6 个月中从某一天下跌 X% 的次数。这将需要使用 Ref() 来引用未来的值。

https://www.amibroker.com/guide/afl/ref.html

我想您正在查看过去 6 个月的收盘价,因为没有可以提供未来价格数据的图表软件。以下是我对下面的 AFL 代码所做的假设。 1. 收盘价后 6 个月或 26 周 X5 天/周 = 130 天 2.比较每日收盘价的X% 3.股价下跌即昨日收盘价>今日收盘价

// 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);
}

您可以回顾过去 20 天内价格从前一天跌至 -1.5% 以下的次数:

N = Sum(ROC(C,1) < -1.5, 20);

您还可以将其转换为未来 20 天内的未来实例,如下所示:

N = Ref(Sum(ROC(C,1) < -1.5, 20), 20);

第二个解决方案在真实交易中不起作用,我敢肯定,你知道的。