等级: 免费版
- 注册:
- 2021-7-23
- 曾用名:
|

楼主 |
发表于 2022-1-13 12:30
|
显示全部楼层
INPUT:N(100,1,600,1);
emaN:EMA(C,N);
kd:cross(emaN,l) and ref(all(c>emaN,5),1);
kk:cross(h,emaN) and ref(all(c<emaN,5),1);
buy(kd and holding=0,1,market);
buyshort(kk and holding=0,1,market);
//平仓
SELL(CROSS(emaN,l),0,limit,c);
SELLSHORT(CROSS(h,emaN),0,limit,c);
//判断当前持仓状态下的最大盈利
win:=0;
win2:=0;
if holding > 0 and enterbars > 0 then
begin
win:=(c-enterprice)/enterprice*100; //记录最大盈利
if win>emaN,l then
emaN,l:=win;
win:=(emaN,l-win)/emaN,l*100; //最大盈利后的回调幅度
end
if holding < 0 and enterbars > 0 then
begin
win2:=(enterprice-c)/enterprice*100; //记录最大盈利
if win2 >h,emaN then
h,emaN:=win2;
win2:=(h,emaN-win)/h,emaN*100; //最大盈利后的回调幅度
end
//出现浮动亏损比如2%平仓
多止损:SELL(win < -2,0,limit,c);
空止损:SELLSHORT(win2 < -2,0,limit,c);
//出现最高盈利后,回落到盈利的60%平仓出场
多止赢:SELL(win >= 60 and openprofit > 0, 0,limit,c);
空止赢:SELLSHORT(win2 >= 60 and openprofit > 0, 0,limit,c);
变成这样 没有开空 而且也没有止损跟止盈出来 哎
|
|