開始使用免費開始

使用 sigComparison

sigComparison 訊號是一種簡單又實用的方式,用來比較兩個(最好是相關的)數值,例如兩條移動平均線。通常,sigComparison 本身不會直接產生買進或賣出訊號(否則就會在每個符合的日子都買或賣),而是最常用來作為篩選條件,決定何時應該套用其他的買賣規則。

在這個練習中,你會使用 sigComparison() 來建立一個訊號比較:50 日簡單移動平均(SMA)必須高於 200 日簡單移動平均(SMA)。你會把這個訊號標記為 longfilter,因為它代表短期均線在長期均線之上。

本練習屬於課程

R 的金融交易

檢視課程

練習說明

  • 使用 add.signal() 新增一個 sigComparison,指定 SMA50 必須大於 SMA200
  • 將此訊號標記為 longfilter

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Add a sigComparison which specifies that SMA50 must be greater than SMA200, call it longfilter
add.signal(strategy.st, name = "sigComparison", 
           
           # We are interested in the relationship between the SMA50 and the SMA200
           arguments = list(columns = c("___", "___"), 
                            
                            # Particularly, we are interested when the SMA50 is greater than the SMA200
                            relationship = "___"),
           
           # Label this signal longfilter
           label = "___")
編輯並執行程式碼