实现功能:
1、ema均线上破水平线即平空开多,下破水平线即平多开空。
2、开仓后,如果亏损,且亏损n1个点即进行止损平仓。
3、开仓后,如果盈利,且盈利最大超过n2个点位,并回落n3个点即进行平仓,并反手开仓。
本策略仅供参考,切勿直接用于实盘。
variable:maxprofit=0; //记录仓位的最大获利
input:A(3800,1,100000,100); //定义的水平线
input:ss(1,1,50,1); //手数
input:p1(5,1,100,1); //均线变量
input:n1(10,1,100,1); //止损点位
input:n2(100,10,1000,1); //止盈点位
input:n3(25,10,1000,1); //回调点位
m1:ema(close,p1);
conpkkd:=cross(m1,A);
conpdkk:=cross(A,m1);
if conpkkd then //平空开多
begin
sellshort(holding<0,holding,market);
buy(holding=0,ss,market);
maxprofit:=0;
end
if conpdkk then //平多开空
begin
sell(holding>0,holding,market);
buyshort(holding=0,ss,market);
maxprofit:=0;
end
if holding>0 and enterprice-low>n1 then sell(1,holding,market); //多头止损
if holding<0 and high-enterprice>n1 then sellshort(1,holding,market); //空头止损
win:=0; //最大盈利变量
win2:=0; //最大回调变量
if holding>0 then
begin
win:=high-enterprice; //记录多头最大盈利
if win>maxprofit then maxprofit:=win;
win2:=maxprofit-win; //记录多头最大盈利后的回调
end
if holding<0 then
begin
win:=enterprice-low;//记录空头最大盈利
if win>maxprofit then maxprofit:=win;
win2:=maxprofit-win; //记录空头最大盈利后的回调
end
if holding>0 and maxprofit>=n1 and win2>=n2 then //多头止盈,并反手开空
begin
sell(1,holding,market);
buyshort(1,ss,market);
end
if holding<0 and maxprofit>=n1 and win2>=n2 then //空头止盈,并反手开多
begin
sellshort(1,holding,market);
buy(1,ss,market);
end
line1:A,linethick2,colorwhite; //水平线
line2:enterprice-n1*mindiff,linethick2,colorgreen; //止损线
line3:enterprice+n2*mindiff,linethick2,colorred; //止盈线
line4:enterprice+(n2-n3)*mindiff,linethick2,coloryellow; //止盈回落线