代码如下:
if c>ma(c,30) then buy
if c<ma(c,30) then sell
我想跳过一次完整的买卖过程,即上两条语句,以前有使用 COUNT(c>ma(c,30),BARSLAST(c<ma(c,30)))>=2,但这只能跳过开仓信号,下一个周期还有c>ma(c,30)的话还会执行开仓,如何跳过一次完整的买卖过程呢,请老师帮助
你是要连续2次 跳过 c>ma(c,30)的开仓和c<ma(c,30)的平仓。 没能完全明白你这个需求到底是怎样的情况。可否再详细说明下。
你的意思是上一次开平仓之后跳过中间一次 满足条件的开平仓吗。等到第三次满足c>ma(c,30)再开仓。
buycond:c>ma(c,30) and holding=0;
sellcond:c<ma(c,30) and holding>0;
buy(buycond and mod(count(buycond,0),2)=1,1,market);
sell(sellcond and mod(count(buycond,0),2)=1,1,market);
这样试下吧。
老师,我试了这个代码不行,我再跟您说一下我的想法:在一次交易完成(即平仓后)获得很大收益比如1万元,我不想进行在这后面的交易(开仓+平仓),我的代码如下,但实际执行的话没有任何交易发生,该如何实现呢?
n:=numprofit(1);
m:=ma(c,30);
buycond:=cross(c,m);
sellcond:=cross(m,c);
if buycond and mod(count(buycond,barslast(n>10000)),2)=1 then buy(holding=0,1,limitr,close);
if sellcond and mod(count(sellcond,barslast(n>10000)),2)=1 then sell(1,0,limitr,close);
n:numprofit(1);
m:=ma(c,30);
buycond:cross(c,m);
sellcond:=cross(m,c);
mark:if(n>100,1,0);
len:BARSLAST(mark=0);
if buycond and (mod(count(buycond,len),2)=0 or n<=0) then buy(holding=0,1,limitr,close);
if sellcond then sell(1,0,limitr,close);
这样试下。
主要numprofit(1)一开始是0反倒限制了交易。