1、开仓(A,开多;B,开空;有持仓条件成立也不开仓、前面平仓是止损平仓时开仓手数是亏损仓位的2倍、最多仓位开到32手、是盈利平仓时就开1手,)。
2、平仓(止损止盈平仓,10点止损30点止盈,收盘平仓1458时间平仓)。
3、要可以全自动交易。
谢谢!
开仓条件是什么?
开仓条件就是A与B,我自己会编,我就是要学会怎样编后面的源码
前面平仓是止损平仓时开仓手数是亏损仓位的2倍、最多仓位开到32手、是盈利平仓时就开1手
这句话能否详细的讲解一下,不明白
td:= (time>=090000 and time<=145800);
variable:aa=1,bb=1;
if A and td then buy(holding=0,1,thisclose);
if B and td then buyshort(holding=0,1,thisclose);
//止损止盈平仓,10点止损30点止盈
if c-enterprice >=30 or enterprice-c>=10 then
sell(holding>0,0,thisclose);
if enterprice-c>=30 or c-enterprice>=10 then
sellshort(holding<0,0,thisclose);
if numprofit(1)>0 and A and td then buy(holding=0,1,thisclose);
if numprofit(1)>0 and B and td then buyshort(holding=0,1,thisclose);
if numprofit(1)<0 and A and td and aa<=32 then begin
buy(holding=0,aa,thisclose);
aa:=aa*2;
end
if numprofit(1)<0 and b and td and bb<=32 then begin
buyshort(holding=0,bb,thisclose);
bb:=bb*2;
end
if time>145800 then begin
sell(holding>0,0,thisclose);
sellshort(holding<0,0,thisclose);
end
if time>=150000 then begin
aa:=1;
bb:=1;
end
我加载试试,(前面一次平仓如果是亏损平仓,接下来的开仓就是前面平仓手数的2倍,如果是盈利平仓,接下来的开仓就是1手)。
模型与我的要求不一致。模型每次开仓都是1手,我要的是前面亏损平仓,接下来就开前面仓位的2倍,直到32手。前面盈利平仓就回到1手开仓
不好意思,上面写得逻辑不够严密,刚改了下,再试试
variable:aa=2,bb=2,cc=0,dd=0;
td:= (time>=090000 and time<=145800);
if A and td and cc=0 then begin
buy(holding=0,1,thisclose);
cc:=1;
end
if B and td and dd=0 then begin
buyshort(holding=0,1,thisclose);
dd:=1;
end
//止损止盈平仓,10点止损30点止盈
if c-enterprice >=30 or enterprice-c>=10 then
sell(holding>0,0,thisclose);
if enterprice-c>=30 or c-enterprice>=10 then
sellshort(holding<0,0,thisclose);
if numprofit(1)>0 and A and td and cc=1 then buy(holding=0,1,thisclose);
if numprofit(1)>0 and B and td and dd=1 then buyshort(holding=0,1,thisclose);
if numprofit(1)<0 and A and td and aa<=32 and cc=1 then begin
buy(holding=0,aa,thisclose);
aa:=aa*2;
end
if numprofit(1)<0 and b and td and bb<=32 and dd=1then begin
buyshort(holding=0,bb,thisclose);
bb:=bb*2;
end
if time>145800 then begin
sell(holding>0,0,thisclose);
sellshort(holding<0,0,thisclose);
end
if time>=150000 then begin
aa:=2;
bb:=2;
cc:=0;
dd:=0;
end
//1分钟K线
variable:buynum=1,sellnum=1;//控制开多和开空的数量
ma5:ma(close,5);
ma20:ma(close,20);
long:=cross(ma5,ma20) and time>090100 and time<145800;
short:=cross(ma20,ma5) and time>090100 and time<145800;
if long and holding=0 then buy(1,buynum,thisclose);
//止损止盈平仓,10个最小变动价位止损,30个最小变动价位止损止盈
if c>enterprice+30*mindiff and holding>0 and enterbars>2 then
begin
多赢:sell(1,0,thisclose);
buynum:=1;
end
if c<enterprice-10*mindiff and holding>0 and enterbars>2 then
begin
多损:sell(1,0,thisclose);
buynum:=2*buynum;
end
if short and holding=0 then buyshort(1,sellnum,thisclose);
if c<enterprice-30*mindiff and holding<0 and enterbars>2 then
begin
空赢:sellshort(1,0,thisclose);
sellnum:=1;
end
if c>enterprice+10*mindiff and holding<0 and enterbars>2 then
begin
空损:sellshort(1,0,thisclose);
sellnum:=2*sellnum;
end
if time>=145800 then
begin
sell(holding>0,0,thisclose);
sellshort(holding<0,0,thisclose);
end
if time>=150000 then
begin
buynum:=1;
sellnum:=1;
end
还是不对,下面一种就开到2手,又回到1手了