觸發張數最小設定

  •   83 
  • 最後發表   peterchang  2022 六月 01
peterchang 發文於   2022/05/25

想詢問設定最低觸發張數 為1000張,但策略在跑時沒有超過1000張也會觸發
不確定下面語法哪裡有錯,感謝回復!!

 input: Length(20); setinputname(1,"計算期數");

input: VLength(10); setinputname(2,"均量期數");

input: volpercent(50); setinputname(3,"爆量增幅%");

input: Rate(5); setinputname(4,"離低點幅度%");

input:XLimit(True); setinputname(5,"限制最低觸發門檻");

input:atVolume(1000); setinputname(6,"最低觸發張數");

input:percent(100); setinputname(7,"量增比例%");

 

 

 

settotalbar(Length + 3);

setbarback(maxlist(Length,VLength));

 

if Close > Close[1] and

Volume >= average(volume,VLength) *(1+ volpercent/100) and

Close <= lowest(close,Length) * (1+Rate/100)

then ret=1;

 

variable: AvgVolume(0);

 

AvgVolume=Average(volume,Length);

if XLimit then

begin

if Volume > atVolume and volume > AvgVolume *(1+ percent/100) then ret=1;

end

else

begin

if Volume > Volume[1] and volume > AvgVolume *(1+ percent/100) then ret=1;

end;

 

附加文件

排序方式: 標準 | 最新
XQ小幫手 發文於   2022/05/26

Hello peterchang,

 

您的腳本中有三個地方會觸發警示,只有其中一個有用到 Volume > atVolume 的條件。

後面兩個條件雖然是由 XLimit 來決定執行哪一個,但第一個條件:

if Close > Close[1] and

Volume >= average(volume,VLength) *(1+ volpercent/100) and

Close <= lowest(close,Length) * (1+Rate/100)

then ret=1;

一定會執行到。

 

推測可能是這個地方導致策略觸發。

建議您可以使用print函數來檢查相關數值。

 

如果還是有問題的話,麻煩告知您是在什麼商品什麼頻率等策略設定及什麼日期時間觸發的,讓小幫手這邊實際print出來檢驗。

peterchang 發文於   2022/05/30

您好小編,

那想請問一下如果條件都需要同時符合才能觸發條件,需要怎麼修改?
我目前是拿來設定我的股票組合中,設定1分線

感謝回復

XQ小幫手 發文於   2022/06/01

Hello peterchang,

 

您第二個條件和第三個條件原本的設計是擇一執行,所以應該是分開判斷。

只要將希望同時符合的條件寫在一個 if 判斷式裡,像是 Volume > atVolume and volume > AvgVolume *(1+ percent/100) 就是兩個條件組合而成。

舉例來說,將原本的三個條件用 condition 整理起來:

condition1 =  Close > Close[1] and Volume >= average(volume,VLength) *(1+ volpercent/100) and Close <= lowest(close,Length) * (1+Rate/100);

condition2 = Volume > atVolume and volume > AvgVolume *(1+ percent/100);

condition3 = Volume > Volume[1] and volume > AvgVolume *(1+ percent/100);

 

這樣就可以自行決定要哪幾個條件符合時警示,若要1跟2的話就會是 if condition1 and condition2 then ret = 1;

 

網站上有教學區,裡面有XS語法的基礎和應用可以閱覽。

發表回覆
Close