老师好!
麻烦老师看一下, MapContain 函数在有的代码中正常,有的代码中不起作用,是什么原因?
能正常运行的代码:
Params
Numeric Length(5);
Numeric Length1(10);
Numeric Length2(20);
Vars
String my_tb("tbf_wd118552");
series<Numeric> Ma1;
series<Numeric> Ma2;
series<Numeric> Ma3;
//Array<String> SubSymbols;
//array<Integer> indexsid;
//Integer i;
//Global Integer id(0);
Global Integer a;
//Global Integer unof;
//String b;
Global map<String,Integer> ret;
Global map<String,Integer> ccmap;
Global map<String,String> pdmap;
//array<Numeric> testa;
//Array<Integer> ids;
Integer accountIndex;
Events
//此处实现事件函数
//初始化事件函数,策略运行期间,首先运行且只有一次,应用在订阅数据等操作
OnInit()
{
A_BindTradeAccount(my_tb);
A_SubscribeTradeByCreateId(Enum_Trade_Source_ALL);
SubscribeBar("a2301.DCE","1d",20220201,0);
SubscribeBar("bu2306.SHFE","1d",20220201,0);
SubscribeBar("ag2302.SHFE","1d",20220201,0);
SubscribeBar("AP301.CZCE","1d",20220201,0);
SubscribeBar("al2301.SHFE","1d",20220201,0);
SubscribeBar("rb2301.SHFE","1d",20220201,0);
SubscribeBar("a2301.DCE","1m",20221101,0);
SubscribeBar("bu2306.SHFE","1m",20221101,0);
SubscribeBar("ag2302.SHFE","1m",20221101,0);
SubscribeBar("AP301.CZCE","1m",20221101,0);
SubscribeBar("al2301.SHFE","1m",20221101,0);
SubscribeBar("rb2301.SHFE","1m",20221101,0);
}
OnReady()
{
}
OnBar(ArrayRef<Integer> indexs)
{
range[ a=0 : DataSourceSize()/2-1]
{
ma1=Average((open+close+high+low)/4,Length);
ma2=Average((open+close+high+low)/4,Length1);
ma3=Average((open+close+high+low)/4,Length2);
PlotNumeric("ma1",ma1);
PlotNumeric("ma2",ma2);
PlotNumeric("ma3",ma3);
if (BarStatus==2)
{
if (close>open)
{
pdmap[symbol]="up";
}
if (close<open)
{
pdmap[symbol]="down";
}
}
}
Range [a=DataSourceSize()/2 : DataSourceSize()-1]
{
ma1=Average((open+close+high+low)/4,Length);
ma2=Average((open+close+high+low)/4,Length1);
ma3=Average((open+close+high+low)/4,Length2);
PlotNumeric("ma1",ma1);
PlotNumeric("ma2",ma2);
PlotNumeric("ma3",ma3);
if (BarStatus==2)
{
if (MapContain(pdmap,symbol)) //////////////////////
{ // MapContain 函数正常
print("in="+symbol); //
} //////////////////////
}
}
}
if (MapContain(pdmap,symbol)) 你这个只能是说明返回了false 不能说明MapContain有什么问题。
false了说明你可能数据都没存进去
另外还尝试了其它方法,Arrayfind 函数也不行,用for循环编译不了,提示错误为:无法识别的字符串:OnOrder(OrderRef ord)
你是怎么确定MapContain他有效或者无效的
如下,一个输出,另一个不输出,
if (MapContain(pdmap,symbol))
{
print("in="+symbol); // MapContain 函数不起作用
mapkeypd=True;
}