If nHold<>0 Then
iZhibiaoCCNew = nHold
ElseIf sCode<>"" and sMarket<>"" and isNumeric(iPeriod) and nHold=0 Then
Set Formula = marketdata.STKINDI(sCode,sMarket,sPolicy,0,iPeriod) '取策略
iZhibiaoCCNew=Formula.GetBufData(sHoldingZhibiao,Formula.DataSize-1) '取指标的返回值
iEnterPrice=Formula.GetBufData(sEnterPriceZhibiao,Formula.DataSize-1) '取的返回值
iExitPrice=Formula.GetBufData(sExitPriceZhibiao,Formula.DataSize-1) '取指标的返回值
sLogLine = "sCode=" & sCode & ",sMarket=" & sMarket & ",sPolicy=" & sPolicy & ",iPeriod=" & iPeriod
logFs.writeLine(sLogLine)
sLogLine = "time=" & Now & ",iZhibiaoCCNew=" &iZhibiaoCCNew& ",iEnterPrice=" &iEnterPrice& ",iExitPrice=" & iExitPrice
logFs.writeLine(sLogLine)
Else
WriteLog "存在参数不符合条件的情况,请检查。code=[" & sCode & "],market=[: [" & sMarket & "],period=[" & iPeriod & "]."
Exit For
End If
上面就是调用formula的代码,这段代码是放在一个函数中的。。
Sub Application_Timer(ID)
'数据导出导入部分删掉
If ID=2 Then
'将行情信息输出到文件中,方便监控程序监控是否一直在刷新行情
getOutInfo
'iRunStatus的赋值由界面进行控制
If iRunStatus=1 Then
DebugLog("=====Start====")
Call Application.KillTimer(2)
'读取第一个tick,当第一个tick处于9:00-15:00,21:00-23:59的时候,修改市场的启动状态。当有一个市场启动的时候,就执行策略检查;在策略检查的时候,处理交易的状态,还有市场的启动标记
nRet = CheckMarketFlag()
if nRet=1 then
ReadPubPara '读入公共参数
tYcTime=gettime(sYcTime)
If tYcTime=true Then '移仓判断
'在移仓时间段内,首先判断是否已经移仓判断过。如果没有判断过,则循环账户持仓列表,只要不是主力合约的,则直接用市价移仓。
DoYc
Else
bYcRun=0
End If 'tYcTime=true
If CDate(time) >CDate("14:50:00") and CDate(time)<CDate("15:00:00") Then
'快收盘的时候,再次判断下移仓到预先判断的主力合约品种的成交量
CheckMainCode
End If
'如果到了日内平仓时间且日内点了勾,则进行平仓判断
If CDate(time)>CDate(sPingTimeSP) and CDate(time)<=CDate("15:00:00") Then
'商品日内平仓
If Instr(sPingMarket,"SQ,ZQ,DQ")=0 Then
sPingMarket = sPingMarket&"SQ,ZQ,DQ"
End If
RiNeiPingCang "SQ,ZQ,DQ"
End If
If CDate(time)>CDate(sPingTimeZJ) and CDate(time)<=CDate("15:15:00") Then
'股指日内平仓
If Instr(sPingMarket,"ZJ")=0 Then
sPingMarket = sPingMarket&"ZJ"
End If
RiNeiPingCang "ZJ"
End If
'检查策略是否发单
CheckPolicy
'待移仓结束后
'If bYcRun=0 and bReleaseRun=0 Then
' '循环发单列表,对能够发单的进行发单
' SendOrder
'End If
'判断账户是否存在锁仓,有的话需要用对手价进行解锁
If nJieSuo=1 Then
ReleaseCapital
End If
'If sCSGZ="1" or sCSSP="1" or sCJGZ="1" or sCJSP="1" Then
' CancelAndReOrder '撤单逻辑
'End If
ShouPanClear
end if
Call Application.SetTimer(2,1000) '交易计时器
DebugLog("=====End====")
End If
End If
End Sub
这段代码就是定时器的调用。。其中CheckPolicy 这个函数中就调用了formula。
我只能贴到这个程度了,代码量太大,而且不方便完全放出来。。