会卖是师傅 截断亏损 让利润奔跑 通达信止盈止损主图指标 源码附图
N:=1;
X:=2;
起始:=N;
天数:=BARSLAST(起始+1000000=DATE)+1;
HX:=HHV(H,天数);
止盈:IF((HX-X)/X<=0.05,X*1.003,IF((HX-X)/X>0.05 AND (HX-X)/X<=0.1,X+(HX-X)*0.5,IF((HX-X)/X>0.1 AND (HX-X)/X<=0.15,X+(HX-X)*0.6,IF((HX-X)/X>0.15 AND (HX-X)/X<=0.2,X+(HX-X)*0.7,IF((H-X)/X>0.2 AND (HX-X)/X<=0.3,X+(HX-X)*0.8,IF((H-X)/X>0.3 ,X+(HX-X)*0.9,DRAWNULL)))))),NODRAW;
止盈线:IF(DATE>起始+1000000,止盈,DRAWNULL),LINETHICK3,COLORFF80FF;
DRAWTEXT(ISLASTBAR, 止盈, STRCAT(' <--止盈:',CON2STR(止盈,2))),COLORYELLOW;
DRAWTEXT_FIX(ISLASTBAR ,0.11,0.01,0,STRCAT('成本:',CON2STR(X,2))),COLOR4080FF;
DRAWTEXT_FIX(ISLASTBAR ,0.02,0.09,0,STRCAT('建议止盈:',CON2STR(止盈,2))),COLORFF00FF;
DRAWTEXT_FIX(ISLASTBAR ,0.10,0.09,0,STRCAT(STRCAT('止盈比例:',CON2STR((止盈/X-1)*100,2)),'%')),COLORYELLOW;
DRAWTEXT_FIX(ISLASTBAR ,0.02,0.01,0,STRCAT('建仓: 20',CON2STR(N,0))),COLORWHITE;
DRAWTEXT_FIX(ISLASTBAR ,0.18,0.01,0,STRCAT('持仓天数:',CON2STR(天数,0))),COLORFFFF00;
DRAWTEXT_FIX(ISLASTBAR ,0.02,0.17,0,STRCAT(STRCAT('日均收益:',CON2STR((C/X-1)*100/天数,2)),'%')),COLORRED;
DRAWTEXT_FIX(ISLASTBAR ,0.10,0.17,0,STRCAT(STRCAT('年化收益:',CON2STR((C/X-1)*100/天数*365,2)),'%')),COLORRED;
LX:=IF(天数>=1,REF(L,天数-1),L);
DRAWTEXT_FIX(ISLASTBAR ,0.02,0.25,0,STRCAT('建议止损:',CON2STR(LX*0.99,2))),COLOR80FF00;
DRAWTEXT_FIX(ISLASTBAR ,0.10,0.25,0,STRCAT(STRCAT('止损幅度:',CON2STR((X-LX*0.99)/X*100,2)),'%')),COLOR80FF00;
止损线:IF(DATE>起始+1000000,LX*0.98,DRAWNULL),LINETHICK3,COLOR80FF00;
DRAWTEXT(ISLASTBAR, 止损线, STRCAT(' <--止损:',CON2STR(LX*0.99,2))),COLOR80FF00;
来函数检测结果如下:
该公式没有未来函数
解密、编写股票、期货策略请联系QQ或微信同号:88652583
相关股票指标公式
原理解析:
N赋值:1
X赋值:2
起始赋值:N
天数赋值:上次起始+1000000=DATE距今天数+1
HX赋值:天数日内H最高值
输出止盈:IF((HX-X)/X<=0.05,X*1.003,IF((HX-X)/X>0.05 AND (HX-X)/X<=0.1,X+(HX-X)*0.5,IF((HX-X)/X>0.1 AND (HX-X)/X<=0.15,X+(HX-X)*0.6,IF((HX-X)/X>0.15 AND (HX-X)/X<=0.2,X+(HX-X)*0.7,IF((H-X)/X>0.2 AND (HX-X)/X<=0.3,X+(HX-X)*0.8,IF((H-X)/X>0.3 ,X+(HX-X)*0.9,DRAWNULL)))))),NODRAW
如果DATE>起始+1000000返回止盈否则返回DRAWNULL
DRAWTEXT(ISLASTBAR, 止盈, STRCAT(' <--输出止盈:',CON2STR(止盈,2))),画黄色
DRAWTEXT_FIX(ISLASTBAR ,0.11,0.01,0,STRCAT('成本:',CON2STR(X,2))),COLOR4080FF
DRAWTEXT_FIX(ISLASTBAR ,0.02,0.09,0,STRCAT('建议输出止盈:',CON2STR(止盈,2))),COLORFF00FF
DRAWTEXT_FIX(ISLASTBAR ,0.10,0.09,0,STRCAT(STRCAT('止盈比例:',CON2STR((止盈/X-1)*100,2)),'%')),画黄色
DRAWTEXT_FIX(ISLASTBAR ,0.02,0.01,0,STRCAT('建仓: 20',CON2STR(N,0))),画白色
DRAWTEXT_FIX(ISLASTBAR ,0.18,0.01,0,STRCAT('持仓输出天数:',CON2STR(天数,0))),COLORFFFF00
DRAWTEXT_FIX(ISLASTBAR ,0.02,0.17,0,STRCAT(STRCAT('日均收益:',CON2STR((C/X-1)*100/天数,2)),'%')),画红色
DRAWTEXT_FIX(ISLASTBAR ,0.10,0.17,0,STRCAT(STRCAT('年化收益:',CON2STR((C/X-1)*100/天数*365,2)),'%')),画红色
LX赋值:IF(天数>=1,天数-1日前的L,L)
DRAWTEXT_FIX(ISLASTBAR ,0.02,0.25,0,STRCAT('建议止损:',CON2STR(LX*0.99,2))),COLOR80FF00
DRAWTEXT_FIX(ISLASTBAR ,0.10,0.25,0,STRCAT(STRCAT('止损幅度:',CON2STR((X-LX*0.99)/X*100,2)),'%')),COLOR80FF00
如果DATE>起始+1000000返回LX*0.98否则返回DRAWNULL
DRAWTEXT(ISLASTBAR, 止损线, STRCAT(' <--止损:',CON2STR(LX*0.99,2))),COLOR80FF00