如何使用XS選股腳本撰寫K線貼近布林通道下緣,並且KD在30以下且黃金交叉的選股條件?

 

邏輯說明:

K線收盤價貼近布林通道下緣-->數值是上下10%

 

程式撰寫參考內建的選股腳本:

1. KD黃金交叉

2. 布林通道超賣

 

程式撰寫大致說明:

1. 參考內建的選股腳本修改

2. 設兩個條件變數(Condition) 分別設為兩個條件,當兩個條件皆為True則挑選出該股票。

 

程式碼範例如下:

// K線貼近布林通道下緣 K線收盤價貼近布林通道下緣-->數值是上下10%
//  KD在30以下,且黃金交叉

Input: LengthBand(20), LowerBand(2), Length(9), RSVt(3), Kt(3);
variable: rsv_(0), k(0), _d(0);

SetInputName(1, "期數");
SetInputName(2, "通道下緣");
SetInputName(3, "天數");
SetInputName(4, "RSVt權數");
SetInputName(5, "Kt權數");

SetTotalBar(maxlist(Length,6) * 3);

Stochastic(Length, RSVt, Kt, rsv_, k, _d);

condition1 = close < bollingerband(Close, LengthBand, LowerBand * -1)*1.1 and close > bollingerband(Close, LengthBand, LowerBand * -1)*0.9;
condition2 = k <= 30 and _d <= 30 and k crosses above _d;

if condition1 and condition2 then ret = 1;

 

以上,提供參考。