设为首页收藏本站

 找回密码
 注册
查看: 2298|回复: 1

求助:请老师指导下跨周期日线bias(乖离率)函数 [复制链接]

Rank: 1

精华
0
UID
233612
积分
22
帖子
10
主题
8
阅读权限
10
注册时间
2016-5-3
最后登录
2021-3-4
发表于 2016-11-18 10:14:36 |显示全部楼层
本帖最后由 xjy313 于 2016-11-21 09:25 编辑

请老师指导下我编写的跨周期日线bias(乖离率)函数,在5分钟公式中调用该函数,但是取出的数值和图表应该对应的乖离率值不对,应该是我的函数编写思路有问题,谢谢。
Params
         Numeric TimeFrame(1440);        // 目标时间周期参数,参数说明参见MtBar
         Numeric BarsBack(1);                // 目标时间周期BAR偏移参数,说明见MtBar函数
        Numeric L1(6);       // 乖离率周期参数
        Numeric L2(12);  
         Numeric L3(24);  
         NumericRef oBISA1;             // 以目标时间周期下的K线数据计算出的乖离率
        NumericRef oBISA2;             // 以目标时间周期下的K线数据计算出的乖离率
        NumericRef oBISA3;             // 以目标时间周期下的K线数据计算出的乖离率
Vars
         NumericSeries mtBarCnt;
         NumericSeries mtClose;
         Numeric refCurBar;
         Numeric refOpen;
         Numeric refHigh;
         Numeric refLow;
         Numeric refClose;
         Numeric refVol;
         Numeric refOpenInt;
         
         Numeric SumValue1(0);
         Numeric SumValue2(0);
         Numeric SumValue3(0);
         Numeric i;
         Numeric j(0);
Begin
         mtBarCnt = MtBar(TimeFrame,BarsBack,refCurBar,refOpen,refHigh,refLow,refClose,refVol,refOpenInt);
         mtClose = refClose;

         SumValue1 = MtSummation(mtClose,mtBarCnt,L1);
         SumValue2 = MtSummation(mtClose,mtBarCnt,L2);
         SumValue3 = MtSummation(mtClose,mtBarCnt,L3);
         oBISA1 =(mtClose- SumValue1/L1)/SumValue1/L1*100;
         oBISA2 =(mtClose- SumValue2/L2)/SumValue2/L2*100;
         oBISA3 =(mtClose- SumValue3/L3)/SumValue3/L3*100;
         Return mtBarCnt;
End

Rank: 1

精华
0
UID
233612
积分
22
帖子
10
主题
8
阅读权限
10
注册时间
2016-5-3
最后登录
2021-3-4
发表于 2016-12-2 13:20:16 |显示全部楼层
//------------------------------------------------------------------------

// 简称: ITF_T_DualThrust_V101

// 名称: 国贸期货上海营业部量化交易 客户群:186100158

// 类别: 公式应用

// 类型: 用户应用

// 输出:

//------------------------------------------------------------------------



Params

        Numeric Lots(1);

        Numeric TimesMaxToday(1);  //限制当天开仓最多次数;

        Numeric K1(0.5);

        Numeric K2(0.5);

        Numeric Mday(1);

        Numeric Nday(1);

        Numeric offset(0);

        

Vars

        Numeric BuyRange(0);

        Numeric SellRange(0);

        Numeric BuyTrig(0);

        Numeric SellTrig(0);

        Numeric HH;

        Numeric LL;

        Numeric HC;

        Numeric LC;

        Numeric i_offset;

        Numeric BuyPosition;

        Numeric SellPosition;

        NumericSeries TimesToday(0);  //记录当天开仓次数;



Begin



        If(Barstatus==2 )

        {

                If( Time==0.090000 And CurrentTime<=0.090001) Return;

                If( Time==0.101500 And CurrentTime<=0.103001) Return;

                If( Time==0.133000 And CurrentTime<=0.133001) Return;

        }

        

        If(CurrentBar > 44*Max(Mday,Nday))//使用的是5分钟周期,其它的周期自己做相应修改

        {

                i_offset = offset*MinMove*PriceScale;

                HH = Highest(HighD(1),Mday);

                HC = Highest(CloseD(1),Mday);

                LL = Lowest(LowD(1),Mday);

                LC = Lowest(CloseD(1),Mday);

                If((HH - LC) >= (HC - LL))

                {

                        SellRange = HH - LC;

                }

                Else

                {

                        SellRange = HC - LL;

                }

                HH = Highest(HighD(1),Nday);

                HC = Highest(CloseD(1),Nday);

                LL = Lowest(LowD(1),Nday);

                LC = Lowest(CloseD(1),Nday);



                If((HH - LC) >= (HC - LL))

                {

                        BuyRange = HH - LC;

                }

                Else

                {

                        BuyRange = HC - LL;

                }

                BuyTrig = K1*BuyRange;

                SellTrig = K2*SellRange;

                BuyPosition = OpenD(0)+BuyTrig;

                SellPosition = OpenD(0)-SellTrig;

                PlotNumeric("BuyPosition",BuyPosition);

                PlotNumeric("SellPosition",SellPosition);

               

                //开盘第一根K线将当天开仓次数清零;

                If(BarsSinceToday==0)

                {

                        TimesToday = 0;

                }

                //开仓;

                If(TimesToday<TimesMaxToday And CurrentBar>90)

                {

                        If(MarketPosition!=1)

                        {

                                If(High>=BuyPosition)

                                {

                                        Buy(lots,Max(Open,BuyPosition)+i_offset);

                                        TimesToday = TimesToday+1;

                                        Return;

                                }

                        }

                        If(MarketPosition!=-1)

                        {

                                If(Low<=SellPosition)

                                {

                                        SellShort(lots,Min(Open,SellPosition)-i_offset);

                                        TimesToday = TimesToday+1;

                                        Return;

                                }

                        }

                }

                //平仓;

                If(MarketPosition==1 and Low<=SellPosition)

                {

                        Sell(lots,Min(Open,SellPosition)-i_offset);

                        TimesToday = TimesToday+1;

                        Return;

                }

                If(MarketPosition==-1 and High>=BuyPosition)

                {

                        BuyToCover(lots,Max(Open,BuyPosition)+i_offset);

                        TimesToday = TimesToday+1;

                        Return;

                }

        }

        Commentary("当天开仓次数="+Text(TimesToday));

         

End



//------------------------------------------------------------------------

// 编译版本        GS2010.12.08

// 用户版本        2013/03/28 11:02

// 版权所有        国贸期货上海营业部量化交易 客户群:186100158

// 更改声明        TradeBlazer Software保留对TradeBlazer平台

//                        每一版本的TrabeBlazer公式修改和重写的权利

使用道具 举报

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

bottom

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

GMT+8, 2024-3-28 19:34

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部