等级: 标准版
- 注册:
- 2021-12-10
- 曾用名:
|
楼主 |
发表于 2022-4-16 14:19
|
显示全部楼层
老师有空的话,能否帮我实现一下加仓的 分段止损问题,具体代码如下
runmode : 0 ;
// Macd
diff := ema( close,12 ) - ema( close,26 ) ;
dea := ema( diff,9 ) ;
macd := 2 * ( diff - dea ) ;
//---- 开仓条件
Bcond := ref( cross( diff,dea ),1 ),tfilter ;
//---- 平 仓
if holding > 0 and ref( cross( dea,diff ),1 ) then sell( holding > 0,holding,limitr, open - 1 * mindiff ), ignorecheckprice ;
//---- 进 场
if holding = 0 and Bcond then buy( 1,1,limitr, open + 1 * mindiff ), ignorecheckprice ;
//-- 加 仓
Addline : if( holding > 0,Intpart( enterprice - enterprice * 1.5/100 ),DRAWNULL ), coloryellow,LINEDOT ; // 加仓线
BuyAdd := low < Addline,tfilter ;
if holding > 0 and BuyAdd and count( BuyAdd,barslast( Bcond ) ) <= 1 then 加 多 : buy( 1,2,limitr, Addline + 1 * mindiff ), ignorecheckprice ;
//-- 止 损
Stopline : if( holding > 0,Intpart( enterprice - enterprice * 3/100 ),DRAWNULL ), colorgreen ;
if holding > 0 and low < Stopline then sell( holding > 0,holding,limitr, min( open - 1 * mindiff,Stopline - 1 * mindiff ) ), ignorecheckprice ;
具体问题描述,请老师查看 下面图示
|
|