编了一个平台突破下单的简单交易系统
1、设置一个区间,ceilprice为上轨,floorprice为下轨,突破上轨买入2手,突破下轨卖出2手
2、设置止损为loss,如果浮赢达到一定数额(loss+fee)平掉1手,剩下1手追踪止赢,梯度为dispoint
好像无法实现下单功能,不知道是啥原因,代码如下
input:ceilprice(6788,3000,9000),floorprice(6781,3000,9000),loss(12,0,100),num(2,2,100),dispoint(12,2,600),fee(20,0,60);
variable:longfuying=0,shortfuying=0,longyk=0,shortyk=0;
//第一步,设置上下价,num=2
IF holding=0 then
begin
longfuying:= 0;
shortfuying:=0;
longchase:=0;
shortchase:=0;
longyk:=0;
shortyk:=0;
BUY(holding=0,num,STOP,ceilprice);//市价超过上限时买入
BUYSHORT(holding=0,num,STOP,floorprice);//市价低于下限时沽出
end
//第二步,设止损,设初步止盈
IF ABS(holding)=num then
begin
SELL(holding>0,holding,STOPR,ENTERPRICE-loss);
SELLSHORT(holding<0,holding,STOPR,ENTERPRICE+loss);
SELL(holding > 0,num*0.5,LIMITR,ENTERPRICE+loss+fee);
SELLSHORT(holding < 0,num*0.5,LIMITR,ENTERPRICE-loss-fee);
end
//第三步,跟踪止损
longyk:=HHV(H,ENTERBARS)-enterprice-fee;
shortyk:=enterprice-LLV(L,ENTERBARS)-fee;
if holding>0 then //持仓为多单时
if longyk>0 then
begin
longfuying:=longyk;
longchase:=longfuying-mod(longfuying,dispoint)+enterprice-loss;
end
else
begin
longfuying:=0;
longchase:=enterprice-loss;
end
if holding <0 then//持仓为空单时
if shortyk>0 then
begin
shortfuying:=shortyk;
shortchase:=enterprice+loss-(shortfuying-mod(longfuying,dispoint));
end
else
begin
shortfuying:=0;
shortchase:=enterprice+loss;
end
IF ABS(holding)=num*0.5 then
begin
SELL(holding>0,holding,STOPR,longchase);
SELLSHORT(holding<0,holding,STOPR,shortchase);
end
BUY(holding=0,num,STOP,ceilprice);//市价超过上限时买入
BUYSHORT(holding=0,num,STOP,floorprice);//市价低于下限时沽出
类似的语句,不妨改成,
BUY(c>ceilprice and holding=0,num,thisclose);//市价超过上限时买入
BUYSHORT(c<floorprice and holding=0,num,thisclose);//市价低于下限时沽出
推荐您,先把1手的固定止损和固定止盈先写好.下单什么的都通过了
然后再转成1手固定止损和1手移动止盈.