关于论坛中R-Break策略中全局变量的几点疑问
最近在研究R-Break策略,关于全局变量SetGlobalVar和GetGlobalVar的使用还是很迷惑,在论坛里面也找了一些老的帖子研究,稍懂一点,但是看到全局变量的用法就又迷糊了。if(Date != Date)
{
SetGlobalVar(0,0); //设置全局变量
SetGlobalVar(1,0); //设置全局变量
startnow=startnow+1;
。。。
。。。
}
在这里把位置0和位置1赋值为0。
if(Time*100>=notbef and Time*100<notaft and startnow>=2 and rfilter)
{
if(Time != GetGlobalVar(1) and GetGlobalVar(1) != 0)
{
SetGlobalVar(1,1 );
}
if(hitoday>=ssetup and marketposition>-1 and GetGlobalVar(1)<1)
{
If(Low<=(senter+(hitoday-ssetup)/div))
{
SellShort(1,senter+(hitoday-ssetup)/div);
SetGlobalVar(1,Time);
Return;
}
}
这里红色的IF句里面的条件明显不能成立,GetGlobalVar(1)是调用第一个位置处的全局变量值本来前面就赋值为零了,这里条件又不等于零,感觉明显不对呀。
哪位大侠能够解释一下呀。不胜感激。 策略里面有其他位置有 SetGlobalVar的语句,在这些语句中全局变量被赋予了其他值 darknesszeal 发表于 2013-11-13 14:18 static/image/common/back.gif
策略里面有其他位置有 SetGlobalVar的语句,在这些语句中全局变量被赋予了其他值 ...
Params
Numeric notbef(9.00);
Numeric notaft(14.55);
Numeric f1(0.35);
Numeric f2(0.07);
Numeric f3(0.25);
Numeric reverse(1.00);
Numeric rangemin(0.2);
Numeric xdiv(3);
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);
NumericSeries startnow(0);
NumericSeries div(0);
BoolSeries rfilter(false);
Numeric i_reverse;
Numeric i_rangemin;
Numeric i_vB;
Numeric i_vS;
Begin
i_reverse = reverse*(OpenD(0)/100);
i_rangemin = rangemin*(OpenD(0)/100);
if(BarStatus==0)
{
startnow=0;
div=max(xdiv,1);
}
if(Date != Date)
{
SetGlobalVar(0,0);
SetGlobalVar(1,0);
startnow=startnow+1;
ssetup=hitoday+f1*(Close-ltoday);
senter=((1+f2)/2)*(hitoday+Close)-(f2)*ltoday;
benter=((1+f2)/2)*(ltoday+Close)-(f2)*hitoday;
bsetup=ltoday-f1*(hitoday-Close);
bbreak=ssetup+f3*(ssetup-bsetup);
sbreak=bsetup-f3*(ssetup-bsetup);
hitoday=High;
ltoday=Low;
rfilter=(hitoday-ltoday)>=i_rangemin;
}
if(High>hitoday)
{
hitoday=High;
}
if(Low<ltoday)
{
ltoday=Low;
}
if(Time*100>=notbef and Time*100<notaft and startnow>=2 and rfilter)
{
if(Time != GetGlobalVar(1) and GetGlobalVar(1) != 0)
{
SetGlobalVar(1,10000);
}
if(hitoday>=ssetup and marketposition>-1 and GetGlobalVar(1)<1)
{
If(Low<=(senter+(hitoday-ssetup)/div))
{
SellShort(1,senter+(hitoday-ssetup)/div);
SetGlobalVar(1,Time);
Return;
}
}
if(ltoday<=bsetup and marketposition<1 and GetGlobalVar(1)<1)
{
If(High>=(benter-(bsetup-ltoday)/div))
{
Buy(1,benter-(bsetup-ltoday)/div);
SetGlobalVar(1,Time);
Return;
}
}
if(marketposition==-1)
{
SetGlobalVar(0,1);
if(High-EntryPrice>=i_reverse)
{
BuyToCover(1,entryprice+i_reverse);
Return;
}
}
if(marketposition==1)
{
SetGlobalVar(0,1);
if(EntryPrice-Low>=i_reverse)
{
Sell(1,entryprice-i_reverse);
Return;
}
}
if(marketposition==0)
{
if(High>=bbreak and GetGlobalVar(0) == 0)
{
Buy(1,bbreak);
Return;
}
}
if(marketposition==0)
{
if(low<=sbreak and GetGlobalVar(0) == 0)
{
SellShort(1,sbreak);
Return;
}
}
}
if(Time*100>=notaft and Time<0.1600)
{
if(marketposition==-1)
{
BuyToCover(1,Open);
}
if(marketposition==1)
{
Sell(1,Open);
}
}
End
上面是整个策略,使用全局变量的地方我已经用红色标示出来了。SetGlobalVar设置全局变量时只用了0和1两个位置,后面设置的SetGlobalVar会覆盖前面位置设置的值,这个我知道,但是不明白首先给0位置和1位置设置值为0,这个0是数字零,还是有其他含义的,前面也没有说明,那只能按照默认数字0理解了,那后面的条件Time != GetGlobalVar(1) and GetGlobalVar(1) != 0这个条件就明显不合理了。很难理解。 这个全局变量大家都看不懂吗?怎么没人解答一下呢。 bcqhsz 发表于 2013-11-20 10:23 static/image/common/back.gif
这个全局变量大家都看不懂吗?怎么没人解答一下呢。
0号全局变量用于控制重复开仓
1号全局变量记录开仓时间,控制交易时段 我想问下
ssetup=hitoday+f1*(Close-ltoday);
senter=((1+f2)/2)*(hitoday+Close)-(f2)*ltoday;
benter=((1+f2)/2)*(ltoday+Close)-(f2)*hitoday;
bsetup=ltoday-f1*(hitoday-Close);
bbreak=ssetup+f3*(ssetup-bsetup);
sbreak=bsetup-f3*(ssetup-bsetup);
hitoday=High;
ltoday=Low;
if(High>hitoday)
{
hitoday=High;
}
if(Low<ltoday)
{
ltoday=Low;
}
其中的hitoday和ltoday代表着什么 是High和Low吗?那为什么不直接替换掉,我替换掉了 而六个变量的值也因此发生改变?
还有一个问题就是后面的两个if循环,为什么hitoday和ltoday赋值后,还与low和high比较。两者不是一样的了吗?我也试过,如果不加上这句,答案还是不一样。
本人是菜鸟,不懂TB的一些关键的思想,请求大神解答。
页:
[1]