開始使用免費開始

使用 sigThreshold(1)

在接下來的兩個練習中,你將專注於 sigThreshold 訊號。sigThreshold 訊號主要用來把指標與固定數值比較,通常應用在有界震盪指標,或是滾動統計分數上(例如:某些交易策略可能會在「平均值與標準差比值」達到 -2 時做多,或反向操作)。相較之下,sigComparison 與 sigCrossover 處理的量通常基於與價格大致同一數值區間的指標;而 sigThreshold 則專為那些「超出與價格相近區間的指標」情境而設計。

此外,sigThreshold() 函式有 cross 引數,可指定其行為類似 sigComparison(cross = FALSE)或 sigCrossover(cross = TRUE)。在本練習中,你要實作一個行為類似 sigComparison 的 sigThreshold 變體。

你的工作是實作一個 sigThreshold,檢查 DVO_2_126 是否低於 20。這個訊號將作為進場做多所需的兩個「開關」之一。

本練習屬於課程

R 的金融交易

檢視課程

練習說明

  • 使用 add.signal() 新增一個 sigThreshold 訊號,指定 DVO_2_126 必須低於 20。
  • cross 設為 FALSE
  • 將此訊號標記為 longthreshold

動手互動練習

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

# Implement a sigThreshold which specifies that DVO_2_126 must be less than 20, label it longthreshold
add.signal(strategy.st, name = "___", 
           
           # Use the DVO_2_126 column
           arguments = list(column = "___", 
                            
                            # The threshold is 20
                            threshold = ___, 
                            
                            # We want the oscillator to be under this value
                            relationship = "___", 
                            
                            # We're interested in every instance that the oscillator is less than 20
                            cross = ___), 
           
           # Label it longthreshold
           label = "___")
編輯並執行程式碼