選股常用語的對應程式集

By | 2019-03-20

愈來愈多網友,開始試著用XS來寫程式挑股票,決定進場時機,新手上路,需要老司機,我整理了一些股市專有名詞對應的語法,供大家參考。

一,整理結束

語法如下:

1//盤整後噴出
2input: Periods(20,"計算期數");
3input: Ratio(3,"近期波動幅度%");
4settotalbar(300);
5setbarback(50);
6
7condition1 = false;
8
9if (highest(high[1],Periods-1) - lowest(low[1],Periods-1))/close[1] <= ratio*0.01 
10then condition1=true//近期波動在?%以內
11else return;
12
13if condition1 and high = highest(high, Periods)
14and close>close[1]*1.02
15then ret=1;//盤整後往上突破

這個腳本可以挑出像下面這樣的股票

2019032301

 

二,下跌時價量背離

腳本如下

1input:period(10);
2input:times(5);
3if close[1]*1.1<close[40]
4and countif(c>c[1]xor v>v[1],period)
5>=times
6and close=highest(close,period)
7then ret=1;

可以挑出的股票如下

2019032202

三,KD進入超賣區

腳本如下

1input: Length(9), RSVt(3), Kt(3);
2variable: rsv(0), k(0), _d(0);
3
4SetBarBack(maxlist(Length,6));
5SetTotalBar(maxlist(Length,6) * 4);
6
7SetInputName(1, "天數");
8SetInputName(2, "RSVt權數");
9SetInputName(3, "Kt權數");
10
11Stochastic(Length, RSVt, Kt, rsv, k, _d);
12
13IF k<20 and _d<30
14then ret=1;

這是在挑出KD值分別低於20及30的股票

四,千張大戶增加

腳本如下

1value1=GetField("大戶持股人數","W",param:=1000);
2value2=GetField("散戶持股人數","W");
3if value1>value1[1]
4and value2<value2[1]
5then ret=1;
6outputfield(1,value1,0,"本週大戶人數");
7outputfield(2,value1[1],0,"上週大戶人數");
8outputfield(3,value1-value1[1],0,"大戶增加數");
9outputfield(4,value2,0,"本週散戶人數");
10outputfield(5,value2[1],0,"上週散戶人數");

這腳本可以挑出千張大戶數比前一週多的股票

五,BBand出現買進訊號

腳本如下

1input:length(20);
2variable:up1(0),down1(0),mid1(0),bbandwidth(0);
3up1 = bollingerband(Close, Length, 1);
4down1 = bollingerband(Close, Length, -1 );
5mid1 = (up1 + down1) / 2;
6
7bbandwidth = 100 * (up1 - down1) / mid1;
8if bbandwidth crosses above 5 and close > up1 and close> up1[1]
9then ret=1;

六,本益比低於某個水準

腳本如下

1input:per(12,"本益比上限");
2value1=GetField("本益比","D");
3if value1<per
4then ret=1;

七,近期處於上昇趨勢

腳本如下

1input:Length(20); //"計算期間"
2
3LinearReg(close, Length, 0, value1, value2, value3, value4);
4//做收盤價20天線性回歸
5{value1:斜率,value4:預期值}
6value5=rsquare(close,value4,20);//算收盤價與線性回歸值的R平方
7if value1>0 and value5>0.2
8then ret=1;

八,放量起漲

腳本

1if average(volume,5) > 200 and
2 C> 10 and
3 volume > average(V[1],20) *2 
4 and close>close[1]*1.01
5 then ret=1;

九,空翻多

腳本如下:

1condition1 = angle(date[20], date[5]) < 0;
2value1 = angle(date[5], date);
3condition2 = value1 > 0;
4
5setoutputname1("angle");
6outputfield1(value1);
7if condition1 and condition2 then ret=1;

十,投信第一天大買進

腳本如下

1value1=GetField("最新股本");//單位:億
2value2=GetField("投信買張","D");
3value3=value2*close/10; //單位:萬}
4
5 
6 
7condition1=value3>200 and value1<80;
8 
9condition2=filter(condition1,5);
10
11if condition2 
12then ret=1;

這邊有用了一個叫filter的函數,這個涵數是用來過濾一定期別內某一情況為true的次數就僅有最近這一期是true.

 

提供這些腳本,主要是讓大家可以參考,也可以直接copy之後編譯完成變成您的腳本,然後再跟其他條件整合起來一起用。