你这里语句都重复了,下单条件的语句和 开仓语句 整段的重复了一次。
这样结果就是 BuyCond这个条件 第一次出现时候 值是1 很快再下面 又被重复的那条语句 重新赋值为0 了。
反正就是给你反过来。
另外前面那个回复 应该是笔误给你写错了,均线上 应该是指收盘价在均线上吧。 那应该 是c>ma10
[PEL] 复制代码 //定义参数
Input:N(12,1,100,1);//均线和标准差参数
Num:=1;//开仓手数
//中间变量
Ma10:Ma(c,N);//10日均线
Std1:=Std(c,N);//一个标准差
Upper:=Ma10+Std1;//通道上轨
Bottom:=Ma10-Std1;//通道下轨
BuyCond:=h>ref(h,1) and l>ref(l,1) and l<=Bottom and ma10<close ;//上涨趋势中价格触及下轨
SellCond:=h<ref(l,1) and l<ref(l,1) and h>=Upper and ma10>close ;//下跌趋势中价格初级上轨开仓
//下单语句
if BuyCond then begin
Sellshort(holding<0,0,market);//市价平空
Buy(holding=0,Num,market);//市价开多
end
if SellCond then begin
Sell(holding>0,0,market);//市价平多
BuyShort(holding=0,Num,market);//市价开空
end
//止盈止损
Win_Buy:=h-enterprice>=2;//多头盈利2点
Win_Sell:=enterprice-l>=2;//空头盈利2点
Lose_Buy:=enterprice-l>=1.25;//多头亏损1.25点
Lose_Sell:=h-enterprice>=1.25;//空头亏损1.25点
//市价止盈止损
if Win_Buy and holding>0 then 多止盈:Sell(enterbars>0,0,market);
if Win_Sell and holding<0 then 空止盈:Sellshort(enterbars>0,0,market);
if Lose_Buy and holding>0 then 多止损:Sell(enterbars>0,0,market);
if Lose_Sell and holding<0 then 空止损:Sellshort(enterbars>0,0,market);
|