公式調(diào)用VBA函數(shù),參數(shù)返回問題 [金字塔]
- 咨詢內(nèi)容:
Function zbDate(Formula,ZB,XH)
'系統(tǒng)會在逐K線模式解釋公式時的每個周期都會調(diào)用此函數(shù)一遍,因此設計時應該注重程序的執(zhí)行效率,不要重復的執(zhí)行一些沒必要的代碼dim resultMa
redim resultMa(2)
'msgbox ubound(resultMa)
resultMa(0)=-2
resultMa(1)=-2
zbDate=resultMa
'sgbox zbdate(1)'if Formula.workmode=0 then '如果是逐漸K模式,直接退出函數(shù)
' exit function
'end if
zbName="MACD"
seriseName="MACD1"
for i=0 to technic.GridCount-1 '循環(huán)獲得指標所在的grid
Set Grid = Technic.GetGridByIndex(i)
for j=0 to Grid.formulaCount-1
set formula1=grid.getformulaByIndex(j)
if formula1.name=zbName then
exit for
end if
next
if j<> Grid.formulaCount then exit for
next
if i=technic.GridCount then '未找到對應的指標
exit function
end ifset history=grid.gethistorydata()
zb1=formula1.vardata(seriseName)
dataCount=UBound(zb1)
redim resultMa(dataCount)for i=formula1.dataSize-1 to 1 step -1
if zb1(i)>0 and zb1(i-1)<=0 then
a1=history.date(i)
a2=year(a1)*10000000000+month(a1)*100000000+day(a1)*1000000+hour(a1)*10000+minute(a1)*100+second(a1)'這里為了返回柱線的日期時間,特把其轉換為數(shù)值(公式只能返回數(shù)值?),在VBA下用宏運行是沒有問題的,但在公式中自定義函數(shù)調(diào)用傳遞回來時在小時、分鐘、秒上出錯,比如2013年9月2日11點30分,傳遞回'來的結果是20130901786624。請問高手們幫忙解決,急急……
msgbox a2
resultMa(i)=a2
EXIT FOR
else
resultMa(i)=-1
end if
nextzbDate=resultMa
End Function - 金字塔客服:
用cdbl試試
- 用戶回復:
金字塔公式的數(shù)值最大是幾位的?似乎數(shù)值超過10位之后,數(shù)值計算就會出錯,如果是,這就是一個很大的bug,希望改進
- 網(wǎng)友回復:
32位的操作系統(tǒng).
2的31次方,值為21 4748 3648
您的日期值已經(jīng)遠遠超過這個值了,所以出現(xiàn)了異常顯示
分成兩個部分傳遞, 年月日 + 時分秒
- 網(wǎng)友回復:
謝謝,但改成這樣還是有錯
Function zbDate(Formula,ZB,XH)
'系統(tǒng)會在逐K線模式解釋公式時的每個周期都會調(diào)用此函數(shù)一遍,因此設計時應該注重程序的執(zhí)行效率,不要重復的執(zhí)行一些沒必要的代碼dim resultMa
redim resultMa(2)
'msgbox ubound(resultMa)
resultMa(0)=-2
resultMa(1)=-2
zbDate=resultMa
'sgbox zbdate(1)'if Formula.workmode=0 then '如果是逐漸K模式,直接退出函數(shù)
' exit function
'end if
zbName="MACD"
seriseName="MACD1"
for i=0 to technic.GridCount-1 '循環(huán)獲得指標所在的grid
Set Grid = Technic.GetGridByIndex(i)
for j=0 to Grid.formulaCount-1
set formula1=grid.getformulaByIndex(j)
if formula1.name=zbName then
exit for
end if
next
if j<> Grid.formulaCount then exit for
next
if i=technic.GridCount then '未找到對應的指標
exit function
end if
cycT=grid.cyctype
'msgbox cycT
set history=grid.gethistorydata()
zb1=formula1.vardata(seriseName)
dataCount=UBound(zb1)
redim resultMa(dataCount)for i=formula1.dataSize-1 to 1 step -1
if zb1(i)>0 and zb1(i-1)<=0 then
a1=history.date(i)
if cycT<=4 or (cycT>=10 and cycT<=14) or (cycT>=17 and cycT<=18) then '由于返回值超過10位后在公式調(diào)用中會出錯,所以這里在日頻度以下只返回時分秒,日頻度以上返回年月日
a2=cdbl(hour(a1))*10000+cdbl(minute(a1))*100+cdbl(second(a1))
else
a2=cdbl(year(a1))*10000+cdbl(month(a1))*100+cdbl(day(a1))
end if
'msgbox a1
resultMa(i)=a2
' EXIT FOR在日線先本來應該返回20130903的,但在公式中顯示出來的是20130904?好多個日子都是這樣,請問是什么原因?你們可以拷貝代碼去測試,謝謝!
else
resultMa(i)=-1
end if
nextzbDate=resultMa
End Function
有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友
可聯(lián)系技術人員 QQ: 1145508240 進行 有償 編寫!(不貴!點擊查看價格!)
相關文章
-
沒有相關內(nèi)容