//交易系统 走完K线模式
if holding>0 and kkcond and not(islastbar) then sell(1,ss,marketr);
if holding<0 and kdcond and not(islastbar) then sellshort(1,ss,marketr);
if holding=0 and buycond and not(islastbar) then buy(1,ss,marketr);
if holding=0 and sellcond and not(islastbar) then buyshort(1,ss,marketr);
//用全局变量EXTGBDATA,实现信号消失处理功能
if islastbar and tholding2<>holding then
begin
if barpos=EXTGBDATA('kai')+1 then//开仓信号消失,平原持仓
begin
sell(tholding2>0,ss,marketr);
sellshort(tholding2<0,ss,marketr);
EXTGBDATASET( 'kai',0);
end
if barpos=EXTGBDATA('ping')+1 then//平仓信号消失,平原持仓
begin
sell(holding>0,ss,marketr);
sellshort(holding<0,ss,marketr);
EXTGBDATASET( 'ping',0);
end
end
if holding>0 and kkcond and islastbar then
begin
sell(1,ss,marketr);
EXTGBDATASET( 'ping',BARPOS);
end
if holding<0 and kdcond and islastbar then
begin
sellshort(1,ss,marketr);
EXTGBDATASET( 'ping',BARPOS);
end
上面是我编写想实现处理功能。实盘中不处理。
程序要求这样:
1)开多,开空,平多空采用走完K线模式。
2)处理情况:有时候出现开仓或者平仓后,信号消失,这样就需要处理原开仓的平仓处理,原仓位直接平掉。
3)要求不开启金子塔持仓同步功能就可以自动实现。
请帮忙编写?
[此贴子已经被作者于2017/6/13 12:09:49编辑过]
我是要求不开启你们的同步功能,就能使用自己编写的处理信号消失问题。
还有一个问题请教;//止损止盈
if enterbars>1 and l<=Tl-2*MINDIFF and holding>0 then sell(1,ss,marketr);
if enterbars>1 and h>=Th+2*MINDIFF and holding<0 then sellshort(1,ss,marketr);
若信号消失了,这开仓历时还有效否?enterbars
信号消失了,enterbars返回的就不是信号在的时候的值,而是消失后,当前历史上最近的开仓位置的值。
//交易系统 走完K线模式
temp_ll:=llv(l,2); temp_hh:=hhv(h,2);
if holding>0 and kkcond and not(islastbar) then sell(1,ss,marketr);
if holding<0 and kdcond and not(islastbar) then sellshort(1,ss,marketr);
if holding=0 and buycond and not(islastbar) then begin
buy(1,ss,marketr);
extgbdataset('kaiduo',temp_ll);
end
if holding=0 and sellcond and not(islastbar) then begin
buyshort(1,ss,marketr);
extgbdataset('kaikong',temp_hh);
end
//信号消失止损处理
if tholding2<>holding and l<extgbdata('kaiduo') then
begin
sell(holding>0,ss,marketr);
end
if tholding2<>holding and h>extgbdata('kaikong') then
begin
sellshort(holding<0,ss,marketr);
end
if holding=0 then begin
extgbdataset('kaikong',drawnull);
extgbdataset('kaiduo',drawnull);
end
这样可以处理信号消失的单子?
不行,如果开仓信号消失了,是不会出平仓信号的,就不会执行”信号消失止损处理”的平仓动作。
使用extgbdataset('kaikong',temp_hh); 记录当时开仓的高低点,止损不行?这个不会消失? if tholding2<>holding and l<extgbdata('kaiduo') then
begin
sell(holding>0,ss,marketr);
end
你这种用法,在图表上只会造成历史信号不断变化。extgbdata只在最新值上有效。它发生变化,历史k线条件就会跟着变化。