请老师帮忙写一个,在1分钟周期或者5分钟周期 1:取得今天的开盘价 2如果现在价格大于开盘价那么开多,如果小于开空。2如果亏损p*mindiff多单空单都平仓。3如果赢了2P*mindiff多单空单都止盈。谢谢老师
top:ref(o,TODAYBAR);
if c>top and holding=0 then buy(1,1,MARKET);
if c<top and holding=0 then buyshort(1,1,MARKET);
if holding>0 and ENTERPRICE-c>P*MINDIFF then sell(1,holding,market);
if holding<0 and c-ENTERPRICE>P*MINDIFF then sellshort(1,holding,market);
if holding>0 and c-ENTERPRICE>2*P*MINDIFF then sell(1,holding,market);
if holding<0 and ENTERPRICE-c>2*P*MINDIFF then sellshort(1,holding,market);
不要用下根K线的开盘价或者这根K线的收盘,就是到了条件就执行。你这样写固定轮训会出现闪烁啊。忘开始改一下
可以用限价的, 到了条件就执行这个是要选择固定轮询模式,并不是代码里面控制的。你这个也做不到不闪烁,因为你下单条件在行情上下变化的时候是很容易反复变化的。
“如果现在价格大于开盘价那么开多”这个条件没办法让它不闪烁的。
top:ref(o,TODAYBAR);
if h>top and holding=0 then buy(1,1,MARKET);
if l<top and holding=0 then buyshort(1,1,MARKET);
if holding>0 and ENTERPRICE-c>P*MINDIFF then sell(1,holding,market);
if holding<0 and c-ENTERPRICE>P*MINDIFF then sellshort(1,holding,market);
if holding>0 and c-ENTERPRICE>2*P*MINDIFF then sell(1,holding,market);
if holding<0 and ENTERPRICE-c>2*P*MINDIFF then sellshort(1,holding,market);
那可以稍微改下,开仓条件。 限价指令那个你可以参考下单函数的说明自行修改下就行了。
top:ref(o,TODAYBAR);
if h>top and holding=0 then buy(1,1,LIMITR,top);
if l<top and holding=0 then buyshort(1,1,LIMITR,top);
if holding>0 and ENTERPRICE-l>P*MINDIFF then sell(1,holding,LIMITR,ENTERPRICE-p*mindiff);
if holding<0 and h-ENTERPRICE>P*MINDIFF then sellshort(1,holding,LIMITR,ENTERPRICE+p*MINDIFF);
if holding>0 and h-ENTERPRICE>2*P*MINDIFF then sell(1,holding,LIMITR,ENTERPRICE+2*p*MINDIFF);
if holding<0 and ENTERPRICE-l>2*P*MINDIFF then sellshort(1,holding,LIMITR,ENTERPRICE-2*p*MINDIFF);
我这样改就会出现问题,请老师指正