发个完整的公式上来,否则我们也没法查找问题的
INPUT:N(8,1,100,1); //设置参数时;
INPUT:M(21,1,100,1); //设置参数时;;
INPUT:M2(10,1,100,1); //设置参数时;
INPUT:M4(10,1,100,1); //设置参数时;
MA1:MA(C,n);
MA3:MA(C,m);
//建立多头的进场条件
long := time>093000 and time<140000;
if long and cross(ma1,ma3) then
begin
sellshort(holding < 0 , 0, thisclose);
end
if long and cross(ma1,ma3) then
begin
buy(holding = 0 , N, thisclose);
end
//14:00-14:55平空仓
if cross(ma3,ma1) and time>140000 and time<145500 then
begin
sellshort(holding < 0, 0, thisclose);
end
//开空条件
short := time > 093000 and time < 140000;
if short and cross(ma3,ma1) then
begin
sell(holding > 0, 0, thisclose);
end
if short and l < cross(ma3,ma1) then
begin
buyshort(holding = 0 ,N, thisclose);
end
//140000-1455平多仓
if cross(ma3,ma1) and time>=140000 and time<=145500 then
begin
sell(holding > 0, 0, thisclose);
end
//收盘前5分钟平仓
if time > 145400 then
begin
sell(holding > 0, 0, thisclose);
sellshort(holding < 0, 0, thisclose);
end
//赢10点(m2及M4均先设为10)
If holding < 0 then begin
sellshort(Enterprice-l>=M2, 1, limitr, enterprice-M2+mindiff);
end
If holding > 0 then begin
sell(h-Enterprice>=M2, 1, limitr, enterprice+m2-mindiff);
end
//赢20点
If holding < 0 then begin
sellshort(Enterprice-l>=M2+M4, 1, limitr, enterprice-M2-m4+mindiff);
end
If holding > 0 then begin
sell(h-Enterprice>=M2+M4, 1, limitr, enterprice+m2+m4-mindiff);
end
//赢30点
If Enterprice-l>=M2+2*M4 then begin
sellshort(holding < 0, 1, limitr, enterprice-M2-2*m4+mindiff);
end
If h-Enterprice>=M2+2*M4 then begin
sell(holding > 0, 1, limitr, enterprice+m2+2*m4-mindiff);
end
//赢40点
If Enterprice-l>=M2+3*M4 then begin
sellshort(holding < 0, 1, limitr, enterprice-M2-3*m4+mindiff);
end
If h-Enterprice>=M2+3*M4 then begin
sell(holding > 0, 1, limitr, enterprice+m2+3*m4-mindiff);
end
//赢50点
If Enterprice-l>=M2+4*M4 then begin
sellshort(holding < 0, 1, limitr, enterprice-M2-4*m4+mindiff);
end
If h-Enterprice>=M2+4*M4 then begin
sell(holding > 0, 1, limitr, enterprice+m2+4*m4-mindiff);
end
//赢60点
If Enterprice-l>=M2+5*M4 then begin
sellshort(holding < 0, 1, limitr, enterprice-M2-5*m4+mindiff);
end
If h-Enterprice>=M2+5*M4 then begin
sell(holding > 0, 1, limitr, enterprice+m2+5*m4-mindiff);
end
//赢70点
If Enterprice-l>=M2+6*M4 then begin
sellshort(holding < 0, 1, limitr, enterprice-M2-6*m4+mindiff);
end
If h-Enterprice>=M2+6*M4 then begin
sell(holding > 0, 1, limitr, enterprice+m2+6*m4-mindiff);
end
//赢80点
If Enterprice-l>=M2+7*M4 then begin
sellshort(holding < 0, 1, limitr, enterprice-M2-7*m4+mindiff);
end
If h-Enterprice>=M2+7*M4 then begin
sell(holding > 0, 1, limitr, enterprice+m2+7*m4-mindiff);
end
//赢90点
If Enterprice-l>=M2+8*M4 then begin
sellshort(holding < 0, 1, limitr, enterprice-M2-8*m4+mindiff);
end
If h-Enterprice>=M2+8*M4 then begin
sell(holding > 0, 1, limitr, enterprice+m2+8*m4-mindiff);
end
//赢100点
If Enterprice-l>=M2+9*M4 then begin
sellshort(holding < 0, 1, limitr, enterprice-M2-9*m4+mindiff);
end
If h-Enterprice>=M2+9*M4 then begin
sell(holding > 0, 1, limitr, enterprice+m2+9*m4-mindiff);
end
//赢110点
If Enterprice-l>=M2+10*M4 then begin
sellshort(holding < 0, 1, limitr, enterprice-M2-10*m4+mindiff);
end
If h-Enterprice>=M2+10*M4 then begin
sell(holding > 0, 1, limitr, enterprice+m2+10*m4-mindiff);
end
图表方式不好实现,使用后台策略来实现吧,因为要取实际持仓。
后台方式怎么实现????
已经做好了修改
另外,楼主注意顺序。你自己写的顺序是错的。
如果穿越当根最高价比收盘价高10个点,按你的写法,你会平仓的
但是在收盘价的位置产生信号,却在当根平仓。这是不符合逻辑的,因为盘中价早于收盘价出现。怎么可能“开仓在后,平仓在前”呢!
这种方法要实盘,还有2点要注意:
1,同一根K线多次符合止盈条件,图表只会自动下一次。除非规定一根K线只能止盈一次
2,盘中下单和K线走完下单并存,实盘交易时还需要作稍微的修改,请参考 阿火秘笈
INPUT:N(8,1,100,1); //设置参数时;
INPUT:M(21,1,100,1); //设置参数时;;
INPUT:M2(10,1,100,1); //设置参数时;
INPUT:M4(10,1,100,1); //设置参数时;
variable:price=drawnull;
MA1:MA(C,n);
MA3:MA(C,m);
if holding>0 then begin
cis:=intpart((h-price)/10);
if cis>0 then begin
//如果同一根K线上涨了20个点以上,虽然有2个平仓信号,但图表只会执行一次
for i=1 to cis do begin
sell(1,1,limitr,price+10*i);
end
price:=price+10*cis;
end
end
if holding<0 then begin
cis:=intpart((price-l)/10);
if cis>0 then begin
for i=1 to cis do begin
sellshort(1,1,limitr,price-10*i);
end
price:=price-10*cis;
end
end
//建立多头的进场条件
long := time>093000 and time<140000;
if long and cross(ma1,ma3) then
begin
sellshort(holding < 0 , 0, thisclose);
end
if cross(ma3,ma1) and time>140000 and time<145500 then
begin
sellshort(holding < 0, 0, thisclose);
end
if holding = 0 and long and cross(ma1,ma3) then
begin
buy(1 , N, thisclose);
price:=c;
end
//14:00-14:55平空仓
//开空条件
short := time > 093000 and time < 140000;
if short and cross(ma3,ma1) then
begin
sell(holding > 0, 0, thisclose);
end
if cross(ma3,ma1) and time>=140000 and time<=145500 then
begin
sell(holding > 0, 0, thisclose);
end
if holding = 0 and short and l < cross(ma3,ma1) then
begin
buyshort(1 ,N, thisclose);
price:=c;
end
//140000-1455平多仓
//收盘前5分钟平仓
if time > 145400 then
begin
sell(holding > 0, 0, thisclose);
sellshort(holding < 0, 0, thisclose);
end
阿火兄,怎样才能修改到能实盘,请帮帮忙,我是菜鸟