金字塔VBA判斷三角形向上突破源碼[金字塔模型]
- 金字塔自帶的判斷三角形向上突破的一個VBA的范例
- 轉(zhuǎn)載保留出處 www.tumamayizhan.com
Function TriangleShape(Formula,Cyc,SCyc,ECyc)
'msgbox cyc & "-" & scyc & "-" & ecyc
'該函數(shù)計算當前位置圖形是否是三角形突破,如果是則返回1,否則返回0。該函數(shù)只有在選股時才能使用。
TriangleShape=0
'如果是分時數(shù)據(jù)或者分筆成交那么直接返回
If Formula.ParentGrid.DataType = 0 or Formula.ParentGrid.CycType = 10 Then
Exit Function
End If
'得到K線數(shù)據(jù)對象
Set History = Formula.ParentGrid.GetHistoryData()
If History.Count < Cyc+3 Then
Exit Function
End If
'為了加快處理速度,只有公式在執(zhí)行最后一個周期時使用。這就意味著只能在選股時使用該函數(shù)
'如果你在公式測試中使用,請注釋掉以下語句
If Formula.IndexData < History.Count-1 Then Exit Function
'下面的代碼判斷當前圖形是否可能為三角形態(tài)
'開始位置SCyc周期內(nèi)的高低價格為三角形態(tài)的開始
StartPos = Formula.IndexData - (Cyc+2)
EndPos = Formula.IndexData-3
High = History.High(StartPos)
Low = History.Low(StartPos)
For I = StartPos To StartPos+SCyc
If History.High(I) > High Then
High = History.High(I)
End If
If History.Low(i) < Low Then
Low = History.Low(I)
End If
Next
'ECyc周期內(nèi)的周期高低價格為三角的結(jié)束
High2 = History.High(EndPos - ECyc)
Low2 = History.Low(Endpos-ECyc)
for i = endpos - ECyc to endpos
If History.High(I) > High2 Then
High2 = History.High(I)
End If
If History.Low(i) < Low2 Then
Low2 = History.Low(I)
End If
next
'最后圖形范圍為開始圖形的1/2的話,初步表明是可以做為三角形的結(jié)束
if high2-low2 <= 0 then
exit function
end if
If (High-Low) / (high2-low2) < 2 Then
Exit Function
End if
if high2 > high or low2 < low then
exit function
end if
'如果中間有超過三角形邊界的地方,三角圖形則不成立
'用斜率計算圖形邊界
'計算上邊界
Slope = (high2-high) / (Endpos-StartPos)
b = high - slope * startpos
for i = startpos+SCyc to endpos
temp = slope * i + b
price = (history.open(i)+history.close(i))/2
if temp < price then
exit function
end if
next
'計算下邊界
slope = (low2-low) / (endpos - startpos)
b = low - slope * startpos
for i = startpos to endpos-3
temp = slope * i + b
price = (history.open(i)+history.close(i))/2
if temp > price then
exit function
end if
next
'如果3日后的價格突破了三角型結(jié)束的上邊線認為突破成功
if history.close(Formula.IndexData) > high2 then
TriangleShape = 1
end if
End Function
有思路,想編寫各種指標公式,程序化交易模型,選股公式,預(yù)警公式的朋友
可聯(lián)系技術(shù)人員 QQ: 262069696 進行 有償 編寫!(不貴!點擊查看價格!)
相關(guān)文章
-
沒有相關(guān)內(nèi)容