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

问题描述 投票:0回答:2

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

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

trading algorithmic-trading amibroker
2个回答
1
投票

我想你正在考虑过去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);
}

-1
投票

您可以计算过去20天内价格从前一天降至-1.5%以下的次数:

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

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

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

第二种解决方案不会在实际交易中起作用,因为,我相信,你知道。

© www.soinside.com 2019 - 2024. All rights reserved.