如下代码在K线图中无交易信号显示,策略测试也没有交易记录,请金字塔的老师们帮找原因
DIFF:=EMA(CLOSE,12) - EMA(CLOSE,26);
DEA:=EMA(DIFF,9);
MACD1:=2*(DIFF-DEA);
LC := REF(CLOSE,1);
m1:=SMA(MAX(CLOSE-LC,0),3,1)/SMA(ABS(CLOSE-LC),3,1)*100;
m2:=-100*(HHV(HIGH,42)-CLOSE)/(HHV(HIGH,42)-LLV(LOW,42))+100;
enlong:=count(cross(m1,10),5)>1 and count(cross(m2,10),2)>1 and cross(diff,ref(diff,1))
or count(cross(m1,10),2)>1 and count(cross(m2,10),5)>1 and cross(diff,ref(diff,1));//开多条件
enshort:=count(cross(90,m1),5)>1 and count(cross(90,m2),2)>1 and cross(ref(diff,1),diff)
or count(cross(90,m1),2)>1 and count(cross(90,m2),5)>1 and cross(ref(diff,1),diff);//开空条件
exlong1:=cross(90,m1) or cross(90,m2) or cross((enterprice-c),3);//平多条件1
exshort1:=cross(m2,10) or cross(m2,10) or cross((c-enterprice),3);//平空条件1
exlong2:=barslast(enlong)>10 and (c-enterprice)<0;//平多条件2(以限价单来平仓)
exshort2:=barslast(enshort)>10 and (c-enterprice)>0;//平多条件2(以限价单来平仓)
if enlong then
begin
buy(holding=0,1,market);
end
if exshort1 then
begin
sell(holding=1,0,market);
end
if enshort then
begin
buyshort(holding=0,1,market);
end
if exshort1 then
begin
sellshort(holding=-1,1,market);
end
if exlong2 then
begin
sell(holding=1,0,limit,enterprice+2*mindiff);
end
if exshort2 then
begin
sellshort(holding=-1,0,limit,enterprice-2*mindiff);
end
多笔线、股指
你写的条件太苛刻了 一直都不成立
例如enlong 从来都没成立 当然不会下单了
enlong:=count(cross(m1,10),5)>1 and count(cross(m2,10),2)>1 and cross(diff,ref(diff,1))
or count(cross(m1,10),2)>1 and count(cross(m2,10),5)>1 and cross(diff,ref(diff,1));//开多条件
开多条件其实分为两个,中间有or分开。
我自己在K线图和指标中,能够看得到有开仓机会的。你可以将开仓条件的公式做成之表现来看看。
我将开仓条件改了一下,有出现开仓信号,但是平仓信号预想的一样
DIFF:=EMA(CLOSE,12) - EMA(CLOSE,26);
DEA:=EMA(DIFF,9);
MACD1:=2*(DIFF-DEA);
LC := REF(CLOSE,1);
m1:=SMA(MAX(CLOSE-LC,0),3,1)/SMA(ABS(CLOSE-LC),3,1)*100;
m2:=-100*(HHV(HIGH,42)-CLOSE)/(HHV(HIGH,42)-LLV(LOW,42))+100;
enlong:=count(cross(m1,10),5)>=1 and count(cross(m2,10),2)>=1 and cross(diff,ref(diff,1))
or count(cross(m1,10),2)>=1 and count(cross(m2,10),5)>=1 and cross(diff,ref(diff,1));//开多条件
enshort:=count(cross(90,m1),5)>=1 and count(cross(90,m2),2)>=1 and cross(ref(diff,1),diff)
or count(cross(90,m1),2)>=1 and count(cross(90,m2),5)>=1 and cross(ref(diff,1),diff);//开空条件
exlong1:=cross(90,m1) or cross(90,m2) or cross((enterprice-c),3);//平多条件1
exshort1:=cross(m2,10) or cross(m2,10) or cross((c-enterprice),3);//平空条件1
exlong2:=barslast(enlong)>10 and (c-enterprice)<0;//平多条件2(以限价单来平仓)
exshort2:=barslast(enshort)>10 and (c-enterprice)>0;//平多条件2(以限价单来平仓)
if enlong then
begin
buy(holding=0,1,market);
end
if exshort1 then
begin
sell(holding=1,0,market);
end
if enshort then
begin
buyshort(holding=0,1,market);
end
if exshort1 then
begin
sellshort(holding=-1,1,market);
end
if exlong2 then
begin
sell(holding=1,0,limit,enterprice+2*mindiff);
end
if exshort2 then
begin
sellshort(holding=-1,0,limit,enterprice-2*mindiff);
end
那就只能跟踪你的各个条件的值来看条件是否成立了.如果开平仓条件成立,肯定会有信号的.
注意各个条件,按远近,用括号隔离开.
我将平仓条件做了注释,是不是语句未正确表达我的意思呢
DIFF:=EMA(CLOSE,12) - EMA(CLOSE,26);
DEA:=EMA(DIFF,9);
MACD1:=2*(DIFF-DEA);
LC := REF(CLOSE,1);
m1:=SMA(MAX(CLOSE-LC,0),3,1)/SMA(ABS(CLOSE-LC),3,1)*100;
m2:=-100*(HHV(HIGH,42)-CLOSE)/(HHV(HIGH,42)-LLV(LOW,42))+100;
enlong:=count(cross(m1,10),5)>=1 and count(cross(m2,10),2)>=1 and cross(diff,ref(diff,1))
or count(cross(m1,10),2)>=1 and count(cross(m2,10),5)>=1 and cross(diff,ref(diff,1));//开多条件
enshort:=count(cross(90,m1),5)>=1 and count(cross(90,m2),2)>=1 and cross(ref(diff,1),diff)
or count(cross(90,m1),2)>=1 and count(cross(90,m2),5)>=1 and cross(ref(diff,1),diff);//开空条件
exlong1:=cross(90,m1) or cross(90,m2) or cross((enterprice-c),3);//平多条件1
exshort1:=cross(m2,10) or cross(m2,10) or cross((c-enterprice),3);//平空条件1
exlong2:=barslast(enlong)>10 and c<enterprice;//平多条件2(以限价单来平仓),当距离开仓K线大于10个周期,并且最新价格小于开仓价。
exshort2:=barslast(enshort)>10 and c>enterprice;//平多条件2(以限价单来平仓),当距离开仓K线大于10个周期,并且最新价格大于开仓价。
if enlong then
begin
buy(holding=0,1,market);
end
if exshort1 then
begin
sell(holding=1,0,market);
end
if enshort then
begin
buyshort(holding=0,1,market);
end
if exshort1 then
begin
sellshort(holding=-1,1,market);
end
if exlong2 then
begin
sell(holding=1,0,limit,enterprice+2*mindiff);
end
if exshort2 then
begin
sellshort(holding=-1,0,limit,enterprice-2*mindiff);
end
ENTERBARS>10 AND C<ENTERPRICE
当距离开仓K线大于10个周期(ENTERBARS>10 ),并且最新价格小于开仓价(C<ENTERPRICE)。
全部用系统函数来实现.
最多,多仓加个HOLDING>0的限制,就可以