我真是被策略选股打败了。
5千多只股票,选出3千多只。
我只用了一个自己写的公式A。在选出的标的中运行公式A,根本不会触发选择条件啊。
你们这个策略选股到底有些什么坑。
第一个坑就是要加:Range[0:DataCount-1]
还有些什么坑 ,能不能做一个专题教程啊!
Params
//此处添加参数
Integer skyVolDays(120);//天量统计周期(天)
Numeric volRatio(4);//天量判断系数
Integer restDaysMin(20);//天量后最小的调整交易日数
Integer restDaysMax(120);//天量后最大的调整交易日数
Numeric unnormalRatio(1);//异动判断系数
//Integer skyVolEffectiveDays(120);//天量有效期
Integer unnormalMoveDays(500);//异动距离最新k线的距离
Numeric priceFallFromSkyPriceRatio(0.4);//从最高价下来的跌幅,超过此值后,之前的天量信息无效
Vars
Series<Integer> selectedBar;
Integer j;
Series<Numeric> skyVol(0);
Series<Numeric> skyPrice(0);
Series<Numeric> avgVol(0);
Series<Integer> skyVolBarIndex(-1);
Series<Bool> picked(false);
Series<Numeric> MA5(0);
Defs
//此处添加公式函数
Events
//此处实现事件函数
//初始化事件函数,策略运行期间,首先运行且只有一次
OnInit()
{
AddDataFlag(Enum_Data_RolloverForWard); //设置前复权
}
//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
OnBar(ArrayRef<Integer> indexs)
{
Range[0:DataCount-1]
{
Integer ret = 0;
//去除ST 去除科创板( 68 69 开头)
Bool conToSkipStock = FindFirstOf(Upper(SymbolName),\"ST\")<>InvalidNumeric Or FindFirstOf(Symbol,\"68\")==0 Or FindFirstOf(Symbol,\"69\")==0;
Integer restDays = CurrentBar- skyVolBarIndex;
bool con1 = Vol== Highest(Vol,skyVolDays) And Vol>avgVol[1]*volRatio;
bool con2 = Vol== Highest(Vol,skyVolDays) And restDays < skyVolDays And skyVol[1]<>0 ;
If(!conToSkipStock)
{
avgVol = AverageFC(Vol, skyVolDays);
MA5 = AverageFC(Close,5);
If(con1 Or con2)
{
skyVol=Vol;
skyPrice = IIF(H>skyPrice[1],H,skyPrice[1]);
skyVolBarIndex = CurrentBar;
}
Numeric priceFallRatio = (skyPrice[1]-L)/skyPrice;
If(priceFallRatio>priceFallFromSkyPriceRatio)
{
skyVol=0;//天量失效
skyPrice=0;
skyVolBarIndex=-1;
}
Commentary(\"avgVol*volRatio:\"+Text(avgVol*volRatio/10000));
Commentary(\"skyVol:\"+Text(skyVol/10000));
Commentary(\"skyPrice:\"+Text(Round(skyPrice,2)));
Commentary(\"restDays:\"+Text(restDays));
//Commentary(\"BarCount- CurrentBar:\"+Text(BarCount- CurrentBar));
//Commentary(IIFString(skyVol[1]<>0 ,\"是\",\"否\"));
bool con = restDays> restDaysMin And restDays<restDaysMax ;
con1 = Vol>=unnormalRatio*skyVol[1] And skyVol[1]<>0 ;
con2 = BarCount- CurrentBar<unnormalMoveDays;
Commentary(IIFString(con ,\"是\",\"否\"));
Commentary(IIFString(con1 ,\"是\",\"否\"));
Commentary(IIFString(con2 ,\"是\",\"否\"));
If(con and con1 And con2)
{
PlotString(\"tip\",\"异动\", Low-10);
Commentary(\"异动\");
SetPickCondition();
selectedBar = CurrentBar;
ret = 1;
picked = True;
If(MarketPosition<>1 And Close>MA5)
{
Integer buyNum = RoundDown(100000/Close/100,0)*100;
Buy(buyNum,Close);
}
}
If(MarketPosition==1 And BarsSinceLastEntry>=1 And L<MA5[1])
{
Sell(0,MA5);
}
}
Commentary(\"CurrentBar:\"+Text(CurrentBar));
Commentary(\"selectedBar:\"+Text(selectedBar));
}
}