我把常用的一些語法匯總在這裡給大家參考,這樣大家就可以直接取用,不用再自己另外撰寫
開盤暴量
input:P1(1000,"暴量張數定義");
if barfreq <> "Tick" then RaiseRuntimeError("請設定頻率為TICK");
variable:BarNumberOfToday(0);
if Date <> Date[1] then BarNumberOfToday=1
else BarNumberOfToday+=1;{記錄今天的Bar數}
if currenttime < 090500 and date =currentdate {必需在9:05以前發生}
then begin {計算拉升時總張數}
variable: HighBar(NthHighestBar(1,Close,BarNumberOfToday)); {找到出現最高價那根Bar}
variable:idx(BarNumberOfToday-1),PullVolume(0),DropVolume(0);
for idx = BarNumberOfToday-1 to HighBar
{從開盤那個Bar,拉升到最高點那個Bar,上漲過程累計量}
begin
PullVolume += volume[idx]; {拉升的量}
end;
if PullVolume > P1 then ret=1;
end;
暴量剛起漲
input: Length(20); setinputname(1,"計算期數");
input: VLength(10); setinputname(2,"均量期數");
input: volpercent(50); setinputname(3,"爆量增幅%");
input: Rate(5); setinputname(4,"離低點幅度%");
settotalbar(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;
分鐘量暴量N%
input:percent(100); setinputname(1,"量增比例%");
input:Length(200); setinputname(2,"均量期數");
input:XLimit(True); setinputname(3,"限制最低觸發門檻");
input:atVolume(500); setinputname(4,"最低觸發張數");
input:TXT("建議使用分鐘線"); setinputname(5,"使用說明");
variable: AvgVolume(0);
settotalbar(Length + 3);
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;
暴量脫離長期盤整區
以下腳本程式碼其中有一個 estvolume 自訂函數,在連結的文章中有做介紹,請注意要新增並編譯完成 estvolume 函數腳本後,才能取用此函數到其他腳本中。
input: VLength(20,"均量期數");
input: volpercent(60,"爆量增幅%");
input: r1(5,"區間高低差%");
input: period(30,"盤整最小期數");
if Close crosses above highest(high[1],period)//股價突破盤整區間
and
estvolume > average(volume,VLength) *(1+ volpercent/100)//暴量
and
highest(high,period)<=lowest(low,period)*(1+r1/100)//先前區間盤整
then ret=1;
箱型整理突破
input:period(40,"計算區間");
value1=highest(close[1],period);
value2=lowest(close[1],period);
if value1<value2*1.05
and close>close[2]*1.006
and close crosses over value1
and volume>average(volume[1],20)*1.3
then ret=1;
波動範圍變大
value1=truerange;
value2=highest(value1,20);
if value1>value2[1]
and value1>value1[1]
and close*1.01>high
and close>close[1]
and volume>1000
then ret=1;
底部愈墊愈高且資金流入
input:r1(7); setinputname(1,"近來漲幅上限%");
SetTotalBar(8);
value1 = RateOfChange(close, 12);
value2 = lowest(low,3);
value3 = lowest(low,8);
value4 = lowest(low,13);
condition1=false;
condition2=false;
if
value1 < r1 and
value2 > value3 and
value3 > value4 and
close = highest(close,13)
then
condition1=true;
Value5=average(GetField("資金流向")[1],13);
if linearregslope(Value5,5) > 0
then condition2=true;
if condition1 and condition2
then ret=1;
股價突破布林值上緣
input:length(20,"布林值計算天數");
variable:up1(0),down1(0),mid1(0),bbandwidth(0);
up1 = bollingerband(Close, Length, 2);
//以上是計算布林值的上軌值
input: day(9, "日KD期間");
variable:rsv_d(0),kk_d(0),dd_d(0);
stochastic(day, 3, 3, rsv_d, kk_d, dd_d);
//以上是計算KD值
if kk_d >=80
//KD鈍化
and close crosses over up1
then ret=1;
突破下降趨勢線
在新增「突破下降趨勢線」腳本前,請大家記得要先新增 angleprice 自訂函數,此自訂函數的腳本程式碼如下:
input:Date1(numeric),ang(numeric);
variable:Date1Price(0);
Date1Price =Open[Date1];
value1=tan(ang);
value2=date1price*(1+value1*date1/100);
angleprice=value2;
新增並編譯完成 angleprice 自訂函數後,即可撰寫「突破下降趨勢線」的腳本:
setbackbar(60);
variable:keyprice(0);
value1=highestbar(high,20);
value2=swinghighbar(close,20,2,2,2);
if value2<>-1 then begin
value3=angle(date[value1],date[value2]);
keyprice=angleprice(value1,value3);
if value1>value2
and trueall(close >keyprice,3)
and close>keyprice*1.05
and close[40]*1.1<highest(high,20)
then ret=1;
end;
有大買單
input: BigBuy(500); setinputname(1,"大戶買單(萬)");
input: BigBuyTimes(10); setinputname(2,"大戶買進次數");
input:TXT("須逐筆洗價"); setinputname(3,"使用限制:");
variable: intrabarpersist Xtime(0);//計數器
variable: intrabarpersist Volumestamp(0);
Volumestamp =q_DailyVolume;
if Date <> currentdate or Volumestamp = Volumestamp[1] then Xtime =0; //開盤那根要歸0次數
if q_tickvolume*q_Last > BigBuy*10 and q_BidAskFlag=1 then Xtime+=1; //量夠大就加1次
if Xtime > BigBuyTimes then ret=1;
價量背離後跌破
input:Length(5, "計算期數");
input:times(3, "價量背離次數");
input:Dist(20, "距離");
variable:count(0),KPrice(0),hDate(0);
count = CountIf(close > close[1] and volume < volume[1], Length);
if count > times then begin
hDate=Date;
Kprice = lowest(l,length);
end;
Condition1 = Close crosses below Kprice;
Condition2 = DateDiff(Date,hdate) < Dist;
Ret = Condition1 And Condition2;
回檔後籌碼收集
condition1=false;
value1=GetField("分公司買進家數")[1];
value2=GetField("分公司賣出家數")[1];
value3=value2-value1;
value4=countif(value3>20,10);
value5=GetField("投信買張")[1];
value6=summation(value5,5);
if countif(value6>=1000,60)>=1
then condition1=true;
//過去60個交易日投信曾五天買超過2000張
if value4>=6
//最近十天有六天以上,籌碼是收集的
and close[30]>close*1.1
//最近三十天跌超過一成
and condition1
then ret=1;
突破外資成本線
Input: period(20, "期間(天)");
variable: avg_b(0);
value3=GetField("成交金額")/(GetField("Volume")*1000);
//當日均價
if GetField("Volume") > 0 then
Value5 = GetField("外資買張")*value3
//外資買進金額
else
Value5 = 0;
Value1 = summation(Value5, period);
Value2 = summation(GetField("外資買張"), period);
if Value2 > 0 then avg_b = Value1 / Value2;
if close crosses over avg_b then ret=1;
內外盤力道空翻多
variable:IORatio(0),z(1);
if GetField("內盤量")[z]<>0 then
IORatio=GetField("外盤量")[z]/GetField("內盤量")[z]-1
{每天的內外盤力道比例}
else
ioratio=ioratio[1];
variable:iHigh(0),iLow(10000);
if IORatio > 0.5 then
begin
iHigh = H;
end
else if IORatio < -0.5 then
begin
iLow = L;
end;
if iHigh crosses over iLow then ret=1;
開盤委買暴增
input:length(5);
value1=GetField("開盤委買");
value5=average(value1,100);
if
value1>4*value5
and value1>200
and close<close[10]
then ret=1;