INPUT:P(50,2,200,1){建倉量},P1(1,0,50,1){初始止損幅度},P2(5,2,100,1){止盈幅度},P3(30,5,60,5){回撤止盈};
VARIABLE:MAXPROFIT=0,{有倉位時最大獲利幅度}VMIN = 090000;{用于隔夜高開或低開時間差}????????????????
WIN1:=0;???????????????????????????????????????????????????????????
WIN2:=0;//止盈、止損、回撤控制
?
交易時間:=TIME>VMIN AND TIME<151430;
a:=open+10;
b:=open-10;
HNL:=IF(HIGH>REF(HHV(HIGH,3),1),LOW,0);
L1:=IF(HNL>REF(L,1),REF(L,1),IF(HNL>REF(L,2),REF(L,2),IF(HNL>REF(L,3),REF(L,3),IF(HNL>REF(L,4),REF(L,4),0))));
L2:=IF(L1>REF(L,1),REF(L,1),IF(L1>REF(L,2),REF(L,2),IF(L1>REF(L,3),REF(L,3),IF(L1>REF(L,4),REF(L,4),0))));
L3:=VALUEWHEN(L2>0,L2);
LNH:=IF(LOW<REF(LLV(LOW,3),1),HIGH,99999);
H1:=IF(LNH<REF(H,1),REF(H,1),IF(LNH<REF(H,2),REF(H,2),IF(LNH<REF(H,3),REF(H,3),IF(LNH<REF(H,4),REF(H,4),99999))));
H2:=IF(H1<REF(H,1),REF(H,1),IF(H1<REF(H,2),REF(H,2),IF(H1<REF(H,3),REF(H,3),IF(H1<REF(H,4),REF(H,4),0))));
H3:=VALUEWHEN(H2>0,H2);
SEL:=VALUEWHEN((CLOSE>H3 and REF(CLOSE,1)<=H3)or(CLOSE<L3 and REF(CLOSE,1)>=L3),IF(CLOSE>H3 and REF(CLOSE,1)<=H3,1,0));
LINE:IF(SEL=1,L3,H3),COLORblue,LINETHICK2;
DRAWNUMBER(ISLASTBAR,LINE,LINE,0,COLORblue);
//建立多頭的進場條件
long:=c>a AND C>LINE ;
if long then
begin
sellshort(holding<0,0,MARKET);
buy(holding=0,p,limitr,a);
end
//建立空頭的進場條件
short:=c<b AND C<LINE ;
if short then
begin
sell(holding>0,0,MARKET);
buyshort(holding=0,p,limitr,b);
end
//盈虧計算
???? IF ENTERBARS>0 THEN BEGIN
???????? WIN1:=(C-ENTERPRICE)/ENTERPRICE*100;
???????? IF WIN1>MAXPROFIT THEN
???????????? MAXPROFIT:=WIN1;
???????? WIN2:=(MAXPROFIT-WIN1)/MAXPROFIT*100;
???? END
?
???? //多頭初始浮虧 P1% 止損
???? IF WIN1<-P1 THEN
???????? SELL(1,HOLDING,LIMITR,CLOSE);
?
???? //多頭利潤大于 P2% 止盈
???? IF WIN1>P2 THEN
???????? SELL(1,HOLDING,LIMITR,CLOSE);
?????
???? //多頭獲利后回撤 P3%止盈
???? IF WIN2>P3 AND OPENPROFIT>0 THEN
???????? SELL(1,HOLDING,LIMITR,CLOSE);
?//END
?
// IF HOLDING<0 THEN BEGIN
????
???? //空頭平倉
//???? IF 平空 THEN
//???????? SELLSHORT(1,HOLDING,LIMITR,CLOSE);
?
???? //空頭收盤平倉
??? // IF NOT(交易時間) THEN
????? //?? SELLSHORT(1,HOLDING,LIMITR,CLOSE);
?????
???? //盈虧計算
???? IF ENTERBARS>0 THEN BEGIN
???????? WIN1:=(ENTERPRICE-C)/ENTERPRICE*100;
???????? IF WIN1>MAXPROFIT THEN
???????????? MAXPROFIT:=WIN1;
???????? WIN2:=(MAXPROFIT-WIN1)/MAXPROFIT*100;
???? END
?
???? //空頭初始浮虧超過 P1% 止損
???? IF WIN1<-P1 THEN
???????? SELLSHORT(1,HOLDING,LIMITR,CLOSE);
?
???? //空頭利潤大于 P2%止盈
???? IF WIN1>P2 THEN
???????? SELLSHORT(1,HOLDING,LIMITR,CLOSE);
?????
???? //空頭回撤 P3% 止盈
???? IF WIN2>P3 AND OPENPROFIT>0 THEN
???????? SELLSHORT(1,HOLDING,LIMITR,CLOSE);
// END
?
?
?
?
您這模型是圖表程序劃交易成功了,還是光看圖表成功了?
我也是個新手啊,別挑我~
?您的交易時間 從末尾時間是股指? 開盤時間是商品? VMIN = 090000;? TIME<151430;
我也復制進軟件看了看,勝率高的離譜了 都90%以上,? 還有一些問題,可能是我嫩點,沒完全讀出您的模型意思,希望您再斟酌斟酌!
?
?
因為樓主沒有搞清楚后臺自動交易的原理,所以我們采用了依舊取前臺信號,后臺下單的方法來解決問題。
希望樓主仔細研究下面的代碼,至于后臺的工作機理部分,希望樓主日后熟練使用金字塔的交易策略后再來自己嘗試編寫更復雜的后臺策略。
下面代碼紅色部分就是我們給你添加的代碼。
?
?
INPUT:P(50,2,200,1){建倉量},P1(1,0,50,1){初始止損幅度},P2(5,2,100,1){止盈幅度},P3(30,5,60,5){回撤止盈};
VARIABLE:MAXPROFIT=0,{有倉位時最大獲利幅度}VMIN = 090000;{用于隔夜高開或低開時間差}????????????????
WIN1:=0;???????????????????????????????????????????????????????????
WIN2:=0;//止盈、止損、回撤控制
?
交易時間:=TIME>VMIN AND TIME<151430;
a:=open+10;
b:=open-10;
HNL:=IF(HIGH>REF(HHV(HIGH,3),1),LOW,0);
L1:=IF(HNL>REF(L,1),REF(L,1),IF(HNL>REF(L,2),REF(L,2),IF(HNL>REF(L,3),REF(L,3),IF(HNL>REF(L,4),REF(L,4),0))));
L2:=IF(L1>REF(L,1),REF(L,1),IF(L1>REF(L,2),REF(L,2),IF(L1>REF(L,3),REF(L,3),IF(L1>REF(L,4),REF(L,4),0))));
L3:=VALUEWHEN(L2>0,L2);
LNH:=IF(LOW<REF(LLV(LOW,3),1),HIGH,99999);
H1:=IF(LNH<REF(H,1),REF(H,1),IF(LNH<REF(H,2),REF(H,2),IF(LNH<REF(H,3),REF(H,3),IF(LNH<REF(H,4),REF(H,4),99999))));
H2:=IF(H1<REF(H,1),REF(H,1),IF(H1<REF(H,2),REF(H,2),IF(H1<REF(H,3),REF(H,3),IF(H1<REF(H,4),REF(H,4),0))));
H3:=VALUEWHEN(H2>0,H2);
SEL:=VALUEWHEN((CLOSE>H3 and REF(CLOSE,1)<=H3)or(CLOSE<L3 and REF(CLOSE,1)>=L3),IF(CLOSE>H3 and REF(CLOSE,1)<=H3,1,0));
LINE:IF(SEL=1,L3,H3),COLORblue,LINETHICK2;
DRAWNUMBER(ISLASTBAR,LINE,LINE,0,COLORblue);
//建立多頭的進場條件
long:=c>a AND C>LINE ;
if long then
begin
tsellshort(holding<0,0,mkt);
sellshort(holding<0,0,MARKET);
tbuy(holding=0,lmt,a);
buy(holding=0,p,limitr,a);
end
//建立空頭的進場條件
short:=c<b AND C<LINE ;
if short then
begin
tsell(holding>0,0,mkt);
sell(holding>0,0,MARKET);
tbuyshort(holding=0,p,lmt,b);
buyshort(holding=0,p,limitr,b);
end
//盈虧計算
???? IF ENTERBARS>0 THEN BEGIN
???????? WIN1:=(C-ENTERPRICE)/ENTERPRICE*100;
???????? IF WIN1>MAXPROFIT THEN
???????????? MAXPROFIT:=WIN1;
???????? WIN2:=(MAXPROFIT-WIN1)/MAXPROFIT*100;
???? END
?
???? //多頭初始浮虧 P1% 止損
???? IF WIN1<-P1 THEN?
???? begin
????????? TSELL(1,HOLDING,MKT);?
???????? SELL(1,HOLDING,LIMITR,CLOSE);?
??????end
?
???? //多頭利潤大于 P2% 止盈
???? IF WIN1>P2 THEN?
???? begin
???????? TSELL(1,HOLDING,MKT);?
???????? SELL(1,HOLDING,LIMITR,CLOSE);?
?????end
???? //多頭獲利后回撤 P3%止盈
???? IF WIN2>P3 AND OPENPROFIT>0 THEN?
??? begin
???????? TSELL(1,HOLDING,MKT);?
???????? SELL(1,HOLDING,LIMITR,CLOSE);?
??? end
?//END
?
// IF HOLDING<0 THEN BEGIN
????
???? //空頭平倉
//???? IF 平空 THEN
//???????? SELLSHORT(1,HOLDING,LIMITR,CLOSE);
?
???? //空頭收盤平倉
??? // IF NOT(交易時間) THEN
????? //?? SELLSHORT(1,HOLDING,LIMITR,CLOSE);
?????
???? //盈虧計算
???? IF ENTERBARS>0 THEN BEGIN
???????? WIN1:=(ENTERPRICE-C)/ENTERPRICE*100;
???????? IF WIN1>MAXPROFIT THEN
???????????? MAXPROFIT:=WIN1;
???????? WIN2:=(MAXPROFIT-WIN1)/MAXPROFIT*100;
???? END
?
???? //空頭初始浮虧超過 P1% 止損
???? IF WIN1<-P1 THEN?
???? BEGIN
???????? TSELLSHORT(1,HOLDING,MKT);?
???????? SELLSHORT(1,HOLDING,LIMITR,CLOSE);?
?????END
?
???? //空頭利潤大于 P2%止盈
???? IF WIN1>P2 THEN?
???? BEGIN
???????? TSELLSHORT(1,HOLDING,MKT);?
???????? SELLSHORT(1,HOLDING,LIMITR,CLOSE);?
???? END
??????
???? //空頭回撤 P3% 止盈
???? IF WIN2>P3 AND OPENPROFIT>0 THEN?
???? BEGIN
???????? TSELLSHORT(1,HOLDING,MKT);?
???????? SELLSHORT(1,HOLDING,LIMITR,CLOSE);
?????END
// END