- 精华
- 0
- 在线时间
- 181 小时
- UID
- 173160
- 积分
- 82
- 帖子
- 53
- 阅读权限
- 30
- 注册时间
- 2013-9-30
- 最后登录
- 2018-4-3
- 精华
- 0
- UID
- 173160
- 积分
- 82
- 帖子
- 53
- 主题
- 19
- 阅读权限
- 30
- 注册时间
- 2013-9-30
- 最后登录
- 2018-4-3
|
本帖最后由 research 于 2013-10-18 13:15 编辑
以下是网友穿堂风在本论坛发过的一个策略(链接为;http://bbs.tb18.net/thread-15508-1-1.html)其中的一部分,因为没有基础,看不明白,贴上来请教;
params
... ...
Numeric f1(0.35);
Numeric f2(0.07);
Numeric f3(0.25);
... ...
Vars
NumericSeries ssetup(0);
NumericSeries bsetup(0);
NumericSeries senter(0);
NumericSeries benter(0);
NumericSeries bbreak(0);
NumericSeries sbreak(0);
NumericSeries ltoday(0);
NumericSeries hitoday(9999);
... ...
Begin
... ...
if(BarStatus==0)
{
startnow=0;
div=max(xdiv,1);
}
if(Date != Date[1])
{
SetGlobalVar(0,0);
SetGlobalVar(1,0);
startnow=startnow+1;
ssetup=hitoday[1]+f1*(Close[1]-ltoday[1]);
senter=((1+f2)/2)*(hitoday[1]+Close[1])-(f2)*ltoday[1];
benter=((1+f2)/2)*(ltoday[1]+Close[1])-(f2)*hitoday[1];
bsetup=ltoday[1]-f1*(hitoday[1]-Close[1]);
bbreak=ssetup+f3*(ssetup-bsetup);
sbreak=bsetup-f3*(ssetup-bsetup);
hitoday=High;
ltoday=Low;
rfilter=(hitoday[1]-ltoday[1])>=i_rangemin;
}
if(High>hitoday)
{
hitoday=High;
}
if(Low<ltoday)
{
ltoday=Low;
}
不明白主要在红色位置:当第一个tick进来时,hitoday[1],ltoday[1]都应该取初值,算出ssetup,senter,benter,bsetup等,后面对hitoday,ltoday赋值。我的问题是,按TB(V4)的解释下次如果是同一根BAR运行公式的话,变量值又会传递上一根BAR的值(这里我理解还应该是初值),只有这根BAR的最后一个tick运行完后,序列变量的值才能保留下来。也就是说在当天开盘的第一根BAR中hitoday[1]与 ltoday[1]始终取初值计算。我知道我的理解是错的,但又不知道错在哪,请求帮助,非常感谢! |
|