常用的語法匯總

By | 2021-07-07

我把常用的一些語法匯總在這裡給大家參考,這樣大家就可以直接取用,不用再自己另外撰寫

 

開盤暴量

1input:P1(1000,"暴量張數定義");
2if barfreq <> "Tick" then RaiseRuntimeError("請設定頻率為TICK");
3variable:BarNumberOfToday(0); 
4if Date <> Date[1] then BarNumberOfToday=1 
5else BarNumberOfToday+=1;{記錄今天的Bar數}
6
7if currenttime < 090500 and date =currentdate {必需在9:05以前發生}
8then begin {計算拉升時總張數}
9variable: HighBar(NthHighestBar(1,Close,BarNumberOfToday)); {找到出現最高價那根Bar}
10variable:idx(BarNumberOfToday-1),PullVolume(0),DropVolume(0); 
11for idx = BarNumberOfToday-1 to HighBar 
12{從開盤那個Bar,拉升到最高點那個Bar,上漲過程累計量}
13begin
14PullVolume += volume[idx]; {拉升的量}
15end;
16if PullVolume > P1 then ret=1;
17end;

 

暴量剛起漲

1input: Length(20); setinputname(1,"計算期數");
2input: VLength(10); setinputname(2,"均量期數");
3input: volpercent(50); setinputname(3,"爆量增幅%");
4input: Rate(5); setinputname(4,"離低點幅度%");
5
6settotalbar(3);
7setbarback(maxlist(Length,VLength));
8
9if Close > Close[1] and
10Volume >= average(volume,VLength) *(1+ volpercent/100) and
11Close <= lowest(close,Length) * (1+Rate/100)
12then ret=1;

 

分鐘量暴量N%

1input:percent(100); setinputname(1,"量增比例%");
2input:Length(200); setinputname(2,"均量期數");
3input:XLimit(True); setinputname(3,"限制最低觸發門檻");
4input:atVolume(500); setinputname(4,"最低觸發張數");
5input:TXT("建議使用分鐘線"); setinputname(5,"使用說明");
6
7variable: AvgVolume(0);
8
9settotalbar(Length + 3);
10
11AvgVolume=Average(volume,Length);
12if XLimit then 
13begin
14if Volume > atVolume and volume > AvgVolume *(1+ percent/100) then ret=1;
15end
16else
17begin
18if Volume > Volume[1] and volume > AvgVolume *(1+ percent/100) then ret=1;
19end;

暴量脫離長期盤整區

以下腳本程式碼其中有一個 estvolume 自訂函數,在連結的文章中有做介紹,請注意要新增並編譯完成 estvolume 函數腳本後,才能取用此函數到其他腳本中。

1input: VLength(20,"均量期數");
2input: volpercent(60,"爆量增幅%");
3input: r1(5,"區間高低差%");
4input: period(30,"盤整最小期數");
5
6if Close crosses above highest(high[1],period)//股價突破盤整區間
7and
8estvolume > average(volume,VLength) *(1+ volpercent/100)//暴量
9and
10highest(high,period)<=lowest(low,period)*(1+r1/100)//先前區間盤整
11then ret=1;

箱型整理突破

 

1input:period(40,"計算區間");
2value1=highest(close[1],period);
3value2=lowest(close[1],period);
4if value1<value2*1.05
5and close>close[2]*1.006
6and close crosses over value1
7and volume>average(volume[1],20)*1.3
8then ret=1;

 

波動範圍變大

1value1=truerange;
2value2=highest(value1,20);
3if value1>value2[1]
4and value1>value1[1]
5and close*1.01>high
6and close>close[1]
7and volume>1000
8then ret=1;

 

底部愈墊愈高且資金流入

1input:r1(7); setinputname(1,"近來漲幅上限%");
2
3SetTotalBar(8);
4
5value1 = RateOfChange(close, 12);
6value2 = lowest(low,3);
7value3 = lowest(low,8);
8value4 = lowest(low,13);
9
10condition1=false;
11condition2=false;
12
13if 
14value1 < r1 and
15value2 > value3 and 
16value3 > value4 and
17close = highest(close,13)
18then 
19condition1=true;
20
21Value5=average(GetField("資金流向")[1],13);
22
23if linearregslope(Value5,5) > 0
24then condition2=true;
25
26if condition1 and condition2
27then ret=1;

 

股價突破布林值上緣

1input:length(20,"布林值計算天數");
2variable:up1(0),down1(0),mid1(0),bbandwidth(0);
3up1 = bollingerband(Close, Length, 2); 
4//以上是計算布林值的上軌值
5input: day(9, "日KD期間");
6variable:rsv_d(0),kk_d(0),dd_d(0);
7stochastic(day, 3, 3, rsv_d, kk_d, dd_d);
8//以上是計算KD值
9
10if kk_d >=80
11//KD鈍化
12and close crosses over up1
13then ret=1;

 

突破下降趨勢線

在新增「突破下降趨勢線」腳本前,請大家記得要先新增 angleprice 自訂函數,此自訂函數的腳本程式碼如下:

1input:Date1(numeric),ang(numeric);
2variable:Date1Price(0);
3Date1Price =Open[Date1];
4value1=tan(ang);
5value2=date1price*(1+value1*date1/100);
6angleprice=value2;

新增並編譯完成 angleprice 自訂函數後,即可撰寫「突破下降趨勢線」的腳本:

1setbackbar(60);
2variable:keyprice(0);
3value1=highestbar(high,20);
4value2=swinghighbar(close,20,2,2,2);
5if value2<>-1 then begin
6value3=angle(date[value1],date[value2]);
7keyprice=angleprice(value1,value3);
8if value1>value2 
9and trueall(close >keyprice,3)
10and close>keyprice*1.05
11and close[40]*1.1<highest(high,20)
12then ret=1;
13end;

有大買單

1input: BigBuy(500); setinputname(1,"大戶買單(萬)");
2input: BigBuyTimes(10); setinputname(2,"大戶買進次數");
3input:TXT("須逐筆洗價"); setinputname(3,"使用限制:");
4
5variable: intrabarpersist Xtime(0);//計數器
6variable: intrabarpersist Volumestamp(0);
7
8Volumestamp =q_DailyVolume;
9
10if Date <> currentdate or Volumestamp = Volumestamp[1] then Xtime =0; //開盤那根要歸0次數
11
12if q_tickvolume*q_Last > BigBuy*10 and q_BidAskFlag=1 then Xtime+=1; //量夠大就加1次
13
14if Xtime > BigBuyTimes then ret=1;

 

價量背離後跌破

1input:Length(5, "計算期數");
2input:times(3, "價量背離次數");
3input:Dist(20, "距離");
4
5variable:count(0),KPrice(0),hDate(0);
6
7count = CountIf(close > close[1] and volume < volume[1], Length);
8
9if count > times then begin
10hDate=Date;
11Kprice = lowest(l,length);
12end;
13
14
15Condition1 = Close crosses below Kprice;
16Condition2 = DateDiff(Date,hdate) < Dist;
17Ret = Condition1 And Condition2;

 

回檔後籌碼收集

1condition1=false;
2value1=GetField("分公司買進家數")[1];
3value2=GetField("分公司賣出家數")[1];
4value3=value2-value1;
5value4=countif(value3>20,10);
6value5=GetField("投信買張")[1];
7value6=summation(value5,5);
8if countif(value6>=1000,60)>=1
9then condition1=true;
10//過去60個交易日投信曾五天買超過2000張
11if value4>=6
12//最近十天有六天以上,籌碼是收集的
13and close[30]>close*1.1
14//最近三十天跌超過一成
15and condition1
16then ret=1;

 

突破外資成本線

1Input: period(20, "期間(天)");
2
3variable: avg_b(0);
4value3=GetField("成交金額")/(GetField("Volume")*1000);
5//當日均價
6if GetField("Volume") > 0 then 
7Value5 = GetField("外資買張")*value3
8//外資買進金額
9else 
10Value5 = 0;
11Value1 = summation(Value5, period);
12Value2 = summation(GetField("外資買張"), period);
13if Value2 > 0 then avg_b = Value1 / Value2;
14if close crosses over avg_b then ret=1;

內外盤力道空翻多

1variable:IORatio(0),z(1);
2if GetField("內盤量")[z]<>0 then 
3IORatio=GetField("外盤量")[z]/GetField("內盤量")[z]-1
4{每天的內外盤力道比例}
5else
6ioratio=ioratio[1];
7
8
9variable:iHigh(0),iLow(10000);
10
11if IORatio > 0.5 then 
12begin
13iHigh = H;
14end
15else if IORatio < -0.5 then 
16begin
17iLow = L;
18end;
19
20
21if iHigh crosses over iLow then ret=1;

 

開盤委買暴增

1input:length(5);
2value1=GetField("開盤委買");
3
4value5=average(value1,100);
5
6if 
7value1>4*value5
8and value1>200
9and close<close[10]
10then ret=1;