您现在的位置:程序化交易>> 期货公式>> 交易开拓者(TB)>> 开拓者知识>>正文内容

TB公式中加仓问题 [开拓者 TB]

  • 咨询内容: 问题描述:
    1. 实盘操作加仓未成功(autotrade没有加仓记录,实际账户也没有加仓记录)
    2. 我在加仓操作前面加了日志,却记录很多加仓记录
    本地记录日志文件截取
    20160111 90005 Add Sell: Unit=2, Price=5495
    20160111 90005 Add Sell: Unit=2, Price=5495
    20160111 90006 Add Sell: Unit=2, Price=5495
    20160111 90006 Add Sell: Unit=2, Price=5495
    20160111 90007 Add Sell: Unit=2, Price=5495
    20160111 90007 Add Sell: Unit=2, Price=5495
    20160111 90008 Add Sell: Unit=2, Price=5495
    20160111 90008 Add Sell: Unit=2, Price=5495
    20160111 90009 Add Sell: Unit=2, Price=5495
    20160111 90009 Add Sell: Unit=2, Price=5495
    20160111 90010 Add Sell: Unit=2, Price=5495
    20160111 90010 Add Sell: Unit=2, Price=5495
    20160111 90011 Add Sell: Unit=2, Price=5495
    20160111 90011 Add Sell: Unit=2, Price=5495
    ....
    参数定义源码
    Params
            Numeric LongLength(60);
            Numeric StopLossSet(20);
            Numeric AvgLen(20);                                                         // 高低点均线计算周期
            Numeric AbsDisp(5);                                                         // 高低点均线前移周期
            Numeric AddSet(10);        //加仓情况
            Numeric FirstUnit(1);
            Numeric AddUnit(2);
            Numeric MaxUnit(5);
            Numeric MaxLoss(2000);
            Numeric TradeOffset(1);                                                        //交易滑点
    Vars
            //NumericSeries UpperAvg(0);                                           // 通道上轨
            NumericSeries LowerAvg(0);                                           // 通道下轨
            NumericSeries LongMA(0);
            //NumericSeries ExitAvg(0);                                            // 通道中轨
            BoolSeries RangeLeadS(False);                                          // 是否RangeLead
            NumericSeries MedianPrice;                                             // K线中价
            NumericSeries range;                                                       // 振幅       
            NumericSeries HighestAfterEntry(0);
            NumericSeries LowestAfterEntry(0);
            Numeric MyPrice(0);
            NumericSeries MyLastPrice(0);
            NumericSeries MyUnit(0);
            String LogFileName;
            String Msg;
            Bool ShouldCover(False);

    加仓公式源代码:
            // 系统入场
            //...省略代码 参考 平移高低点均值通道与K线中值突破

            // 系统出场或加仓       
            If(MarketPosition == -1)             // 开仓后N根K线内用中轨止损,N根K线后用上轨止损,N=参数ExitBar
            {
                    //初始化及计算动态止盈
                    MyPrice=Open;
                    ShouldCover=False;
                   
                    if(BarsSinceEntry==0)
                    {
                            HighestAfterEntry=High;
                            LowestAfterEntry=Low;
                    }else
                    {
                            LowestAfterEntry = Min(LowestAfterEntry, Low);
                            HighestAfterEntry = Max(HighestAfterEntry, High);
                    }
                   
                    Commentary("LowestAfterEntry"+Text(LowestAfterEntry));
                    Commentary("HighestAfterEntry"+Text( HighestAfterEntry));
                   
                    //动态止损线
                    If(BarsSinceEntry>0)
                    {
                            Commentary(" LowestAfterEntry[1]"+Text( LowestAfterEntry[1]));
                            PlotNumeric("DynamicStopLossLine", LowestAfterEntry[1]+StopLossSet);

                            //动态止损
                            if(High>LowestAfterEntry[1]+StopLossSet)
                            {
                                    ShouldCover=True;
                                    MyPrice=LowestAfterEntry[1]+StopLossSet+TradeOffset;
                            }
                            //加仓
                            else if(Open<=MyLastPrice-AddSet and MyUnit<MaxUnit)
                            {
                                    MyUnit=MyUnit+AddUnit;
                                    MyLastPrice=Min(MyLastPrice-AddSet, Open-TradeOffset);
                                    Sellshort(AddUnit,MyLastPrice);
                           
                                    Msg="Add Sell: Unit="+Text(AddUnit)+", Price="+Text(MyLastPrice);
                                    LogMsg(Msg, BarStatus==2, LogFileName);
                            }
                    }
            }

    LogMsg函数源码

    Params
            String Msg;
            Bool Enabled(false);
            String FileName("D:\\autotrade");
    Vars
            String LogTime;
            String Path("D:\\Autotrade\\Trade_");
    Begin
           
            Commentary(Msg);
            Path=Path+FileName+"_"+A_AccountID+"_"+Text(CurrentDate)+".log";
           
            IF(Enabled)
            {
                    LogTime=Text(CurrentDate)+" "+Text(CurrentTime*1000000)+" ";
                    FileAppend(Path, LogTime+Msg);
            }
            Return Msg;
    End

     

  • TB技术人员: 追加系统入场代码
            // 集合竞价和小节休息过滤
            If(!CallAuctionFilter()) Return;
           
            LogFileName="My_K_V3_S_"+Symbol;
           
            // 指标计算
            range = High - Low;
            //UpperAvg = Average(High[AbsDisp], AvgLen);          // 计算N周期前高点的MA,N=参数AbsDisp
            LowerAvg = Average(Low[AbsDisp], AvgLen);           // 计算N周期前低点的MA,N=参数AbsDisp
            LongMA=Average(C, LongLength);
            MedianPrice = (High + Low)*0.5;                     // 计算K线中点
           
            PlotNumeric("LowMA",LowerAvg);
            PlotNumeric("LongMA", LongMA);
            PlotNumeric("LowerAvg", LowerAvg);
           
            RangeLeadS = MedianPrice < Low[1] and Range > Range[1];   // 当K线中点小于前一根K线低点并且振幅〉上一根振幅时,RangeLeadS为真

            //策略退出条件
            if(NetProfit<=-MaxLoss)
            {
                    If(MarketPosition!=0)
                    {
                            ShouldCover=True;
                            MyPrice=Open+TradeOffset;
                    }
                    PlotBool("Failed", false);
            }
            // 系统入场
            Else If(MarketPosition == 0)
            {
                    If(RangeLeadS[1] and Close[1] < LowerAvg[1] and LowerAvg<LowerAvg[1] and LongMA[1]<LongMA[2] )                // 上根K线RangeLeadS为真,并且上一根收盘价小于N周期前低点的MA,当前无空仓,则开空仓
                    {
                            MyUnit=FirstUnit;
                            MyLastPrice=Open-TradeOffset;
                            Sellshort(MyUnit, MyLastPrice);
                           
                            Msg="SellShort: Unit="+Text(MyUnit)+", Price="+Text(MyLastPrice);
                            LogMsg(Msg, BarStatus==2, LogFileName);
                    }
            }

     

  • TB客服: 麻烦高手指点下问题所在,非常感谢!

     

  • 网友回复:
    sywg8011006110 发表于 2016-1-12 09:02
    麻烦高手指点下问题所在,非常感谢!

    先试一下在全局交易设置里设置为允许连续建仓,以及加仓次数设大一些,再看看信号有无加仓信号。

     

  • 网友回复:
    小米 发表于 2016-1-12 13:41
    先试一下在全局交易设置里设置为允许连续建仓,以及加仓次数设大一些,再看看信号有无加仓信号。 ...

    请问我的日志文件重复记录日志怎么解释?

 

有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友

可联系技术人员 QQ: 511411198  点击这里给我发消息进行 有偿 编写!不贵!点击查看价格!


【字体: 】【打印文章】【查看评论

相关文章

    没有相关内容