源碼解析理論:
輸出INPUT:CANG1(1,0,10,1),CANG2(1,0,10,1)
輸出VARIABLE:CC1=0,CC2=0
反手HI賦值:1日前的10日內最高價的最高值
LO賦值:1日前的10日內最低價的最低值
BEGINPC賦值:HOLDING和0的較大值和CANG1的較小值
KC賦值:CANG1-PC
條件判斷 PC>0 THEN 平倉賣出
條件判斷 KC>0 THEN 平倉買入
CC1賦值:0
BEGINPC賦值:HOLDING和0的較小值的絕對值和CANG1的較小值
KC賦值:CANG1-PC
條件判斷 PC>0 THEN 開倉賣出
條件判斷 KC>0 THEN 開倉買入
CC1賦值:0
BEGINPC賦值:HOLDING和0的較小值的絕對值和CANG1的較小值
KC賦值:CANG1-PC
條件判斷 PC>0 THEN 開倉賣出
條件判斷 KC>0 THEN 開倉買入
CC1賦值:1
BEGINPC賦值:HOLDING和0的較大值和CANG1的較小值
KC賦值:CANG1-PC
條件判斷 PC>0 THEN 平倉賣出
條件判斷 KC>0 THEN 平倉買入
CC1賦值:-1
反手HI賦值:1日前的20日內最高價的最高值
LO賦值:1日前的20日內最低價的最低值
BEGINPC賦值:HOLDING和0的較大值和CANG2的較小值
KC賦值:CANG2-PC
條件判斷 PC>0 THEN 平倉賣出
條件判斷 KC>0 THEN 平倉買入
CC2賦值:0
BEGINPC賦值:HOLDING和0的較小值的絕對值和CANG2的較小值
KC賦值:CANG2-PC
條件判斷 PC>0 THEN 開倉賣出
條件判斷 KC>0 THEN 開倉買入
CC2賦值:0
BEGINPC賦值:HOLDING和0的較小值的絕對值和CANG2的較小值
KC賦值:CANG2-PC
條件判斷 PC>0 THEN 開倉賣出
條件判斷 KC>0 THEN 開倉買入
CC2賦值:1
BEGINPC賦值:HOLDING和0的較大值和CANG2的較小值
KC賦值:CANG2-PC
條件判斷 PC>0 THEN 平倉賣出
條件判斷 KC>0 THEN 平倉買入
CC2賦值:-1
輸出END/////////////////////////////////以上是模型2//有更多的模型,往后面添加即可如果各個模型都是K線走完模式的,可以這樣組合更加方便VARIABLE:LEE=0
KC1賦值:LEE和0的較大值-HOLDING和0的較大值
KC2賦值:LEE和0的較小值-HOLDING和0的較小值
條件判斷 KC1<-0.5 THEN 平倉賣出
條件判斷 KC2>0.5 THEN 開倉賣出
條件判斷 KC1>0.5 THEN 開倉買入
條件判斷 KC2<-0.5 THEN 平倉買入
輸出//模型1VARIABLE:CC1=0
BUYCOND1賦值:收盤價>1日前的收盤價 AND 1日前的收盤價>2日前的收盤價
SELLCOND1賦值:收盤價<1日前的收盤價 AND 1日前的收盤價<2日前的收盤價
CC1賦值:0
CC1賦值:0
CC1賦值:1
CC1賦值:-1
輸出//模型2VARIABLE:CC2=0
BUYCOND2賦值:收盤價的5日簡單移動平均>收盤價的20日簡單移動平均
SELLCOND2賦值:收盤價的5日簡單移動平均<收盤價的20日簡單移動平均
CC2賦值:0
CC2賦值:0
CC2賦值:1
CC2賦值:-1
輸出//模型3VARIABLE:CC3=0
BUYCOND3賦值:收盤價的10日簡單移動平均>收盤價的30日簡單移動平均
SELLCOND3賦值:收盤價的10日簡單移動平均<收盤價的30日簡單移動平均
CC3賦值:0
CC3賦值:0
CC3賦值:1
CC3賦值:-1
LEE賦值:1*CC1+1*CC2+1*CC3
//每個模型乘以各自的下單系數
源碼:
因為圖表交易同一根K線出現2個開多信號的話,只會開一次,另外一個無法執行,但是可以做歷時回測
組合起來的模型,加入后臺下單語句,就可以用于后臺下單,當然,后臺下單用“后臺下單模板”會更好用。
方法原理:計算每個時點要下單的手數和方向,再根據holding判斷出要平倉和開倉的數量,然后再下單。
看起來很多,其實很簡單,最基本得模塊就是藍色部分
input:cang1(1,0,10,1),cang2(1,0,10,1);
variable:cc1=0,cc2=0;
/////////////////////////////////模型1——10周期反手
hi:=ref(hhv(h,10),1);
lo:=ref(llv(l,10),1);
if cc1>0 and l<lo then begin
pc:=min(max(holding,0),cang1);
kc:=cang1-pc;
if pc>0 then sell(1,pc,limitr,min(o,lo-0.2)-0.6);
if kc>0 then buyshort(1,kc,limitr,min(o,lo-0.2)-0.6);
cc1:=0;
end
if cc1<0 and h>hi then begin
pc:=min(abs(min(holding,0)),cang1);
kc:=cang1-pc;
if pc>0 then sellshort(1,pc,limitr,max(o,hi+0.2)+0.6);
if kc>0 then buy(1,kc,limitr,max(o,hi+0.2)+0.6);
cc1:=0;
end
if cc1=0 and h>hi then begin
pc:=min(abs(min(holding,0)),cang1);
kc:=cang1-pc;
if pc>0 then sellshort(1,pc,limitr,max(o,hi+0.2)+0.6);
if kc>0 then buy(1,kc,limitr,max(o,hi+0.2)+0.6);
cc1:=1;
end
if cc1=0 and l<lo then begin
pc:=min(max(holding,0),cang1);
kc:=cang1-pc;
if pc>0 then sell(1,pc,limitr,min(o,lo-0.2)-0.6);
if kc>0 then buyshort(1,kc,limitr,min(o,lo-0.2)-0.6);
cc1:=-1;
end
/////////////////////////////////以上是模型1
/////////////////////////////////模型2——20周期反手
hi:=ref(hhv(h,20),1);
lo:=ref(llv(l,20),1);
if cc2>0 and l<lo then begin
pc:=min(max(holding,0),cang2);
kc:=cang2-pc;
if pc>0 then sell(1,pc,limitr,min(o,lo-0.2)-0.6);
if kc>0 then buyshort(1,kc,limitr,min(o,lo-0.2)-0.6);
cc2:=0;
end
if cc2<0 and h>hi then begin
pc:=min(abs(min(holding,0)),cang2);
kc:=cang2-pc;
if pc>0 then sellshort(1,pc,limitr,max(o,hi+0.2)+0.6);
if kc>0 then buy(1,kc,limitr,max(o,hi+0.2)+0.6);
cc2:=0;
end
if cc2=0 and h>hi then begin
pc:=min(abs(min(holding,0)),cang2);
kc:=cang2-pc;
if pc>0 then sellshort(1,pc,limitr,max(o,hi+0.2)+0.6);
if kc>0 then buy(1,kc,limitr,max(o,hi+0.2)+0.6);
cc2:=1;
end
if cc2=0 and l<lo then begin
pc:=min(max(holding,0),cang2);
kc:=cang2-pc;
if pc>0 then sell(1,pc,limitr,min(o,lo-0.2)-0.6);
if kc>0 then buyshort(1,kc,limitr,min(o,lo-0.2)-0.6);
cc2:=-1;
end
/////////////////////////////////以上是模型2
//有更多的模型,往后面添加即可
如果各個模型都是K線走完模式的,可以這樣組合更加方便
variable:lee=0;
kc1:=max(lee,0)-max(holding,0);
kc2:=min(lee,0)-min(holding,0);
if kc1<-0.5 then sell(1,abs(kc1),limitr,open);
if kc2>0.5 then sellshort(1,kc2,limitr,open);
if kc1>0.5 then buy(1,kc1,limitr,open);
if kc2<-0.5 then buyshort(1,abs(kc2),limitr,open);
//模型1
variable:cc1=0;
buycond1:=c>ref(c,1) and ref(c,1)>ref(c,2);
sellcond1:=c<ref(c,1) and ref(c,1)<ref(c,2);
if cc1>0 and sellcond1 then cc1:=0;
if cc1<0 and buycond1 then cc1:=0;
if cc1=0 and buycond1 then cc1:=1;
if cc1=0 and sellcond1 then cc1:=-1;
//模型2
variable:cc2=0;
buycond2:=ma(c,5)>ma(c,20);
sellcond2:=ma(c,5)<ma(c,20);
if cc2>0 and sellcond2 then cc2:=0;
if cc2<0 and buycond2 then cc2:=0;
if cc2=0 and buycond2 then cc2:=1;
if cc2=0 and sellcond2 then cc2:=-1;
//模型3
variable:cc3=0;
buycond3:=ma(c,10)>ma(c,30);
sellcond3:=ma(c,10)<ma(c,30);
if cc3>0 and sellcond3 then cc3:=0;
if cc3<0 and buycond3 then cc3:=0;
if cc3=0 and buycond3 then cc3:=1;
if cc3=0 and sellcond3 then cc3:=-1;
lee:=1*cc1+1*cc2+1*cc3;//每個模型乘以各自的下單系數