后臺模板套入后的問題 [金字塔]
- 咨詢內容:
環境介紹:
//運行周期:1分鐘
//運行模式:固定時間間隔,1秒輪詢
//運行品種:IF1303
會多個策略對改品種下單,希望各策略的開平倉獨立,每個策略管好自己的開平倉
系統很簡單,就是最高價突破均線平空開多,最低價突破平多開空,每根K線都只開平一次,開倉后當根K線后面的信號可以忽略
利用火哥的模板http://www.weistock.com/bbs/dispbbs.asp?boardid=10&id=9112
藍色為測試的圖表交易系統:
globalvariable:hold=drawnull;
//以下為系統內容
ss:=1; //手數
//variable:myenterbars=0;maa:ema(c,10);
tt1:=h>maa;
tt2:=l<maa;
//當開始沒有持倉
if holding=0 then begin
if tt1 then begin
buy(1,ss,market)
goto continueline;
end
if tt2 then begin
buyshort(1,ss,market);
goto continueline;
end
endif tt1 and holding<0 and enterbars>=0 then begin
sellshort(1,ss,market);
buy(1,ss,market);
goto continueline;
endif tt2 and holding>0 and enterbars>=0 then begin
sell(1,ss,market);
buyshort(1,ss,market);
goto continueline;
endcontinueline@ 資產:tasset,linethick0;
aa-tt:if(tt1,1,if(tt2,-1,0)),nodraw;
bb-holding:holding,nodraw;
cc-enterbars:enterbars,nodraw;//以上為模型內容
cc803555:=holding;//這句放在信號穩定的地方
drawtextex(1,1,800,0,'虛擬持倉為:'+numtostr(cc803555,0));//在圖表上輸入虛擬持倉以便監控
if not(islastbar) or workmode<>1 then exit;
xiadan803555:=cc803555-hold;
if xiadan803555>0.5 then begin
cang:=min(xiadan803555,abs(hold));
if hold<0 then begin
tsellshort(1,cang,mkt,0,0,'803555'),allowrepeat;
debugfile('d:\803555.txt',numtostr(hold,0)+' '+numtostr(cc803555,0)+' 平空 %.0f',cang);
end
cang:=xiadan803555+min(hold,0);
if cang>0 then begin
tbuy(1,cang,mkt,0,0,'803555'),allowrepeat;
debugfile('d:\803555.txt',numtostr(hold,0)+' '+numtostr(cc803555,0)+' 開多 %.0f',cang);
end
end
if xiadan803555<-0.5 then begin
cang:=min(abs(xiadan803555),abs(hold));
if hold>0 then begin
tsell(1,cang,mkt,0,0,'803555'),allowrepeat;
debugfile('d:\803555.txt',numtostr(hold,0)+' '+numtostr(cc803555,0)+' 平多 %.0f',cang);
end
cang:=abs(xiadan803555)-max(hold,0);
if cang>0 then begin
tbuyshort(1,cang,mkt,0,0,'803555'),allowrepeat;
debugfile('d:\803555.txt',numtostr(hold,0)+' '+numtostr(cc803555,0)+' 開空 %.0f',cang);
end
end
hold:=cc803555;運行環境:(1手單)1分鐘 IF1303 逐K模式 賬號為虛擬賬號
圖表系統單獨運行,測試正常
套入后臺模板后,有幾個問題:
1)單賬號沒有持倉的時候,交易正常
2)當我手動將賬號調成2手多頭2手空頭同時持有,再加載這個后臺系統,系統開始只會把其中的一手空倉或者多倉做反手(就是系統一直都是持有4手單),總單量沒變
3)之前在圖表加載的時候,一根K線只會執行一次開平倉,但套入后套模板后,卻會在同一K線出現多次開平倉(不知道是不是因為模板里面的allowrepeat函數問題),
請問是否將其去除就不會出現多次開平倉的問題?
- 金字塔客服:
2.今天1:30左右模擬交易服務器出了問題
3.是的,allowrepeat允許指令在同一個周期內反復發出信號.
- 用戶回復:
同樣的交易系統,我也寫了一個后臺程序:
ss:=1; //手數
extgbdataset('t1_position',0);
//0表示沒有倉位,1表示持有多頭, -1表示持有空頭
extgbdataset('t1_holding',0);
//0表示沒有倉位,>0表示持有多頭, <0表示持有空頭
extgbdataset('t1_enterbarpos',0);//記錄其開倉的K線maa:ema(c,10);
bpk:=h>maa;
spk:=l<maa;
//非最后一根K線退出
if not(islastbar) or workmode<>1 then exit;//如果當是最后一根k線,執行
IF islastbar and time<151000 then begin// 如果最后一根k線發生過開倉信號,則那一根k線不再交易
if extgbdata('t1_enterbarpos') = barpos then begin
goto continueline ;
end
//沒有持倉狀態
if extgbdata('t1_position')=0 and extgbdata('t1_holding')=0 then begin
if bpk then begin
tbuy(1,ss,mkt);
extgbdataset('t1_position',1);
extgbdataset('t1_holding',ss);
extgbdataset('t1_enterbarpos',barpos);
goto continueline ;
endif spk then begin
tbuyshort(1,ss,mkt);
extgbdataset('t1_position',-1);
extgbdataset('t1_holding',-ss);
extgbdataset('t1_enterbarpos',barpos);
goto continueline ;
end
end//沒有持倉狀態
//持有倉位狀態
//持有空頭
if bpk and extgbdata('t1_position')=-1 and extgbdata('t1_holding')<0 then begintsellshort(1,ss,mkt);
tbuy(1,ss,mkt);
extgbdataset('t1_position',1);
extgbdataset('t1_holding',ss);
extgbdataset('t1_enterbarpos',barpos);
goto continueline ;
end
//持有多頭
if spk and extgbdata('t1_position')=1 and extgbdata('t1_holding')>0 then begintsell(1,ss,mkt);
tbuyshort(1,ss,mkt);
extgbdataset('t1_position',-1);
extgbdataset('t1_holding',-ss);
extgbdataset('t1_enterbarpos',barpos);
goto continueline ;
end
END//if ISLASTBARif time>=151300 then begin
tsell(extgbdata('t1_holding')>0,ss,mkt);
tsellshort(extgbdata('t1_holding')<0,ss,mkt);
extgbdataset('t1_position',0);
extgbdataset('t1_holding',0);
endcontinueline@ 資產:tasset,linethick0;
position:=extgbdata('t1_position');
t1holding:=extgbdata('t1_holding');
debugfile('d:\debug\803555.txt','position=%.0f' ,position) ;
debugfile('d:\debug\803555.txt','t1holding=%.0f' ,t1holding) ;如果上模板不能很好執行,不知道我這個能否可行,謝謝
- 網友回復:
藍色部分少做修改,供您參考
樓主的公式,固定時間間隔,照1樓所寫,會造成信號閃爍,推薦將條件適當修改,以使信號穩定,才能使用阿火的策略
修改部分紅色顯示
ss:=1; //手數
//variable:myenterbars=0;maa:ref(ema(c,10),1);
buycond:=h>maa;
sellcond:=l<maa;if holding>0 and sellcond then sell(1,ss,market);
[此貼子已經被作者于2013-2-28 11:04:22編輯過]
if holding<0 and buycond then sellshort(1,ss,market);
if holding=0 and buycond then buy(1,ss,market);
if holding=0 and sellcond then buyshort(1,ss,market); - 網友回復:
固定時間間隔,有信號就下單,信號閃爍情況下造成HOLDING值不穩定,故不能調用圖表的HOLDING來控制倉位
必須使用后臺程序化交易,
對3樓的少做修改,供您參考
全局變量使用注意事項:
策略運行過程中,手動平倉進行干預,請到"工具--數據--全局變量"里,將對應的全局變量清0,否則會引起開平倉混亂
//序列模式運行
//t1_flag 0表示沒有倉位,1表示持有多頭,-1表示持有空頭ss:=1; //手數
maa:ema(c,5);
buycond:=h>maa;
sellcond:=l<maa;//平多
if extgbdata('t1_flag')>0 and sellcond then
begin
tsell(1,ss,mkt);
extgbdataset('t1_flag',0);
end//平空
if extgbdata('t1_flag')<0 and buycond then
begin
tsellshort(1,ss,mkt);extgbdataset('t1_flag',0);
end//開多
if extgbdata('t1_flag')=0 and buycond then
begin
tbuy(1,ss,mkt);
extgbdataset('t1_flag',1);
end//開空
if extgbdata('t1_flag')=0 and sellcond thenbegin
[此貼子已經被作者于2013-3-5 13:39:41編輯過]
tbuyshort(1,ss,mkt);
extgbdataset('t1_flag',-1);
end
有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友
可聯系技術人員 QQ: 262069696 進行 有償 編寫!(不貴!點擊查看價格!)
相關文章
-
沒有相關內容