公式调用VBA函数,参数返回问题 [金字塔]
- 咨询内容:
	
	
 Function zbDate(Formula,ZB,XH)
 '系统会在逐K线模式解释公式时的每个周期都会调用此函数一遍,因此设计时应该注重程序的执行效率,不要重复的执行一些没必要的代码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模式,直接退出函数 
 ' exit function
 'end if
 
 zbName="MACD"
 seriseName="MACD1"
 for i=0 to technic.GridCount-1 '循环获得指标所在的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)'这里为了返回柱线的日期时间,特把其转换为数值(公式只能返回数值?),在VBA下用宏运行是没有问题的,但在公式中自定义函数调用传递回来时在小时、分钟、秒上出错,比如2013年9月2日11点30分,传递回'来的结果是20130901786624。请问高手们帮忙解决,急急…… 
 msgbox a2
 resultMa(i)=a2
 EXIT FOR
 else
 resultMa(i)=-1
 end if
 nextzbDate=resultMa 
 End Function
-  金字塔客服:
	
	用cdbl试试
	
-  用户回复:
	
	金字塔公式的数值最大是几位的?似乎数值超过10位之后,数值计算就会出错,如果是,这就是一个很大的bug,希望改进 
-  网友回复:
	
	32位的操作系统. 2的31次方,值为21 4748 3648 您的日期值已经远远超过这个值了,所以出现了异常显示 分成两个部分传递, 年月日 + 时分秒 
-  网友回复:
	
	谢谢,但改成这样还是有错 Function zbDate(Formula,ZB,XH) 
 '系统会在逐K线模式解释公式时的每个周期都会调用此函数一遍,因此设计时应该注重程序的执行效率,不要重复的执行一些没必要的代码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模式,直接退出函数 
 ' exit function
 'end if
 
 zbName="MACD"
 seriseName="MACD1"
 for i=0 to technic.GridCount-1 '循环获得指标所在的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位后在公式调用中会出错,所以这里在日频度以下只返回时分秒,日频度以上返回年月日
 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
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 1145508240  进行 有偿 编写!(不贵!点击查看价格!)
                        
相关文章
- 
                        没有相关内容
                       

 
                     会员登录/注册
会员登录/注册