等级: 标准版
- 注册:
- 2021-12-10
- 曾用名:
|
一段出场的代码,我本来想写一个随着时间不断上移的出场线的,但是不知道哪里逻辑错误,好像开了仓一直就出不了场,麻烦老师帮忙看看;
假设买入开仓条件D1,卖出开仓条件K1;
出场部分代码如下:
//开仓
VARIABLE:upline:=0,dnline:=0;
bl:=2;
//atr
TR1 : =MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));
ATR := MA(TR1,14);
lots:=1;
tatr:=ref(atr,1);
IF d1 and HOLDING=0 THEN BEGIN
BUY(1,LOTS,MARKET);
dnline:=low-tatr*bl;;//最低加上一个比例乘以ATR作为初始止损;
END;
IF k1 AND HOLDING=0 THEN BEGIN
BUYSHORT(1,LOTS,MARKET);
upline:=high+bl*tatr;
END;
rc:=ref(c,1);
IF HOLDING>0 AND ENTERBARS >0 THEN BEGIN //当有持仓的情况下,止损点向下移动。
dnline:=if(c>rc,(c-rc)*0.5+dnline,dnline);
END;
IF HOLDING<0 AND ENTERBARS >0 THEN BEGIN
upline:=if(c<rc,upline-(rc-c)*0.5,upline);
END;
AA:dnline;
BB:upline;
IF HOLDING > 0 AND ENTERBARS >0 AND L <= AA THEN BEGIN
多损:sell(1,HOLDING,LIMITR,min(OPEN,AA));
END
IF HOLDING < 0 AND ENTERBARS >0 AND H >= BB THEN BEGIN
空损:SellSHORT(1,HOLDING,LIMITR,max(OPEN,bb));
END
|
|