思路:开仓后的某K线最高价H如高于开仓时那根K线的最高价,则平仓处理。
根据以上思路编制公式:
aa:="kdj.j"(9,3,3) ;
平空:SELLSHORT(cross(aa,80) or h>ref(h,TYPEBAR(1,3)) ,0,thisclose) ;
开空:BUYSHORT(cross(80,aa) or type(1)=2 and enterprice>exitprice,1,thisclose) ;
公式能通过,但由于TYPEBAR函数写于开空编码之前,而这时开空信号还未出现,造成逻辑混乱。所以事实上的效果是第一个平仓信号会紧跟在第一个开仓信号之后,造成错误平仓信号。
改成:
aa:="kdj.j"(9,3,3) ;
开空:BUYSHORT(cross(80,aa) or type(1)=2 and enterprice>exitprice ,1,thisclose) ;
dd: h>ref(h,TYPEBAR(1,3)) ;
平空:SELLSHORT(cross(aa,80) or dd,0,thisclose) ;
公式通过,原来的问题解决了。但此时另一个问题出现,此编法与先平后开的原则相违背,并造成与开空策略中的enterprice>exitprice条件冲突。因为exitprice函数写在平仓之前了。
拜托,问题看全了再回复。