Set Formula = marketdata.STKINDI(codeid, marketid, pelfunction,0,0)
ma1 = formula.getbufdata("ma1", formula.datasize-1)
ma2 = formula.getbufdata("ma2", formula.datasize-1)
ma3 = formula.getbufdata("ma3", formula.datasize-1)
call order.HoldingInfoByCode2(codeid,marketid,buyhoding,buycost,buytodayhoding,sellhoding,sellcost,selltodayhoding,PNL,UseMargin)
dim pendingcount
pendingcount = order.OrderNum2
application.MsgOut pendingcount
if pendingcount = 0 then '后台没有委托单子时才下单
if ma1>ma2 and ma1>ma3 and buyhoding=0 and sellhoding = 0 then '做多
for i = 1 to tradetime
call order.Buy(0,10,reportdata.newprice,0,codeid, marketid,"",0)
next
call order.Buy(0,onevol-tradetime*10,reportdata.newprice,0,codeid, marketid,"",0)
end if
if ma1<ma2 and ma1<ma3 and buyhoding=0 and sellhoding = 0 then '做空
for i = 1 to tradetime
call order.BuyShort(0,10,reportdata.newprice,0,codeid, marketid,"",0)
next
call order.buyshort(0,onevol-tradetime*10,reportdata.newprice,0,codeid, marketid,"",0)
end if
if ma1>ma2 and sellhoding>0 then '平空
for i = 1 to tradetime
call order.sellshort(0,10,reportdata.newprice,0,codeid, marketid,"",0)
next
call order.sellshort(0,onevol-tradetime*10,reportdata.newprice,0,codeid, marketid,"",0)
end if
if ma1<ma2 and buyhoding>0 then '平多
for i = 1 to tradetime
call order.sell(0,10,reportdata.newprice,0,codeid, marketid,"",0)
next
call order.sell(0,onevol-tradetime*10,reportdata.newprice,0,codeid, marketid,"",0)
end if
end if