Consecutive Downs SE#

這是用於捕捉下跌趨勢的策略,透過設定連續下跌的K棒數量作為進入市場的條件,以抓住市場的趨勢進行交易。

原始碼#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[IntrabarOrderGeneration = false]
Inputs: Price(Close), ConsecutiveBarsDown(3);

If Price < Price[1] Then
  Value1 = Value1 + 1
Else
  Value1 = 0;

If Value1 >= ConsecutiveBarsDown Then
  Sell Short ("ConsDnSE") next bar at market;

程式碼說明#

1
[IntrabarOrderGeneration = false]

確保在同一根K棒內不會生成多個委託單,僅在K棒完成時才生成委託單。

1
Inputs: Price(Close), ConsecutiveBarsDown(3);
  • Price: 作為判斷的價格,預設為收盤價。
  • ConsecutiveBarsDown: 價格連續下跌的K棒數量,預設為 3。
1
2
3
4
If Price < Price[1] Then
  Value1 = Value1 + 1
Else
  Value1 = 0;

比較當前K棒的價格與前一根K棒的價格來判斷是否下跌。如果價格下跌,將計數器 Value1 加 1;如果沒有下跌,重置計數器為 0。

1
2
If Value1 >= ConsecutiveBarsDown Then
  Sell Short ("ConsDnSE") next bar at market;

當計數器的值達到或超過設定的連續下跌K棒數量時,在下一根K棒以市價執行賣空。

© 2026 CodeReindeer. All rights reserved.