共10 条记录, 每页显示 10 条, 页签:
[1]
1楼
xwxlmb 发表于:2016/5/17 9:19:38
请教老师,如何添加命令使程序在空仓状态下,系统发出开仓指令一次性执行定义的持仓量,并忽略平仓前的其它开仓信号。
input:inb(20,1,20,1),outb(10,1,20,1),risk(1,0,10,0.1);
//海龟源码
variable:times=0,n=0;
rn:=ema(ref(tr,1),20);
n:=valuewhen(holding=0,rn);
rh:=ref(h,1);
rl:=ref(l,1);
h1:hhv(rh,inb);
h2:hhv(rh,outb);
l1:llv(rl,inb);
l2:llv(rl,outb);
lotst:asset*risk*0.01/(n*multiplier);
lots:=if(risk=0,1,lotst); //如果risk取0,表示固定开1手
tbc:=h<>l;//判断是否停板 if holding=0 and tbc then //不是停板才可以交易
begin
if h>h1 then //开多
begin
buyp:=max(o,h1);
buy(1,lots,limitr,buyp);
end;//开多结束
else if l<l1 then //开空
begin
sellp:=min(o,l1 );
buyshort(1,lots,limitr,sellp);
end;//开空结束
if holding>0 and tbc then //已有多仓
begin
exitlongp:=max(enterprice,l2);
if l<exitlongp and enterbars<>0 then //出场
begin
exitp:=min(o,exitlongp);
sell(1,0,limitr,exitp);
end;//出场
if holding<0 and tbc then //已有空仓
begin
exitlongp:=min(enterprice,h2);
if h>exitlongp and enterbars<>0 then //出场
begin
exitp:=max(o,exitlongp);
sellshort(1,0,limitr,exitp);
end;//出场
end;
end;
end;
2楼
xwxlmb 发表于:2016/5/17 9:22:23
请教老师,如何添加命令使程序在空仓状态下,系统发出开仓指令一次性执行定义的持仓量,并忽略平仓前的其它开仓信号。
input:inb(20,1,20,1),outb(10,1,20,1),risk(1,0,10,0.1);
//海龟源码
variable:times=0,n=0;
rn:=ema(ref(tr,1),20);
n:=valuewhen(holding=0,rn);
rh:=ref(h,1);
rl:=ref(l,1);
h1:hhv(rh,inb);
h2:hhv(rh,outb);
l1:llv(rl,inb);
l2:llv(rl,outb);
lotst:asset*risk*0.01/(n*multiplier);
lots:=if(risk=0,1,lotst); //如果risk取0,表示固定开1手
tbc:=h<>l;//判断是否停板 if holding=0 and tbc then //不是停板才可以交易
begin
if h>h1 then //开多
begin
buyp:=max(o,h1);
buy(1,lots,limitr,buyp);
end;//开多结束
else if l<l1 then //开空
begin
sellp:=min(o,l1 );
buyshort(1,lots,limitr,sellp);
end;//开空结束
if holding>0 and tbc then //已有多仓
begin
exitlongp:=max(enterprice,l2);
if l<exitlongp and enterbars<>0 then //出场
begin
exitp:=min(o,exitlongp);
sell(1,0,limitr,exitp);
end;//出场
if holding<0 and tbc then //已有空仓
begin
exitlongp:=min(enterprice,h2);
if h>exitlongp and enterbars<>0 then //出场
begin
exitp:=max(o,exitlongp);
sellshort(1,0,limitr,exitp);
end;//出场
end;
end;
end;
3楼
jinzhe 发表于:2016/5/17 9:24:37
4楼
xwxlmb 发表于:2016/5/17 9:29:58
input:inb(20,1,20,1),outb(10,1,20,1),risk(1,0,10,0.1);
//海龟源码
variable:times=0,n=0;
rn:=ema(ref(tr,1),20);
n:=valuewhen(holding=0,rn);
rh:=ref(h,1);
rl:=ref(l,1);
h1:hhv(rh,inb);
h2:hhv(rh,outb);
l1:llv(rl,inb);
l2:llv(rl,outb);
lotst:asset*risk*0.01/(n*multiplier);
lots:=if(risk=0,1,lotst); //如果risk取0,表示固定开1手
tbc:=h<>l;//判断是否停板 if holding=0 and tbc then //不是停板才可以交易
begin
if h>h1 then //开多
begin
buyp:=max(o,h1);
buy(1,lots,limitr,buyp);
end;//开多结束
else if l<l1 then //开空
begin
sellp:=min(o,l1 );
buyshort(1,lots,limitr,sellp);
end;//开空结束
if holding>0 and tbc then //已有多仓
begin
exitlongp:=max(enterprice,l2);
if l<exitlongp and enterbars<>0 then //出场
begin
exitp:=min(o,exitlongp);
sell(1,0,limitr,exitp);
end;//出场
if holding<0 and tbc then //已有空仓
begin
exitlongp:=min(enterprice,h2);
if h>exitlongp and enterbars<>0 then //出场
begin
exitp:=max(o,exitlongp);
sellshort(1,0,limitr,exitp);
end;//出场
end;
end;
end;
5楼
jinzhe 发表于:2016/5/17 9:31:35
系统发出开仓指令一次性执行定义的持仓量,并忽略平仓前的其它开仓信号
这句指的是什么情况?
6楼
xwxlmb 发表于:2016/5/17 9:37:12
老师您试一下,开仓量被分成多次执行了,我想空仓状态第一次出信号开仓,如突破前20日高点开仓,反向2ATR止损、反向前10日低点止损或止盈,不加仓。
7楼
jinzhe 发表于:2016/5/17 9:43:04
海龟就是有多次加仓的,你想要不加仓,在开仓语句里面加上holding=0的判断
8楼
xwxlmb 发表于:2016/5/17 9:57:03
老师这样改对吗?
input:inb(20,1,20,1),outb(10,1,20,1),risk(1,0,10,0.1);
//海龟源码
variable:times=0,n=0;
rn:=ema(ref(tr,1),20);
n:=valuewhen(holding=0,rn);
rh:=ref(h,1);
rl:=ref(l,1);
h1:hhv(rh,inb);
h2:hhv(rh,outb);
l1:llv(rl,inb);
l2:llv(rl,outb);
lotst:asset*risk*0.01/(n*multiplier);
lots:=if(risk=0,1,lotst); //如果risk取0,表示固定开1手
tbc:=h<>l;//判断是否停板 if holding=0 and tbc then //不是停板才可以交易
begin
if h>h1 then //开多
begin
buyp:=max(o,h1);
buy(1,lots,limitr,buyp);
end;//开多结束
else if l<l1 then //开空
begin
sellp:=min(o,l1 );
buyshort(1,lots,limitr,sellp);
end;//开空结束
if holding=0 and tbc then //已有多仓
begin
exitlongp:=max(enterprice,l2);
if l<exitlongp and enterbars<>0 then //出场
begin
exitp:=min(o,exitlongp);
sell(1,0,limitr,exitp);
end;//出场
if holding=0 and tbc then //已有空仓
begin
exitlongp:=min(enterprice,h2);
if h>exitlongp and enterbars<>0 then //出场
begin
exitp:=max(o,exitlongp);
sellshort(1,0,limitr,exitp);
end;//出场
end;
end;
end;
9楼
jinzhe 发表于:2016/5/17 10:04:16
buy(1,lots,limitr,buyp);
buyshort(1,lots,limitr,sellp);
这两句改成
buy(holding=0,lots,limitr,buyp);
buyshort(holding=0,lots,limitr,sellp);
其他不要改
10楼
xwxlmb 发表于:2016/5/17 10:06:11
共10 条记录, 每页显示 10 条, 页签:
[1]