您好,我的策略是日内交易,之前回测开仓是用的固定手数,现在打算根据账号头寸进行计算开仓手数,但出现了头寸为负数的告警,请教一下是什么原因呢?
涉及的仓位计算代码如下:
Params
Numeric RiskRatio(0.9);//资金使用比例
Vars
Numeric MyEntryPrice;
Numeric TotalEquity;
Numeric Lots;
Numeric Lots1;
Events
OnBar(ArrayRef<Integer> indexs)
{
TotalEquity = A_FreeMargin;
Lots = (TotalEquity*RiskRatio/MarginRatio) /(Q_Open*ContractUnit()*BigPointValue());
Lots1 = IntPart(Lots); // 对小数取整得出当日全仓交易单位
//开仓代码:
If(Open>Close[1])
{ MyEntryPrice=Open;
Buy(Lots1,MyEntryPrice);
}
}
告警信息:提示交易量居然出现负数,导致申报失败。

图表系统不要拿A函数做
A_FreeMargin Q_Open
那请问图标系统用对应的什么函数替代合适?
用Portfolio_CurrentCapital 代替 A_FreeMargin,用open 代替Q_Open 可以吗?