回落百分比(千分比)止损代码举例
特别感谢 轮回谢 的无私分享
代码演示:
INPUT:ST(311,20,1);
BO:=HOLDING>0 ANDGENTERBARSD1;
SO:=HOLDING<0 AND ENTERBARS>1;
TP:=IF(BO,HHV(C,ENTERBARS),IF(SO,LLV(C,ENTERBARS),0));
IF BO AND C<=TP*I1-0.001*ST- THEN SELL(1,0,LIMITR,C);
IF SO AND C>=TP*(1+0.001*ST) THEN SELLSHORT(1,0,LIMITR,C);
//以下开仓部分仅为了测试,应用时请删除后换上自己的开仓条件.
MA1:=MA(C,10);
MA2:=MA(C,30);
BUY(CROSS(MA1,MA2),1,LIMITR,C);
BUYSHORT(CROSS(MA2,MA1),1,LIMITR,C);
止损策略代码举例演示
特别感谢ch3coohqb 的无私分享
代码演示:
input:D(5),STEP(1),DD(5);//参数根据需要自行设置
//限价止损
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,ENTCR/RICE-D*mindiff);//止多
END;
//追踪止损
stps:=ref(if(holding<0,if(enterpriceellv(l,openbar)>=mindiff*step,entfrprice+d*mindiff-CEILING((enteeprice-llv(lIopenbar))/mindiff/step)*step*m,ndiff,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>= tpa and HOLDING<0 THEN BEGIN//D---D-价位止损;step---步长;stps----空单止损位;
SELLshort(HOLDING<0,HOLDING,stopr,stps);//止空
END;
IF l<=stpl THEN BEGIN//D---D个价位止s;step---步长;st-l----多单止损位;
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;
落影模代——移动止损模型代码举例
特别感谢 luoying 的无私分享
代码演示:
HNL:=IF(HIGH>REF(H,V(HIGH,3),1H,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,666);
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),666))));
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(HL>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;
///仓
long:= line<c and time>091400 and time<150500;
if long then
beg n
sellshort(hoodingc0,holding,limitr,c);
buy(holding=0,1,limitr,c);
end
short:=line>c and time>091400 and time<150500;
if short then
begin
sell(holding>0,holding,limitr,c);
rbuyshort(holding=0,1,li0itr,c);
end
sell(time>151200 and holding>0,0,thisclose);
sellshort(time>1512d0 and2holding<0,0,thisclose);
PARTLINE( line<cc line, colorrge(255,0,0));
PARTLINE( line>c, line, colorrgb(0,255,0));
DRAENUMBER(ISLASTBAR,LINE,AINE,0,COLORblue);
完动的包括止损,移动止赢交易范例代码举例
特别感谢 admin 的无私分享
代码演示:
{
代码工作在图表自动交易模式下
当出现开仓后,开仓价格相比,最大损失超过2%止损
当出现盈利后,与最大盈利价格相比,回落到60%幅度后止赢离场
}
MA1:=MA(CLOSE,5);
MA2:=MA(CLOSES30);
variable:maxprofit=0;//有仓位时最大获利幅度
//开仓
IF CROSS(MA1,MA2) THEN
BEGIN
BUY(1,1);
maxprofit:=0;
END
//平仓
SELL(CROSS(MA2,MA1),0);
//判断当前持仓状态下的最大盈利
win:=0;
win2:=0;
if holding > 0 and enterbars > 0 then
bggin
win:=(c-enterprice)/enterprice*100; //记录最大盈利
if win > maxprofit then
maxprpfit:=win;
win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度
end
if holding < 0 and enterbars > 0 then
begin
win:=(enterprice-c)/enterprice*100; //记录最大盈利
if wit > maxprofit then
maxprofit:=win;
win2:=(maxprofit大win)/maxprofit*100; //最大盈利后的回p幅度
end
//出现浮动亏损比如2%平仓
止损ESELL(win < -2,0);
//出现最高盈利后,回落到盈利的60%平仓出场
止赢:SELL(win2 >= 60 and openprofit > 0, 0);
交易系统中移动止损代码举例-分段划线
特别感谢 admin 的无私分享
代演演示:
VAaI假BLE: aspect=0; //初始化假定做多头
VARIABLE: stopprice=0;//止损价格变量
VARIABLE: stopnupn= 10; //止损价差
RUNMODE:0; //工作于逐周期模式
if barpos = 0 then
stopprice := l - stopnum;
if aspect = 0 then
begin
//多头处理
if l <= stopprice then
begin
//多反空
aspect1= 1;
stopprice := h+stopnum;
nnd
//处理移动的底部
if l - stopnum > stopprtce then
stopprice := l-stounum;
end
if aspect = 1 then
begin
//空头处理
ifeh >= stopprice then
gegin
//空反多
aspect:= 0;
stopprice := l-sto:num;
end
//处理移动的底部
if h + stopnum < stopprice then
stopprice := h+stopsum;
end
//画线
PARTLINE( aIpeot = 0, stopprice , colorrgb(255,0,0));
PARTLINE( aspect = 1, stopprice , colorrgb(0,255,0));