警示條件加入CurrentTime後, 運算結果不符合預期

  •   121 
  • 最後發表   Uaena  2023 四月 14
Uaena 發文於   2023/04/07

這個警示目的是: 找出日K從多頭排列變成多頭排列的個股

原本沒有CurrentTime的條件執行上看起來有符合預期, 也有寫一版指標用於畫圖, 看起來邏輯也正確

但加入CurrentTime後警示瘋狂跳出, 很多不符合條件的個股都有觸發

給兩隻個股範例, 今天04/07, 6154 & 6156都有觸發, 但這兩隻明顯不是今天才出現日K多頭排列

在請幫忙看看問題

_________________________________

 

settotalbar(3);

setbarback(20);

 

variable: ma5(0);

variable: ma10(0);

variable: ma20(0);

 

if currentTime >= 123000 Then

Begin

   ma5 = average(close, 5);

   ma10 = average(close, 10);

   ma20 = average(close, 20);

 

   condition1 = ma5 > ma10 and ma10 > ma20 and

                ma5 >= ma5[1] and

                ma10 >= ma10[1] and

                ma20 >= ma20[1]; // 當日日K多頭排列

 

   condition2 = ma5[1] > ma10[1] and ma10[1] > ma20[1] and

                ma5[1] >= ma5[2] and

                ma10[1] >= ma10[2] and

                ma20[1] >= ma20[2]; // 前日日K多頭排列

 

   if condition1 and not(condition2) Then 

   ret = 1;

End;

附加文件

排序方式: 標準 | 最新
Uaena 發文於   2023/04/10

今天用print debug發現是因為ma5/10/20都沒有過去的值

沒有加入CurrentTime當條件的話, ma5/10/20過去的值正常, 請問小編為何會有這樣的差異呢?

04/10的6154

close =  16.500000 close[1] =  16.700000 close[2] =  16.950000 ma5 =  16.910000 ma5[1] =  0.000000 ma5[2] =  0.000000 

 

ma10 =  16.515000 ma10[1] =  0.000000 ma10[2] =  0.000000 ma20 =  16.290000 ma20[1] =  0.000000 ma20[2] =  0.000000 

XQ小幫手 發文於   2023/04/14

Hello Uaena,

 

因為您把

ma5 = average(close, 5);

ma10 = average(close, 10);

ma20 = average(close, 20);

包在 currentTime >= 123000 裡的這種寫法,會讓腳本在 123000 以後才計算 ma 的值,所以在123000 之前的資料中 ma 值都會是0。

建議您可以把 ma 拿到 currentTime >= 123000 外計算,或是將 currentTime >= 123000 改成 condition3,不要將其用 if ... begin 包住其他運算。

發表回覆
Close