上部分是系统自带的阿火k线走完交易系统,下部分是版主发的止损止盈的通用模板。两者如何相加?感谢老师!
一
{
使用该模板可以很方便的将图表程序化模型很方便的加入到后台来使用,适合哪些已经熟悉金字塔
图表程序化交易,刚刚接触后台程序化的客户
}
Globalvariable:hold=drawnull;
cc800988:=holding;//这句放在信号稳定的地方
//////以下部分改为你自己的模型(K线走完模型)////////////
/////////////////////////////////////////////////////////
buycond:=count(c>o,2)=2;
sellcond:=count(c<o,2)=2;
if holding>0 and sellcond then sell(1,1,thisclose);
if holding<0 and buycond then sellshort(1,1,thisclose);
if holding=0 and buycond then buy(1,1,thisclose);
if holding=0 and sellcond then buyshort(1,1,thisclose);
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
//下面部分是后台的部分下单代码,会根据你图表程序化上的理论持仓进行下单交易
drawtextex(1,1,800,0,'虚拟持仓为:'+numtostr(cc800988,0));//在图表上输入虚拟持仓以便监控
if not(islastbar) or workmode<>1 then exit;
xiadan800988:=cc800988-hold;
if xiadan800988>0.5 then begin
cang:=min(xiadan800988,abs(hold));
if hold<0 then begin
tsellshort(1,cang,mkt,0,0,'800988'),allowrepeat;
debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 平空 %.0f',cang);
end
cang:=xiadan800988+min(hold,0);
if cang>0 then begin
tbuy(1,cang,mkt,0,0,'800988'),allowrepeat;
debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 开多 %.0f',cang);
end
end
if xiadan800988<-0.5 then begin
cang:=min(abs(xiadan800988),abs(hold));
if hold>0 then begin
tsell(1,cang,mkt,0,0,'800988'),allowrepeat;
debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 平多 %.0f',cang);
end
cang:=abs(xiadan800988)-max(hold,0);
if cang>0 then begin
tbuyshort(1,cang,mkt,0,0,'800988'),allowrepeat;
debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 开空 %.0f',cang);
end
end
hold:=cc800988;
二
//计算获利点数
KDYL=HHV(H,ENTERBARS)-ENTERPRICE;
KKYL=ENTERPRICE-LLV(L,ENTERBARS);
//止损
IF HOLDING<0 AND (H-ENTERPRICE>40) THEN SELLSHORT(1,0,LIMITR,ENTERPRICE+40);
IF HOLDING>0 AND (L-ENTERPRICE<-40) THEN SELL(1,0,LIMITR,ENTERPRICE-40);
//动态回撤百分比
IF HOLDING<>0 AND Between(ABS(C-ENTERPrice),2,4) THEN P=10; //回撤10%止盈
IF HOLDING<>0 AND ABS(C-ENTERPrice)>=4 THEN P=5; //回撤5%止盈
//计算跟踪止盈价位,向价格不利方向取0.2整数倍
KDZY=FLOOR(KDYL*(1-P/100)*5)/5;
KKZY=CEILING(KKYL*(1-P/100)*5)/5;
//动态跟踪回撤止盈
IF HOLDING<0 AND ENTERBARS>0 AND H>KKZY AND KKYL>0 THEN SELLSHORT(1,0,LIMITR,KKZY);
IF HOLDING>0 AND ENTERBARS>0 AND L<KDZY AND KDYL>0 THEN SELL(1,0,LIMITR,KDZY);