应该是有效的
因为该功能的运行环境复杂,所以不能100%的实现目标,还请谨慎使用
确保每一个独立的框架次周期恢复持仓,把这段代码放在策略的最后面就可以了是吗?
buycond:=.................自己的条件;
sellcond:=...................自己的条件;
if holding=0 and sellcond and not(islastbar) then buyshort(1,1,marketr);
if islastbar and tholding2<>holding then
begin
if barpos=EXTGBDATA('kai')+1 then//开仓信号消失,平仓恢复仓
begin
sell(tholding2>0,1,marketr);
sellshort(tholding2<0,1,marketr);
EXTGBDATASET( 'kai',0);
end
if barpos=EXTGBDATA('ping')+1 then//平仓信号消失,开仓恢复仓
begin
buy(holding>0,1,marketr);
buyshort(holding<0,1,marketr);
EXTGBDATASET( 'ping',0);
end
end
if holding>0 and sellcond and islastbar then
begin
sell(1,1,marketr);
EXTGBDATASET( 'ping',BARPOS);
end
if holding<0 and buycond and islastbar then
begin
sellshort(1,1,marketr);
EXTGBDATASET( 'ping',BARPOS);
end
//全局变量BAR,信号消失一根K线上也只开一次仓
if ISLASTBAR AND buycond and barpos>EXTGBDATA('kai') and holding=0 then
begin
buy(1,1,marketr);
EXTGBDATASET( 'kai',BARPOS);
end
if ISLASTBAR AND sellcond and barpos>EXTGBDATA('kai') and holding=0 then
begin
buyshort(1,1,marketr);
EXTGBDATASET( 'kai',BARPOS);
end
在图表交易上实现这类功能是需要很高技巧的,如果楼主根本就无法看懂上述的代码,那么还请楼主慎用。
建议你选择使用更加稳定的持仓同步功能
我是多品种,多周期,持仓同步只能单个框架架啊?
想买专业版,但又不懂后台代码
if EXITBARS>0&&islastbar and tholding2<>holding then
begin
if HOLDING=0 then//开仓信号消失,平仓恢复仓
begin
sell(tholding2>0,HOLDING,MARKETR);
sellshort(tholding2<0,HOLDING,MARKETR);
end
if ENTERBARS>0&&islastbar and tholding2<>holding then
if HOLDING<>0 then//平仓信号消失,开仓恢复仓
begin
buy(HOLDING>0,HOLDING,MARKETR);
buyshort(HOLDING<0,HOLDING,MARKETR);
end
end
简化了一下 大家回去试下看行不行 本人编程水平不行 如有遗留还请谅解
兄台真是幽默,编程水平有限,才到论坛发问嘛
呵呵