连续亏损三次则不再开仓。
怎么写
如何使用全局变量,来限定一天只交易3次
variable:num=0;// 全局变量,来控制当天交易次数
cs:=3;//限定一天最多交易3次
ma5:=ma(5,close);
ma20:=ma(20,close);
con1:=cross(ma5,ma20);
con2:=cross(ma20,ma5);
if cond2 and holding>0 then sell(1,1,market);
if cond1 and holding=0 and num<3 then
begin
buy(1,1,market);
num:=num+1;
end
if time=closetime(0) then num:=0;// 商品期货,收盘的同时,num赋值为0
//收盘num不赋值为0,第二天就不再开仓了
参考这个
这个需要把所有的平仓语句都要做下修改,修改范例如下
variable:n=0;//这个写在策略最开头,只写一次
//所有的平仓语句都做如下的修改
if 平空条件 and holding<0 then begin
sellshort(1,0,market);
if numprofit(1)>0 then n:=0;
if numprofit(1)<0 then n:=n+1;
end
if 平多条件 and holding>0 then begin
sell(1,0,market);
if numprofit(1)>0 then n:=0;
if numprofit(1)<0 then n:=n+1;
end
然后在所有开仓条件里面加入一个条件: n<3
还是不能生效, 能不能帮我看看源代码? 怎么联系你? |
INPUT:检索周期(50,50,1000,10);
INPUT:宽高比(7.5,1.5,10,0.5);
INPUT:宽比(65,20,80,5);
INPUT:高比(10,10,40,4);
variable:连续多损次数=0;
variable:连续空损次数=0;
IF主力:=CALLSTOCK('IF00',VTCLOSE,12,0),COLORRED;
SH300:=CALLSTOCK('SH300',VTCLOSE,12,0),COLORCYAN;
远高:HHV(H,检索周期);
远低:llv(l,检索周期);
上距离:=HHV(H,检索周期)-C,NODRAW;
下距离:=C-llv(l,检索周期),NODRAW;
高:远高-远低,NODRAW;
宽:abs(LLVBARS(L,检索周期)-HHVBARS(h,检索周期))*5/60,NODRAW; // 时间分钟
高宽比:高/宽,NODRAW;
makgb:=ma(高宽比,300);
开多条件:=高>40 and LLVBARS(L,检索周期)*5/60<宽/宽比 AND 下距离>高/高比 and 高宽比>=宽高比 {and SH300<ref(SH300,1)} AND TIME>95000 and 连续多损次数<3 and HOLDING=0;
开空条件:=高>40 and HHVBARS(h,检索周期)*5/60<宽/宽比 and 上距离>高/高比 and 高宽比>=宽高比 {and SH300>ref(SH300,1)} AND TIME>95000 and 连续空损次数<3 and HOLDING=0;
平多条件:=c=远高;
平空条件:=c=远低;
//连续亏损三次不再开仓
//所有的平仓语句都做如下的修改
if 平空条件 and holding<0 then begin
sellshort(1,0,market);
if numprofit(1)>0 then 连续空损次数:=0;
if numprofit(1)<0 then
BEGIN
连续空损次数:=连续空损次数+1;
end
end
if 平多条件 and holding>0 then begin
sell(1,0,market);
if numprofit(1)>0 then 连续多损次数:=0;
if numprofit(1)<0 then
begin
连续多损次数:=连续多损次数+1;
end
end
//交易
开空:BUYSHORT(开空条件 and 连续空损次数<3,1,MARKETR);
开多:BUY(开多条件 and 连续多损次数<3,1,MARKETR);
//止损
if c>ref(远高,1) and holding<0 then begin
SELLSHORT(1,0,MARKETR);
if numprofit(1)>0 then 连续空损次数:=0;
if numprofit(1)<0 then BEGIN
连续空损次数:=连续空损次数+1;
end
end
if c<ref(远低,1) and holding>0 THEN begin
SELL(1,0,MARKETR);
if numprofit(1)>0 then 连续多损次数:=0;
if numprofit(1)<0 then
begin
连续多损次数:=连续多损次数+1;
end
end
当前持仓:HOLDING,COLORGRAY,LINETHICK0;
当前资产:ASSET,NOAXIS,COLORGRAY;