发送工作区的代吗
Params
//此处添加参数
Numeric boLength2(0.20551);//时间 。
//Numeric boLength3(10);
Integer millsec(1000); //定时器触发时间
Vars
//此处添加变量
Global Integer timeID1; //定时器ID
Global Map<String,String>a ;
Series<Numeric> y;
Defs
Events
//初始化事件函数,策略运行期间,首先运行且只有一次,应用在订阅数据等操作
OnInit()
{
timeID1 = CreateTimer(millsec);
a["期货代码"] ="";
}
OnTimer(Integer id,Integer millsecs)
{
//可以通过id判断是哪个定时器触发的定时时间
if(id == timeID1)
{
y = currenttime();
if ( y>=0.09001 and y<=boLength2)
{
a["期货代码"] = ",zn888.SHFE,zn888.SHFE,cu888.SHFE,j9888.DCE,SM888.CZCE";
PublishEvent("我的选合约多",a,"所有订阅者");
if(Day<>Day[1])
{
a["期货代码"] = "";
}
}
}
}
接收信息的代码
Params
//此处添加参数
Vars
//此处添加变量
Global Numeric i;
Global String a;
Global Array<String> x2;
Events
//此处实现事件函数
//初始化事件函数,策略运行期间,首先运行且只有一次,应用在订阅数据等操作
OnInit()
{
UnsubscribeBar(0);
SubscribeEvent("我的选合约多");
if (a != "")
{
StringSplit (a,",",x2);
for i=1 to GetArraySize(x2)-1
{
SubscribeBar(x2[i],"10s",DateTimeAdd(SystemDateTime,-1000*60)) ;
A_BindTradeAccount("lj001");
}
}
}
OnEvent(StringRef evtName,MapRef<String,String> evtValue)
{
if (evtName=="我的选合约空")
Print("代码="+evtValue["期货代码"]);
a = evtValue["期货代码"] ;
ReStart(False);
}
运行以上代码后 定约的合约数据 显示出来的图层 不是很稳定 有时候正常显示 5个图层 运行程序 时间长了就会显示一个图层 有时候一个土层也不能显示 这是为什么呢。
只显示一个图层
程序中定约的是5个
一个图层的时候确定一下到底订阅了几个