比如:
MACD金叉,买平开.
MACD死叉,卖平开.
然后不管做多还是做空,开仓后即下委托单赢利10档止赢,到亏损5档发出止损.
请写一下程序公式.以作示例.
if holding>0 and l<enterprice-5 then sell(1,1,limitr,min(o,enterprice-5));
if holding>0 and h>enterprice+10 then sell(1,1,limitr,max(o,enterprice+10));
if holding=0 and cross(diff,dea) then buy(1,1,limitr,c);
当止损止赢当中的一个成交了,另外一个撤单怎么写
if holding>0 and l<enterprice-5 then sell(1,1,limitr,min(o,enterprice-5)); |
也可以,这样写是为了方便理解
同时也是取开盘价格和开仓均价两个价格中较小的一个数值作为价格触发
还有个问题
要是,,if holding>0 and l<enterprice-5 and h>enterprice+10 then 算什么价格,,,止赢止损都可以算啊
K线只是记录最高、最低、开盘、收盘,无法判断是先碰到止损,还是先碰到止盈
二者只能选择其一。或者收阳线选择止盈,收阴线选择止损,自行选择 。但这样只是用于测试
我一般选择 先判断是否止损,再判断是否止盈,即2楼的写法
是实盘也不影响。即使实际情况是先止盈,仓位平仓。而后最低价又触碰止损位,但此时已无仓位。信号依然是平仓信号