进场:
在当前周期上,瀑布线三根(P1,P2,P3)粘合于一点(一根k线)时,开单。金叉: 开多单,死叉:开空单。
出场:
在小一级别周期上,P1和P2粘合交叉时出场。
金叉: P1上穿P2,P1上穿P3,P2上穿P3,发生在同一根k线,或者说发生在当前周期范围内(比如: 10分钟k线图上,这3次上穿,在10分钟内完成)。
死叉: P1下穿P2,P1下穿P3,P2下穿P3,后面同上。
周期: 希望自行设置参数,比如,当前开单是在10分钟图上,那出场就是看5分钟图。
如果是多单,小周期就死叉出场; 如果是空单,小周期就金叉出场。
if cross(P1,P2) and cross(P1,P3) and cross(P2,P3) then
begin
sellshort(1,holding,marketr);
buy(1,1,marketr);
if cross(P2,P1) and cross(P3,P1) and cross(P3,P2) then
begin
sell(1,holding,marketr);
buyshort(1,1,marketr);
金叉:cross(p1,p2) and cross(p1,p3) and cross(p2,p3);
死叉:cross(p2,p1) and cross(p3,p1) and cross(p3,p2);
金叉死叉按照上面方式定义即可。
你这个要跨周期,需要使用STKINDI函数引用上面的判断条件。假设上面代码在指标A中:
input:N(2,1,26,1);//周期调用参数
cd1:STKINDI('','A.金叉',0,N,0);//N默认是2,表示调用五分钟的金叉。其他周期参数请参考stkind函数说明。
cd2:STKINDI('','A.死叉',0,N,0);//N默认是2,表示调用五分钟的死叉。
金叉:cross(p1,p2) and cross(p1,p3) and cross(p2,p3);//当前周期金叉
死叉:cross(p2,p1) and cross(p3,p1) and cross(p3,p2);//当前周期死叉
buy(金叉 and holding=0,1,market);
sell(cd2 and holding>0,holding,market);
buyshort(死叉 and holding=0,1,market);
sellshort(cd1 and holding<0,holding,market);
5楼代码 有设置被引用周期调整的参数N。具体如何调整能对应上需要引用的周期,参考STKINDI函数里面的周期参数说明。另外这个调整的是被引用的周期,当前周期完全取决于你图表上的周期情况。