此主题相关图片如下:2.jpg

runmode:0;input:N1(5),N2(11),InitalStop(0.2),BreakEventStop(0.2),
TrailingStop(0.5),ntimes(4),everylots(1);
variable:bcrossup :=0;
variable:bcrossdown :=0;
nshort : ema((high+low+2*close)/4,n1);
nlong : ema((hhv(high,n2)+llv(low,n2)),n2)/2;
blongEntryCon : cross(nshort,nlong) and nshort>ref(nshort,1) and nlong>ref(nlong,1);
bshortentrycon :cross(nlong,nshort) and nshort<ref(nshort,1) and nlong<ref(nlong,1);
bReLongCon := nshort>ref(nshort,1) and nlong>ref(nlong,1) and nshort>nlong and high>hhv(HIGH[1],N1) and close>nlong;
bReShortCon := nshort<ref(nshort,1) and nlong<ref(nlong,1) and nshort<nlong and low<llv(low[1],N1) and close<nlong;
nhighswing :=hhv(high,enterbars);
nLowSwing :=llv(low,enterbars);
if holding>0 then
begin
stopline :=avgenterprice*(1-InitalStop/100);
if nhighswing>avgenterprice * (1+BreakEventStop/100) then stopline :=avgenterprice;
else if StopLine < nHighSwing*(1-TrailingStop/100) then stopline :=nHighSwing*(1-TrailingStop/100);
else if stopline>=(close+low+2*high)/4 then
begin
myprice := stopline;
if thisclose<myprice then myprice:=thisclose;
风险平多: sell(holding>0,everylots,myprice);
end;
if bshortentrycon then 指标平多 : sell(holding>0,everylots,thisclose);
end
if holding<0 then
begin
StopLine :=avgenterprice*(1+InitalStop/100);//初始止损
If nLowSwing <= avgenterprice * (1-BreakEventStop/100) then StopLine := avgenterprice;
else If StopLine > nLowSwing*(1+TrailingStop/100) then StopLine := nLowSwing*(1+TrailingStop/100);//// 追踪止损的价位超过保本止损价,止损价随盈利峰值价的上升同步提高
else If((high+low*2+close)/4 >= StopLine) then
begin
MyPrice = StopLine;
If thisclose < MyPrice then MyPrice = thisclose;
风险平空: sellshort(1 and holding<0,EveryLots,MyPrice);
end
if bLongEntryCon then 指标平空: sellshort(1 and holding<0,EveryLots,thisclose);
end
if holding=0 then
begin
if blongentrycon then 指标开多仓:buy(1 and holding=0,everylots,thisclose);//(blongentrycon and holding=0,everylots,market);
if bshortentrycon then 指标开空仓:buyshort(1 and holding=0,everylots,thisclose);//(bshortentrycon and holding=0,everylots,market);
if brelongcon then 指标继续开多仓:buy(1 and holding=0,everylots,thisclose);//(brelongcon and holding=0 ,everylots,market);
if bReShortCon then 指标继续开空仓:buyshort(1 and holding=0,everylots,thisclose);//(bReShortCon and holding=0,everylots,market);
end
资产:ASSET,NOAXIS;
可用现金:CASH(0),LINETHICK0;
持仓:HOLDING,LINETHICK0;