等级: 超级版主
- 注册:
- 2021-5-18
- 曾用名:
- FireScript
|
input:m1(4,1,100,10),m2(8,1,100,10),m3(16,1,100,10),m4(32,1,100,10);
bbi:(ma(close,m1)+ma(close,m2)+ma(close,m3)+ma(close,m4))/4;
input:ss(5,1,100,1);//开仓手数;
cz:abs(bbi-ref(bbi,1));
up:bbi>ref(bbi,1);
down:bbi<ref(bbi,1);
平空开多:up and ref(up,1) and c>bbi and cz>ref(cz,1);
平多开空:down and ref(down,1) and c<bbi and cz>ref(cz,1) ;
variable:maxprofit=0;//有仓位时最大获利幅度 //普通开仓
if 平空开多 then begin
sellshort(holding<0,0,marketr);
buy(holding=0,1,marketr); maxprofit:=0;
end
if 平多开空 then
begin
sell(holding>0,0,marketr);
buyshort(holding=0,1,marketr);
maxprofit:=0;
end
//判断当前持仓状态下的最大盈利
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,marketr); //出现最高盈利后,回落到盈利的60%平仓出场
止赢:sell(win2 >= 60 and openprofit > 0, 0,marketr);
另做了调整,过滤 bbi从涨到跌时候 cz也可能是增长的情况。 |
|