Sub ema5()
Testreport.StartAndInit '開始測評系統的準備工作
Testreport.InitCash=100*10000 '初始資金100萬
Set Formula = marketdata.STKINDI("if00","zj","ema5()",0,5) '調用中金所IF00合約的日線自定義指標
Set HistroyData = Formula.ParentGrid.GetHistoryData '直接得到公式區的數據對象,提高運行效率
If TestReport.AddTestStock(HistroyData,"if00","zj",0) < 1 Then '向測試報告系統添加一個新測試品種
MsgBox "請正確添加品種"
End if
'下面的代碼控制循環測試
'使用PEL策略的信號進行交易
For i = 0 to HistroyData.Count-1
if Formula.GetBufData("開多",i) = 1 And TestReport.Holding = 0 Then '開多
TestReport.Buy 1, HistroyData.Close(i)
End if
if Formula.GetBufData("開空",i) = 1 And TestReport.Holding = 0 Then '開空
TestReport.Sell 1, HistroyData.Close(i)
End if
if Formula.GetBufData("平多",i) = 1 And TestReport.Holding > 0 Then '平多
TestReport.Sell 0, HistroyData.Close(i)
End if
if Formula.GetBufData("平空",i) = 1 And TestReport.Holding > 0 Then '平空
TestReport.Sell 0, HistroyData.Close(i)
End if
'顯示測試時當前的資產
Application.msgout TestReport.ASSET
'為步進下一個數據做準備
TestReport.StepIt i
Next
'測試完畢顯示測試報告
Testreport.ShowReport
End Sub
關于期貨的除權概念,請參考 http://www.weistock.com/bbs/dispbbs.asp?boardid=16&Id=88505 問題43