//限价止损
{IF h>=ENTERPRICE+D*mindiff and HOLDING<0 THEN BEGIN//D---D个价位止损
SELLshort(HOLDING<0,HOLDING,stopr,ENTERPRICE+D*mindiff);//止空
END;
IF l<=ENTERPRICE-D*mindiff and HOLDING>0 THEN BEGIN//D---D个价位止损
SELL(HOLDING>0,HOLDING,stopr,ENTERPRICE-D*mindiff);//止多
END;}
//追踪止损
{
stps:ref(if(holding<0,if(enterprice-llv(l,openbar)>=mindiff*step,enterprice+d*mindiff-CEILING((enterprice-llv(l,openbar))/mindiff/step)*step*mindiff,enterprice+d*mindiff),drawnull),1);
stpl:ref(if(holding>0,if(hhv(h,openbar)-enterprice>=mindiff*step,floor(((hhv(h,openbar)-enterprice)/mindiff/step))*step*mindiff+enterprice-d*mindiff,enterprice-d*mindiff),drawnull),1);
IF h>=stps and HOLDING<0 THEN BEGIN//D---D个价位止损;step---步长;stps----空单止损位;
SELLshort(HOLDING<0,HOLDING,stopr,stps);//止空
END;
IF l<=stpl THEN BEGIN//D---D个价位止损;step---步长;stpl----多单止损位;
SELL(HOLDING>0,HOLDING,stopr,stpl);//止多
END;
}
//限价止损+追踪止盈
{
stps:ref(if(holding<0,if(llv(l,openbar)>=enterprice-dd*mindiff-step*mindiff,enterprice+d*mindiff,llv(l,openbar)+step*mindiff),drawnull),1);
stpl:ref(if(holding>0,if(hhv(h,openbar)<=enterprice+dd*mindiff+step*mindiff,enterprice-d*mindiff,hhv(h,openbar)-step*mindiff),drawnull),1);
IF h>=stps and HOLDING<0 THEN BEGIN//D---D个价位止损;step---步长;stps----空单止损位;dd---dd个价位止盈;
SELLshort(HOLDING<0,HOLDING,stopr,stps);//止空
END;
IF l<=stpl THEN BEGIN//D---D个价位止损;step---步长;stpl----多单止损位;dd---dd个价位止盈;
SELL(HOLDING>0,HOLDING,stopr,stpl);//止多
END;
}
input:d(20,5,60,1);
input:dd(5,5,60,1);
input:step(20,5,40,1);
ma1:ma(c,10);
ma2:ma(c,20);
buy(holding=0 and cross(ma1,ma2),thisclose);
stps:ref(if(holding<0 and openbar>=0,if(enterprice-llv(l,openbar+1)>=mindiff*step,enterprice+d*mindiff-CEILING((enterprice-llv(l,openbar+1))/mindiff/step)*step*mindiff,enterprice+d*mindiff),drawnull),1);
stpl:ref(if(holding>0 and openbar>=0,if(hhv(h,openbar+1)-enterprice>=mindiff*step,floor(((hhv(h,openbar+1)-enterprice)/mindiff/step))*step*mindiff+enterprice-d*mindiff,enterprice-d*mindiff),drawnull),1);
IF h>=stps and HOLDING<0 THEN BEGIN//D---D个价位止损;step---步长;stps----空单止损位;
SELLshort(HOLDING<0,HOLDING,stopr,stps);//止空
END;
IF l<=stpl THEN BEGIN//D---D个价位止损;step---步长;stpl----多单止损位;
SELL(HOLDING>0,HOLDING,stopr,stpl);//止多
END;
开仓历时:openbar,linethick0;
test:hhv(h,openbar+1),linethick0;
==================
主贴的源码有点问题~
主要出在开仓后第一个周期openbar返回0结果HHV求出的是所有周期的最大值...
我以前写好的是用enterbars的后来改的不见了~
上面这个源码仅用于测试...
大家用之前先看看文华的策略介绍
然后再仔细看下这个源码是如何运算的..