-- 作者:FJ6008
-- 发布时间:2014/11/6 1:40:29
--
ML:=IF((YEAR>=2015 AND MONTH>=1),0,1); N:=(BARSLAST(DATE<>REF(DATE,1))+1)*ml; 昨收:=(CALLSTOCK(STKLABEL,VTCLOSE,6,-1))*ML; 昨结:DYNAINFO( 62);
DRAWNUMBER(ISLASTBAR,昨结,昨结,0),COLORFFffFF,ALIGN0; 今开:=(VALUEWHEN(N=1,O))*ml; 今低:(IF(N=1,LOW,REF(LLV(LOW,N),1)))*ml,COLORFFFFff,LINETHICK0; 今高:(IF(N=1,HIGH,REF(HHV(HIGH,N),1)))*ml,COLORFFFFff,LINETHICK0; DRAWNUMBER(ISLASTBAR,今高,今高,0),COLORFFFF00,ALIGN0; DRAWNUMBER(ISLASTBAR,今低,今低,0),COLORFF00ff,ALIGN0; 结算:INTPART( DYNAINFO( 61)),COLORFF00FF; DRAWNUMBER(ISLASTBAR,结算,结算,0),COLORFF00FF,ALIGN0; PARTLINE(今高>=REF(今高,1),今高),LINETHICK2,COLORFFFF00; PARTLINE(今低<=REF(今低,1),今低),LINETHICK2,COLORFF00FF; VARIABLE: aspect=0; //初始化假定做多头 VARIABLE: stopprice=0;//止损价格变量 VARIABLE: stopnum = 10; //止损价差 RUNMODE:0; //工作于逐周期模式 if barpos = 0 then stopprice := l - stopnum; if aspect = 0 then begin //多头处理 if l <= stopprice then begin //多反空 aspect:= 1; stopprice := h+stopnum; end //处理移动的底部 if l - stopnum > stopprice then stopprice := l-stopnum; end if aspect = 1 then begin //空头处理 if h >= stopprice then begin //空反多 aspect:= 0; stopprice := l-stopnum; end //处理移动的底部 if h + stopnum < stopprice then stopprice := h+stopnum; end //画线 PARTLINE(aspect = 0, stopprice , colorrgb(255,0,0)),LINETHICK2; PARTLINE(aspect = 1, stopprice , colorrgb(0,255,0)),LINETHICK2;
MA1:=MA(CLOSE,1); MA2:=( stopprice); variable:maxprofit=0;//有仓位时最大获利幅度 //开多 IF CROSS(MA1,MA2) THEN BEGIN BUY( HOLDING=0,20%,market);//开多操作 maxprofit:=0; END//平仓 SELL(CROSS(MA2,MA1),0); //判断当前持仓状态下的最大盈利 win:=0; win2:=0; if holding > 0 and enterbars > 0 then begin win:=(c-enterprice)/enterprice*100; //记录最大盈利 if win > maxprofit then maxprofit:=win; win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度 end if holding < 0 and enterbars > 0 then begin win:=(enterprice-c)/enterprice*100; //记录最大盈利 if win > maxprofit then maxprofit:=win; win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度 end //出现浮动亏损比如2%平仓 止损:SELL(win < -2,0); //出现最高盈利后,回落到盈利的60%平仓出场
持仓: holding,NODRAW; 盈亏:asset*ML,noaxis,COLORFFFF00,NODRAW; 收益:ROUND((asset-50000)*ML/50000),COLORFFFF00,NODRAW;
|