下面这段代码,附加到tbq3的1小时周期不能输出到自选
Params
String SectorName("MA排列60m"); // 目标板块名(一级板块_二级板块)
Numeric MALen1(5);
Numeric MALen2(10);
Numeric MALen3(20);
Numeric MALen4(60);
Vars
Map<String, String> mySyms;
String tmpSymsBull; // 收集多头排列合约
String tmpSymsBear; // 收集空头排列合约
Numeric i;
Events
OnBar(ArrayRef<Integer> indexs)
{
// 每根 Bar 先清空暂存
tmpSymsBull = "";
tmpSymsBear = "";
Numeric ma5 = AverageFC(Close, MALen1);
Numeric ma10 = AverageFC(Close, MALen2);
Numeric ma20 = AverageFC(Close, MALen3);
Numeric ma60 = AverageFC(Close, MALen4);
Bool isBull = (ma5 > ma10) && (ma10 > ma20) && (ma20 > ma60);
Bool isBear = (ma5 < ma10) && (ma10 < ma20) && (ma20 < ma60);
If(BarStatus == 2 && isBull)
{
tmpSymsBull = tmpSymsBull + Symbol + ",";
}
If(BarStatus == 2 && isBear)
{
tmpSymsBear = tmpSymsBear + Symbol + ",";
}
// 只在最后一根 Bar 推送一次
If(BarStatus == 2)
{
// 推送多头排列合约
If(tmpSymsBull != "")
{
mySyms["合约集合"] = tmpSymsBull;
mySyms["板块名称"] = SectorName + "多头";
mySyms["添加方式"] = "append"; // 每次覆盖,保证板块是最新状态
PublishEvent("系统-选股事件", mySyms, "行情报价");
}
// 推送空头排列合约
If(tmpSymsBear != "")
{
mySyms["合约集合"] = tmpSymsBear;
mySyms["板块名称"] = SectorName + "空头";
mySyms["添加方式"] = "append";
PublishEvent("系统-选股事件", mySyms, "行情报价");
}
}
}
