money = A_CurrentEquity(0) /8 / comno;//按账户权益的八分之一为固定保证金额去开设头寸 myprice = Open;//这里使用open MarginRate mRate; Bool ret = A_GetMarginRate(RelativeSymbol,mRate); lots = IntPart(money/(myprice*contractunit*BigPointValue*mRate)); //计算开仓手数我按照老师提示的改写了一下,结果编译时提示 lots公式左右两边数据类型必须属于numeric类型,不知问题在哪?
回复:你lots 怎么定义的
回复:lots一直是numeric哈
回复:我并没有发现报错
回复:谢谢老师,我再试试的。我把函数文档的内容print出来,会给longmarginratio 和 shortmarginraitio两个数字,在实盘交易中,是不是要根据多空方向不同保证金率分别计算lots手数呢?
回复:VarsNumeric money;//开仓资金 Numeric myprice;//委托价格 Numeric mrate;//保证金率 Numeric lmrate;//多单保证金率 Numeric smrate;//空单保证金率 Numeric lotsl;//多单委托数量 Numeric lotss;//空单委托数量 OnReady() { SetBackBarMaxCount(1+Max(SlowLength,Length)); MarginRate mRate; //获取账户对应合约的保证金率 Bool ret = A_GetMarginRate(relativeSymbol, mRate); lmrate = mRate.longMarginRatio; smrate = mRate.shortMarginRatio; }OnBar(ArrayRef<Integer> indexs) { money = A_CurrentEquity * 0.2;//按总风险度的20% myprice = Open;//这里使用open,更为精确的是使用委托价格 lotsl = IntPart(money/(myprice*contractunit*BigPointValue* lmrate)); //计算开仓手数 lotss = IntPart(money/(myprice*contractunit*BigPointValue* smRate)); //计算开仓手数 }老师我研究出来了,以上就是根据账户实时数据,调用多单、空单的保证金率并计算开仓手数的方式,编译通过了。