老师好!还得麻烦老师帮着纠错。A_SendOrder函数发送失败。
Vars
//此处添加变量
String my_tb("tbf_wd118552");
Integer accountIndex;
Integer LastIndex;
Integer nCount;
//Integer InvalidInteger();
Numeric a;
Numeric b;
Numeric c;
Global Numeric k;
bool m;
Defs
//此处添加公式函数
Events
//此处实现事件函数
//初始化事件函数,策略运行期间,首先运行且只有一次
OnInit()
{
A_BindTradeAccount(my_tb);
}
//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
OnBar(ArrayRef<Integer> indexs)
{
if ( BarStatus() == 2 and close>open )
{
if (k==0 )
{
a=IntPart((A_FreeMargin(accountIndex = 0)*0.32)/((close+MinMove()*5)*MarginRatio()*ContractUnit()));
b=Q_AskPrice()-MinMove()*5;
print("委托价格:"+text(b));
m=A_SendOrder(Enum_Buy,Enum_Entry,a,b);
print("发单"+IIFString(m,"成功","失败"));
LastIndex = A_GetLastOpenOrderIndex(Enum_Buy,Enum_Entry);
print("索引:"+text(LastIndex));
print("手数:"+text(a));
print("开仓资金:"+text(A_FreeMargin(accountIndex = 0)*0.32));
print("可用资金:"+text(A_FreeMargin(accountIndex = 0)));
print("未成交数:"+text(A_GetOpenOrderCount()));
print("对手价:"+text(Q_AskPrice()));
print("BAR状态:"+text(barstatus()));
if (A_AccountDataExist(A_AccountIndex(A_AccountID())) == True)
{
print("账户有效");
}
k=1;
}
}
}
运行结果如下图:
你没打开自动交易啊
注意公式运行和打开自动交易的顺序
建议用策略单元来运行,不要用k线,否则不容易控制顺序
多谢老师!