龙听期货论坛's Archiver

C
+
+


 微信: QQ:

龙听 发表于 2018-11-23 14:28

必學常用函式(Function)

[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]學常用保留字就像學英文單字,而學函式就像學英文片語,一樣沒巧門,基本的先背起來,以下列出必學常用的函式及運用範例:[/font][/color]


[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif][b][color=purple]Average(Price,Length)[/color][/b][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif][b]
[/b][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif][b]
[/b][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]說明:計算平均值[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]參數:[/font][/color]
[list][*]Price:要求平均值的標的,可以是Open、High、Low、Close、Volume等等。[*]Length:幾抓近幾個值來計算平均,5就是算最近5個值來平均,以此類推。[/list][color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]範例:畫簡單移動平均線[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
[i]           Value1 = Average(Close,9);[/i][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif][i]           Plot1(Value1, "AvgClose");[/i][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
Average(Price,Length)也可以用AverageFC(Price,Length)取代,後者在演算上比較有效率。[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
[color=purple][b]Xaverage(Price, Length)[/b][/color][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
說明:計算加權移動平均值。給予越近期的值較高權重,以均線來講,會比簡單移動平均線來得敏感而貼近盤勢。[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
參數:[/font][/color]
[list][*]Price:要求加權移動平均值的標的,可以是Open、High、Low、Close、Volume等等[*]Length:幾抓近幾個值來計算平均,5就是算最近5個值來平均,以此類推。[/list][color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]範例:畫加權移動平均線[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
[i]            Value1 = XAverage(Close,9);[/i][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif][i]            Plot1(Value1, "XAvgClose");[/i][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
[color=purple][b]Summation(Price, Length)[/b][/color][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
說明:加總,等於是EXCEL的SUM函式[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]參數:[/font][/color]
[list][*]Price:要加總計算的標的,可以是Open、High、Low、Close、Volume等等[*]Length:幾抓近幾個值來加總,5就是算最近5個值來加總,以此類推。[/list][color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]範例:加總最近5根K棒的成交量[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
[i]            Value1=Summation(Ticks,5)[/i];[/font][/color]


[font=Arial, Tahoma, Helvetica, FreeSans, sans-serif][b]CloseD(PeriodsAgo)[/b][/font]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
說明:抓日線的收盤價。一般我們的主圖是用日內分線,但常需要參考日線的開高低收價格,可以此函數直接取得。[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]參數:[/font][/color]
[list][*]PeriodsAgo:取幾天前的收盤價。[/list][color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]範例:取前天收盤價[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
[i]            CloseD(1);[/i][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
其他Open(PeriodsAgo)、High(PeriodsAgo)、Low(PeriodsAgo)用法一樣。此外,尚有CloseW(PeriodsAgo)、CloseM(PeriodsAgo)、CloseY(PeriodsAgo)等內建函式可用運。[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
[color=purple][b]CountIF(Test,Length)[/b][/color][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
說明:累計過去一定K棒數中,符合特定條件的次數[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]參數:[/font][/color]
[list][*]Test:條件敘述[*]Length:檢定過去K棒數[/list][color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]範例:計算過去12根K棒中,收盤大於開盤(紅K)總數。[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
[i]            Value1 = CountIF(Close > Open, 12);[/i][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
[b][color=purple]LastBarOnChart[/color][/b][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
說明:判斷程式執行K棒是否是最近一根K棒。傳回True或False。[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]參數:無[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
範例:如果希望警示音效只有在最近一根K棒才撥放[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
[i]            If LastBarOnChart Then[/i][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif][i]                 Condition1 = PlaySound("C:\window\ding.wav");[/i][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
[color=purple][b]AvgTrueRange(Length)[/b][/color][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
說明:計算平均真實區間。真實區間的用途相當廣泛,例如用來計算停損點數等。[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]參數:[/font][/color]
[list][*]Length:要計算幾個值來算平均[/list][color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]範例:0.5[/font][/color][color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]倍ATR點數停損[/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]
[i]            If marketposition=1 then [/i][/font][/color]
[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif][i]              sell next bar at entryprice- AvgTrueRange(20)*0.5 stop;[/i][/font][/color]


[color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif]其他還有常用[b]指標類型的函式[/b],僅列舉如下,建議可以參考內建指標或訊號,或是參考相關說明文件,觀摩這些函式是怎麼運用:[/font][/color]


[table]
[tr][td=1,1,319][b]函式[/b][/td][td=1,1,161][b]用途[/b][/td][/tr]
[tr][td=1,1,319]ADX(Length)[/td][td=1,1,161]ADX指標[/td][/tr]
[tr][td=1,1,319]BollingerBand(Price, Length, NumDevs)[/td][td=1,1,161]布林通道指標[/td][/tr]
[tr][td=1,1,319]MACD(Price, FastLength, SlowLength)[/td][td=1,1,161]MACD指標[/td][/tr]
[tr][td=1,1,319]Parabolic(AfStep)[/td][td=1,1,161]SAR指標[/td][/tr]
[tr][td=1,1,319]Stochastic(PriceH, PriceL, PriceC, StochLength, Length1, Length2, SmoothingType, oFastK, oFastD, oSlowK, oSlowD)[/td][td=1,1,161]KD指標[/td][/tr]
[/table][color=#444444][font=Arial, Tahoma, Helvetica, FreeSans, sans-serif][size=13px]
[b]統計類型的函式,列舉如下:[/b]

[/size][/font][/color]
[table]
[tr][td=1,1,319][b]函式[/b][/td][td=1,1,161][b]用途[/b][/td][/tr]
[tr][td=1,1,319]Correlation(Indep,Dep,Length)[/td][td=1,1,161]計算相關係數[/td][/tr]
[tr][td=1,1,319]StdDev(Price, Length)[/td][td=1,1,161]計算標準差

[/td][/tr]
[/table]

奇貨可居 发表于 2023-11-11 15:07

謝謝分享

页: [1]