参考下面代码实现方式。
variable:lossnum=0;// 全局变量,平仓时判断一下是盈利/亏损,若亏损lossnum就加1
VARIABLE:ss=1;//初始手数
ma5:=ma(close,5);
ma10:=ma(close,10);
cond1:=cross(ma5,ma10);
cond2:=cross(ma10,ma5);
if cond2 and holding>0 then
begin
sell(1,HOLDING,MARKET);
if c<enterprice then lossnum:=lossnum+1;
if c>enterprice then lossnum:=0;
end
jcss:=SS*IF(lossnum=0,SS,if(lossnum<3,LOSSNUM,3));
if cond1 then buy(1,jcss,MARKET);
variable:lossnum=0;// 全局变量,平仓时判断一下是盈利/亏损,若亏损lossnum就加1
VARIABLE:ss=1;//初始手数
cond1:=KD;// 开多
cond2:=PD;// 平多
cond3:=KK;// 开空
cond4:=PK;// 平空
////////////////////多单交易
if cond2 and holding>0 then// 平多
begin
sell(1,HOLDING,MARKET);// 平多
if c<enterprice then lossnum:=lossnum+1;
if c>enterprice then lossnum:=0;
end
jcss:=SS*IF(lossnum=0,SS,if(lossnum<3,LOSSNUM,3));
if cond1 then buy(1,jcss,MARKET);// 开多
////////////////////空单交易
if cond4 and holding>0 then// 平空
begin
SELLSHORT(1,HOLDING,MARKET);// 平空
if c>enterprice then lossnum:=lossnum+1;
if c<enterprice then lossnum:=0;
end
jcss:=SS*IF(lossnum=0,SS,if(lossnum<3,LOSSNUM,3));
if cond3 then BUYSHORT(1,jcss,MARKET);// 开空
帮忙看看是那里不对呢?
你多空盈亏是希望一起计算的?
你先理解下我给你的代码,如果修改后也应该是您直接说明什么地方不满足你的思想。
开多条件,平多条件,开空条件,平空条件,都不一样的。
是多空一起计算盈亏次数,谢谢。
怎么不对的,说清楚些。
上面的逻辑中,盈利后,手数会被重置为初始手数
发不了图片,按以下写法,K线图上显示全部是做空的单子,麻烦看看那里写得不对,谢谢。
variable:lossnum=0;// 全局变量,平仓时判断一下是盈利/亏损,若亏损lossnum就加1
VARIABLE:ss=1;//初始手数
ma5:ma(c,5);
ma10:ma(c,10);
ma20:ma(c,20);
ma30:ma(c,30);
cond1:=cross(ma5,ma10);// 开多
cond2:=cross(ma10,ma5);// 平多
cond3:=cross(ma30,ma20);// 平空
cond4:=cross(ma20,ma30);// 开空
////////////////////////////////////////////////-----多
if cond2 and holding>0 then// 平多
begin
sell(1,HOLDING,MARKET);// 平多
if c<enterprice then lossnum:=lossnum+1;
if c>enterprice then lossnum:=0;
end
jcss:=SS*IF(lossnum=0,SS,if(lossnum<3,LOSSNUM,3));
if cond1 then buy(1,jcss,MARKET);// 开多
////////////////////////////////////////////////-----空
if cond3 and holding>0 then// 平空
begin
SELLSHORT(1,HOLDING,MARKET);// 平空
if c>enterprice then lossnum:=lossnum+1;
if c<enterprice then lossnum:=0;
end
jcss:=SS*IF(lossnum=0,SS,if(lossnum<3,LOSSNUM,3));
if cond4 then BUYSHORT(1,jcss,MARKET);// 开空
/////////////////-----以下空白
有开多信号的,用这种方式看下当条件满足时候,图表不支持锁仓,如果有空仓情况下是不能开多的,全部按照反手来处理
cc:cond1;
if cond1 then
begin
sellshort(1,holding,marketr);
buy(1,jcss,MARKET);// 开多
end