虽然,觉得你这种用法没什么必要,但是,你提出的这个问题,很好,就是,自定义函数的参数,能不能是Grid对象?
你有没有打开作为参数传递的这个GRID呢?
可否将代码贴出来,我们帮你仔细看看
请加我QQ442902994, 然后将框架也拷贝给我,否则我这里无法复现你的机器运行状态
初步运行了你的例子,然后发现你的死机情况主要是你的LOOP循环的位置会出现死循环导致,因为你的循环的唯一终止点是一个DataCount变量,但是很不明确,这种代码编写极易导致因为DataCount计算不当导致死循环无法推出,导致金字塔停止相应,我在你的循环地方加了MAXLOOP循环判断,就是到了10000次就强行终止退出,但治标不治本,这个地方还得靠你自己去完善改写
Sub kp_Paint()
set Grid=kp.GetGridByName("Win30")
Set History =Grid.GetHistoryData()
DataCount = 0
rTime=0
lTime=0
i=history.Count-4
spaceNumber=Grid.ShowLastCyc
CS=0
MaxLoop = 0
do
boolH=history.high(i)>history.high(i-1) and history.high(i)>=history.high(i-2) and history.high(i)>=history.high(i-3) _
and history.high(i)>=history.high(i+1) and history.high(i)>=history.high(i+2) and history.high(i)>=history.high(i+3)
' boolL=history.Low(i)<history.Low(i-1) and history.Low(i)<=history.Low(i-2) and history.Low(i)<=history.Low(i-3) _
' and history.Low(i)<=history.Low(i+1) and history.Low(i)<=history.Low(i+2) and history.Low(i)<=history.Low(i+3)
if boolH then
DataCount=DataCount+1
if DataCount=1 then
RTime=i
end if
if DataCount=2 then
LTime=i
exit do
end if
end if
i=i-1
MaxLoop = MaxLoop + 1
if MaxLoop > 10000 then
exit do
end if
loop
hLeftPrice=history.high(LTime)
hRightPrice=history.high(RTime)
xhLeft=Grid.PelsByPos(LTime,false)
xhRight=Grid.PelsByPos(RTime,false)
yhLeft=Grid.PriceToPels(hLeftPrice)
yhRight=Grid.PriceToPels(hRightPrice)
xhLastPos=Grid.PelsByPos(history.Count+spaceNumber,false)
'小心除零错误
if Rtime-Ltime <= 0 then
exit sub
end if
CS1=FormatNumber(CDbl((hleftPrice-hRightPrice)/(Rtime-Ltime)),2)
CS=(yhleft-yhright)/(xhRight-xhLeft)
ZhuLi=HLeftPrice-CS1*(History.Count-Ltime-1)
Grid.drawtext 0,20,"阻力值:"+Cstr(Zhuli),rgb(0,255,0)
yhLastPos=yhRight+(xhright-xhLastPos)*CS
Grid.drawline xhleft,yhleft,xhLastPos,yhlastPos,rgb(255,0,0),3
End Sub