MQ编写 (文华财经wh9)

投资者咨询:MQ编写 (文华财经wh9)
来源:文华财经  日期:2018-6-25 9:59
 为什么我放在MQ软件里和TB软件里都不交易呢 

Params
   Numeric m(10);//计算是否达到N波动跳数净值的TICK数
   Numeric n(10);//M个TICK内,波动的跳数
   Numeric loss(10);//开仓LOSS秒后,仍处浮亏,离场条件之一
   Numeric offset(1);//开仓滑点
   Numeric lots(1);//开仓手数
   Numeric closetime(1459);//收盘前平仓时间
  
Vars
Numeric minpoint;//每跳价值
Numeric i;//循环语句起止值
Numeric trendm;//1,多头趋势;0,无趋势;-1,空头趋势
Numeric tickhigh;//M个TICK内的高点
Numeric ticklow;//M个TICK内的低点
Numeric currentsec;//当前秒数值
Numeric opensec;//开仓秒数值
Begin
minpoint=MinMove*PriceScale;
currentsec=Value(left(timetostring(currenttime),2))*3600;
currentsec=currentsec+Value(mid(timetostring(currenttime),3,2))*60;
currentsec=currentsec+Value(Right(timetostring(currenttime),2));
opensec=GetGlobalVar(0);
trendm=GetGlobalVar(49);
if(BarStatus==0 or (currentsec==InvalidNumeric or trendm==InvalidNumeric))
{
opensec=0;
trendm=0;
SetGlobalVar(0,opensec);
SetGlobalVar(49,trendm);
}
if(BarStatus==2)
{
for i=1 to m
{
if(i<m)SetGlobalVar(i,GetGlobalVar(i+1));
else SetGlobalVar(m,close);
if(i==1)
{
tickhigh=GetGlobalVar(i);
ticklow=tickhigh;
}Else
{
if(tickhigh<GetGlobalVar(i))tickhigh=GetGlobalVar(i);
if(ticklow>GetGlobalVar(i))ticklow=GetGlobalVar(i);
}   
}
if(close-ticklow>=n*minpoint)trendm=1;
if(tickhigh-close>=n*minpoint)trendm=-1;
if(trendm==1 and time<closetime)
{
if(A_SellPosition>0)A_SendOrder(enum_buy,Enum_Exit,A_SellPosition,Q_AskPrice+offset*minpoint);
if(A_BuyPosition==0){A_SendOrder(enum_buy,Enum_Entry,lots,Q_AskPrice+offset*minpoint);
opensec=currentsec;
}
}
if(trendm==-1 and time<closetime)
{
if(A_BuyPosition>0)A_SendOrder(Enum_Sell,Enum_Exit,A_BuyPosition,Q_BidPrice-offset*minpoint);
if(A_SellPosition==0){A_SendOrder(Enum_Sell,Enum_Entry,lots,Q_BidPrice-offset*minpoint);
opensec=currentsec;
}
}
if(currentsec-opensec>loss and A_BuyProfitLoss<0)A_SendOrder(Enum_Sell,Enum_Exit,A_BuyPosition,Q_BidPrice-offset*minpoint);
if(currentsec-opensec>loss and A_SellProfitLoss<0)A_SendOrder(enum_buy,Enum_Exit,A_SellPosition,Q_AskPrice+offset*minpoint);
}
if(time>=closetime)
{
if(A_SellPosition>0)A_SendOrder(enum_buy,Enum_Exit,A_SellPosition,Q_AskPrice+offset*minpoint);
if(A_BuyPosition>0)A_SendOrder(Enum_Sell,Enum_Exit,A_BuyPosition,Q_BidPrice-offset*minpoint);
}

Commentary("A_SellPosition:"+text(A_SellPosition));
Commentary("A_BuyPosition:"+text(A_BuyPosition));
SetGlobalVar(0,opensec);
SetGlobalVar(49,trendm);
Commentary("trendm:"+text(trendm));
End
 
技术人员回复
日期:2018-6-25 10:21
 您代码中有SetGlobalVar 等设置全局变量的编写内容,不支持回测的,您可以保存K线图公式,模组实盘运行看下

另外代码中有判断空值 的内容,不能用==InvalidNumeric 判断的,需要用IsNull判断的,您了解下

 (IsNull( currentsec) or IsNull( trendm))

投资者咨询:MQ编写 (文华财经wh9)
来源:文华财经  日期:2018-6-25 9:59
可以帮我改成可以回测的吗 
技术人员回复
日期:2018-6-25 13:23
 不能的,模型全局变量和算法下单,不能改成回测模型的

您可以重新量化下您的思路,给您直接编制下