老师好,KD金叉,收盘价在MA40日之上,开多1手,收盘价连续2根K线在MA20之下,平多1手;KD死叉,收盘价在MA40之下,开空1手,收盘价连续2根在MA20之上,平空。每日收盘后不论涨跌全部平仓,这个公式怎么写。谢谢!
参考下面的范例:
input:n(9,1,100,10),p1(3,2,40,4),p2(3,2,40,4);//参数设置
RSV:=(CLOSE-LLV(LOW,N))/(HHV(HIGH,N)-LLV(LOW,N))*100;
K:SMA(RSV,P1,1);
D:SMA(K,P2,1);
J:3*K-2*D;
ma40:ma(c,40);//40周期均线
ma20:ma(c,20);
kdjjc:cross(k,d);//kdj金叉
kdjsc:cross(d,k);
if count(c<ma20,2)=2 then sell(holding>0,holding,market);//平多
if c>ma40 and kdjjc then
begin
buy(holding=0,1,MARKET);
end
if count(c>ma20,2)=2 then sellshort(holding<0,holding,market);//平空
if c<ma40 and kdjsc then
begin
buyshort(holding=0,1,MARKET);
end
if time=CLOSETIME(0) then //收盘平仓,日线以上周期无效。
begin
sell(holding>0,holding,market);
sellshort(holding<0,holding,market);
end