设为首页收藏本站

 找回密码
 注册
查看: 3086|回复: 7
打印 上一主题 下一主题

同样的R_Breaker公式为什么结果不一样??? [复制链接]

Rank: 3Rank: 3

精华
0
UID
100877
积分
180
帖子
66
主题
14
阅读权限
40
注册时间
2012-2-27
最后登录
2020-3-26
跳转到指定楼层
1#
发表于 2013-7-4 10:37:44 |只看该作者 |倒序浏览
// 简称: R_Breaker,橡胶指数五分钟

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;
NumericSeries s_enter(0);
NumericSeries b_enter(0);
Begin
i_reverse = reverse*(OpenD(0)/100);
i_rangemin = rangemin*(OpenD(0)/100);
s_enter=(senter+(hitoday-ssetup)/div);
b_enter=(benter-(bsetup-ltoday)/div);

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;
}
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<=s_enter)
                {
                        SellShort(1,senter+(hitoday-ssetup)/div);
                        SetGlobalVar(1,Time);
                        Return;
                }
        }
        if(ltoday<=bsetup and marketposition<1  and GetGlobalVar(1)<1)
        {
                If(High>=b_enter)
                {
                        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
附件: 你需要登录才可以下载或查看附件。没有帐号?注册

Rank: 3Rank: 3

精华
0
UID
100877
积分
180
帖子
66
主题
14
阅读权限
40
注册时间
2012-2-27
最后登录
2020-3-26
2#
发表于 2013-7-4 10:45:09 |只看该作者
// 简称: R_Breaker

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;
NumericSeries s_enter(0);
NumericSeries b_enter(0);
Begin
i_reverse = reverse*(OpenD(0)/100);
i_rangemin = rangemin*(OpenD(0)/100);
s_enter=(senter+(hitoday-ssetup)/div);
b_enter=(benter-(bsetup-ltoday)/div);

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;
}
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

//用s_senter和b_benter替代后两个结果不同,请问为什么????
附件: 你需要登录才可以下载或查看附件。没有帐号?注册

使用道具 举报

Rank: 6Rank: 6

精华
0
UID
116229
积分
2373
帖子
2247
主题
18
阅读权限
70
注册时间
2013-3-4
最后登录
2019-3-24
3#
发表于 2013-7-4 11:39:46 |只看该作者
没有很仔细的看代码,两个程序的不同就是一个使用的是s_enter,一个是计算s_enter的表达式,我看到s_enter'都是在程序一开始赋值的,之后,对于计算该表达式中的变量senter、hitoday、ssetup有重新赋值的可能性,那么在此计算得到的值就不同了

使用道具 举报

Rank: 3Rank: 3

精华
0
UID
100877
积分
180
帖子
66
主题
14
阅读权限
40
注册时间
2012-2-27
最后登录
2020-3-26
4#
发表于 2013-7-4 11:47:49 |只看该作者
没明白,可以举个简单的例子吗

使用道具 举报

Rank: 6Rank: 6

精华
0
UID
116229
积分
2373
帖子
2247
主题
18
阅读权限
70
注册时间
2013-3-4
最后登录
2019-3-24
5#
发表于 2013-7-4 12:30:19 |只看该作者
loafertb 发表于 2013-7-4 11:47
没明白,可以举个简单的例子吗

0、x=1;y=3;
1、s=x+y;
2、x=5;y=6;
3、这一步,s是=4的,但是x+y是=11的

使用道具 举报

Rank: 3Rank: 3

精华
0
UID
100877
积分
180
帖子
66
主题
14
阅读权限
40
注册时间
2012-2-27
最后登录
2020-3-26
6#
发表于 2013-7-4 13:41:33 |只看该作者
你说的很容易明白,但我举的例子该怎么改才正确,麻烦了!!!!!!!主题思想是要用s_enter替代(senter+(hitoday-ssetup)/div);
用b_enter替代(benter-(bsetup-ltoday)/div);

使用道具 举报

Rank: 6Rank: 6

精华
0
UID
116229
积分
2373
帖子
2247
主题
18
阅读权限
70
注册时间
2013-3-4
最后登录
2019-3-24
7#
发表于 2013-7-4 14:05:06 |只看该作者
loafertb 发表于 2013-7-4 13:41
你说的很容易明白,但我举的例子该怎么改才正确,麻烦了!!!!!!!主题思想是要用s_enter替代(senter+( ...

把赋值的位置调整一下就行了
写在那些变量赋值完毕的后面,判断条件之前

使用道具 举报

Rank: 3Rank: 3

精华
0
UID
100877
积分
180
帖子
66
主题
14
阅读权限
40
注册时间
2012-2-27
最后登录
2020-3-26
8#
发表于 2013-7-4 14:11:54 |只看该作者
谢谢,搞定了

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

bottom

静态版|手机版|联系我们|交易开拓者 ( 粤ICP备07044698   

GMT+8, 2024-5-13 18:50

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部