请老师编写下股指的指标,如果方便的话,请附上注释,方便学习,谢谢老师、
开仓信号:以当天开盘价上涨10个点以后开多,例如当天开盘价2013.6 价格涨到2014.8 以2014.8开多仓。 止损10个点。
以当天开盘价下跌10个点以后开空。同上,止损也是10个点。
平仓:开仓后如果盈利>20个点,止损回到开仓价格。如果不碰止损,收盘平仓。
开仓一天只开一次。多头开仓后,当天不开空头。
空头开仓后,当天不开多头。
谢谢老师。
oo:=valuewhen(date<>ref(date,1),open);//当天开盘价
tt:=time<=145500;//限定交易时间:在强平前开仓
if h>=oo+10*mindiff and tt then buy(holding=0,1,limitr,high);//超过当天开盘价+10点后,开多
if enterprice-l>=10*mindiff and tt then sell(holding>0,0,market);//多单止损,止损10点
if l<=oo-10*mindiff then buyshort(holding=0,1,limitr,l);//低于当天开盘价-10点后,开空
if h-enterprice>=10*mindiff then sellshort(holding<0,0,market);//空单止损,止损10点
if holding>0 and hhv(h,enterbars+1)-enterprice>20*mindiff and l<=enterprice then sell(holding>0,0,market);//浮盈20点,回落到开仓价后平多
if holding<0 and enterprice-llv(l,enterbars+1)>20*mindiff and h>=enterprice then sellshort(holding<0,0,market);//浮盈20点,回落到开仓价后平多
if time>145500 then begin
sellshort(1,0,market);
sell(1,0,market);
end//收盘前平仓
老师,测试后,每根K线上都有开平仓。
我调试了一下,调试代码:
oo:=valuewhen(date<>ref(date,1),open);//当天开盘价
tt:=time<=145500;//限定交易时间:在强平前开仓
if enterprice-l>=10*mindiff and enterbars>0 and tt then 多止损:sell(holding>0,0,market);//多单止损,止损10点
if h>=oo+10*mindiff and tt then buy(holding=0,1,thisclose);//超过当天开盘价+10点后,开多
if h-enterprice>=10*mindiff and enterbars>0 then 空止损:sellshort(holding<0,0,market);//空单止损,止损10点
if l<=oo-10*mindiff and tt then buyshort(holding=0,1,thisclose);//低于当天开盘价-10点后,开空
if holding>0 and hhv(h,enterbars+1)-enterprice>20*mindiff and l<=enterprice and enterbars>0 then 多回落:sell(holding>0,0,market);//浮盈20点,回落到开仓价后平多
if holding<0 and enterprice-llv(l,enterbars+1)>20*mindiff and h>=enterprice and enterbars>0 then 空回落:sellshort(holding<0,0,market);//浮盈20点,回落到开仓价后平多
if time>145500 then begin
sellshort(1,0,market);
sell(1,0,market);
end//收盘前平仓
发现是你的条件太容易满足,只要一天的行情是一路走高或者走低,那么开平仓条件都容易满足,导致了后面每根k线都有信号
oo:=valuewhen(date<>ref(date,1),open);//当天开盘价
tt:=time<=145500;//限定交易时间:在强平前开仓
if enterprice-l>=10*mindiff and enterbars>0 and tt then 多止损:sell(holding>0,0,market);//多单止损,止损10点
if h>=oo+10*mindiff and tt and totaldaytrade<1 then buy(holding=0,1,thisclose);//超过当天开盘价+10点后,开多
if h-enterprice>=10*mindiff and enterbars>0 then 空止损:sellshort(holding<0,0,market);//空单止损,止损10点
if l<=oo-10*mindiff and tt and totaldaytrade<1 then buyshort(holding=0,1,thisclose);//低于当天开盘价-10点后,开空
if holding>0 and hhv(h,enterbars+1)-enterprice>20*mindiff and l<=enterprice and enterbars>0 then 多回落:sell(holding>0,0,market);//浮盈20点,回落到开仓价后平多
if holding<0 and enterprice-llv(l,enterbars+1)>20*mindiff and h>=enterprice and enterbars>0 then 空回落:sellshort(holding<0,0,market);//浮盈20点,回落到开仓价后平多
if time>145500 then begin
sellshort(1,0,market);
sell(1,0,market);
end//收盘前平仓