止盈部分,其他部分请自行完善。
HighPrice:hhv(HIGH,ENTERBARS+1);//最近开仓之后的最高价
FirstPrice:=ENTERPRICE;//最近的开仓价
CurrentPrice:close;//取得当前价格
Cond:=0;//判断条件
X:=ABS(CurrentPrice-HighPrice);//当前价格距离最高价的距离,用以判断是否满足止盈条件
if CurrentPrice<=FirstPrice and X>=20 then Cond:=1;
if HighPrice >=FirstPrice+20 and HighPrice<FirstPrice+50 and X >=10 then Cond:=1;
if HighPrice >=FirstPrice+50 and HighPrice<FirstPrice+80 and X >=15 then Cond:=1;
if HighPrice >=FirstPrice+80 and HighPrice<FirstPrice+200 and X >=20 then Cond:=1;
if HighPrice >=FirstPrice+200 and X >=30 then Cond:=1;
SELL(Cond,HOLDING,MARKET);//止盈止损