开拓者期货期权程序化系统交易论坛

标题: 关于盈利之后暂停交易一段时间的问题,急求! [打印本页]

作者: fl1652546    时间: 2016-1-26 13:41:46     标题: 关于盈利之后暂停交易一段时间的问题,急求!

我想实现一个信号盈利超过一定范围后暂停交易几根K线(例如螺纹盈利超过1000(100点)后,自平仓K线起50根K线不在交易),我利用entryprice,exitprice进行判断不行,利用持仓盈利也不行。请大神们帮忙指点一下,源码如下:
Params
    Numeric Length1(13);
        Numeric Length2(55);
       
        Numeric lev1_profit(200);//止盈参数
        Numeric lev2_profit(500);
        Numeric lev3_profit(1000);
        Numeric LV1(0);
        Numeric LV2(0.5);
        Numeric LV3(0.9);
        Numeric Maxloss(0.01);//止损参数
        Numeric Lots(1);//交易手数
Vars
    NumericSeries BuyPosition(0);
        NumericSeries SellPosition(0);
        Bool Conbuy(False);
        Bool ConSellShort(False);

        NumericSeries Tradecontrol(0);//盈利后暂停交易控制器,1为暂停50根K线,2为暂停100根K线
        NumericSeries Tradebutton(1);//是否交易的开关,1为交易,0为暂停交易
Begin
//指标公式
    BuyPosition = XAverage(C,Length1);
        SellPosition = XAverage(LinearRegSlope(C,21)*20+C,Length2);
        PlotNumeric("买线",BuyPosition,0);
        PlotNumeric("卖线",SellPosition,0);
//入场条件
    Conbuy=CrossOver(BuyPosition[1],SellPosition[1]);
        ConSellShort=CrossUnder(BuyPosition[1],SellPosition[1]);
       
        if(Tradebutton==1)
            {
                        if (Conbuy )
                    {
                               Buy(Lots,open);
                                   PlotString("多开","多开",Low-5,Yellow,1);
                          }
                        if (ConSellShort)
                    {
                             SellShort(Lots,open);
                                 PlotString("空开","空开",High+5,Yellow,1);
                        }
            }
// 初始止损
        if (marketposition>0 and close[1]<entryprice*(1-Maxloss))
            {
                    sell(0,open);
                        PlotString("多损","多损",High+5,Yellow,1);
                }
        if (marketposition<0 and close[1]>entryprice*(1+Maxloss))
            {
                    buytocover(0,open);
                        PlotString("空损","空损",Low-5,Yellow,1);
                }

// 多单盈利离场
        if (marketposition>0 and maxpositionprofit>lev3_profit)               
            {
                    if (positionprofit<maxpositionprofit*LV3)
                            {
                                        sell (0,open);
                                        PlotString("多离3","多离3",High+5,Yellow,1);
                                        Tradecontrol=2;
                                }
                }
        if (marketposition>0 and maxpositionprofit>lev2_profit)
            {
                    if (positionprofit<maxpositionprofit*LV2)
                            {
                                        sell (0,open);
                                        PlotString("多离2","多离2",High+5,Yellow,1);
                                        Tradecontrol=1;
                                }
                }
        if (marketposition>0 and maxpositionprofit>lev1_profit)
            {
                    if (positionprofit<maxpositionprofit*LV1)
                            {
                                        sell (0,open);
                                        PlotString("多离1","多离1",High+5,Yellow,1);
                                }
                }
  
// 空单盈利离场  
          
        if (marketposition<0 and maxpositionprofit>lev3_profit)
            {
                        if (positionprofit<maxpositionprofit*LV3)
                            {
                                     buytocover(0,open);
                                        PlotString("空离3","空离3",Low-5,Yellow,1);
                                        Tradecontrol=2;
                                }
                }
    if (marketposition<0 and maxpositionprofit>lev2_profit)
            {
                        if (positionprofit<maxpositionprofit*LV2)
                            {
                                       buytocover(0,open);
                                        PlotString("空离2","空离2",Low-5,Yellow,1);
                                        Tradecontrol=1;
                                }
                }
        if (marketposition<0 and maxpositionprofit>lev1_profit)
            {
                        if (positionprofit<maxpositionprofit*LV1)
                            {
                                     buytocover(0,open);
                                        PlotString("空离1","空离1",Low-5,Yellow,1);
                                }
                }
//大幅盈利之后暂停交易       
        if (Tradecontrol==2 and BarsSinceExit<50 )
        {
                    Tradebutton=0;
                }else
        if (Tradecontrol==1 and BarsSinceExit<30 )
                    {
                        Tradebutton=0;
                    }else
                            {
                                    Tradebutton=1;
                                }
End
作者: tbheyihao    时间: 2016-1-26 16:45:55

建立一个序列变量,比如delaybars(0).
1、在盈利平仓时,将delaybars=50.
2、然后在程序开始阶段,写上一句,delaybars=delaybars-1;
3、开仓条件中补上 delaybars==0的附加条件。
作者: fl1652546    时间: 2016-1-27 09:46:27

能否在我的程序上加一下,根据你的描述我加上后没有信号了
作者: fl1652546    时间: 2016-1-27 13:45:09

Params
    Numeric Length1(13);
        Numeric Length2(55);
       
        Numeric lev1_profit(200);//止盈参数
        Numeric lev2_profit(500);
        Numeric lev3_profit(1000);
        Numeric LV1(0);
        Numeric LV2(0.5);
        Numeric LV3(0.9);
        Numeric Maxloss(0.01);//止损参数
        Numeric Lots(1);//交易手数
Vars
    NumericSeries BuyPosition(0);
        NumericSeries SellPosition(0);
        Bool Conbuy(False);
        Bool ConSellShort(False);
        NumericSeries DelayTradeBars(0);

Begin
//指标公式
    BuyPosition = XAverage(C,Length1);
        SellPosition = XAverage(LinearRegSlope(C,21)*20+C,Length2);
        PlotNumeric("买线",BuyPosition,0);
        PlotNumeric("卖线",SellPosition,0);
//入场条件
    Conbuy=CrossOver(BuyPosition[1],SellPosition[1]);
        ConSellShort=CrossUnder(BuyPosition[1],SellPosition[1]);
       
        if(DelayTradeBars==0)
            {
                        if (Conbuy )
                    {
                               Buy(Lots,open);
                                   PlotString("多开","多开",Low-5,Yellow,1);
                          }
                        if (ConSellShort)
                    {
                             SellShort(Lots,open);
                                 PlotString("空开","空开",High+5,Yellow,1);
                        }
            }
// 初始止损
        if (marketposition>0 and close[1]<entryprice*(1-Maxloss))
            {
                    sell(0,open);
                        PlotString("多损","多损",High+5,Yellow,1);
                }
        if (marketposition<0 and close[1]>entryprice*(1+Maxloss))
            {
                    buytocover(0,open);
                        PlotString("空损","空损",Low-5,Yellow,1);
                }

// 多单盈利离场
    DelayTradeBars=DelayTradeBars-1;
        if (marketposition>0 and maxpositionprofit>lev3_profit)               
            {
                    if (positionprofit<maxpositionprofit*LV3)
                            {
                                        sell (0,open);
                                        DelayTradeBars=50;
                                        PlotString("多离3","多离3",High+5,Yellow,1);
                                }
                }
        if (marketposition>0 and maxpositionprofit>lev2_profit)
            {
                    if (positionprofit<maxpositionprofit*LV2)
                            {
                                        sell (0,open);
                                        PlotString("多离2","多离2",High+5,Yellow,1);
                                }
                }
        if (marketposition>0 and maxpositionprofit>lev1_profit)
            {
                    if (positionprofit<maxpositionprofit*LV1)
                            {
                                        sell (0,open);
                                        PlotString("多离1","多离1",High+5,Yellow,1);
                                }
                }
  
// 空单盈利离场  
          
        if (marketposition<0 and maxpositionprofit>lev3_profit)
            {
                        if (positionprofit<maxpositionprofit*LV3)
                            {
                                     buytocover(0,open);
                                        DelayTradeBars=50;
                                        PlotString("空离3","空离3",Low-5,Yellow,1);
                                }
                }
    if (marketposition<0 and maxpositionprofit>lev2_profit)
            {
                        if (positionprofit<maxpositionprofit*LV2)
                            {
                                       buytocover(0,open);
                                        PlotString("空离2","空离2",Low-5,Yellow,1);
                                }
                }
        if (marketposition<0 and maxpositionprofit>lev1_profit)
            {
                        if (positionprofit<maxpositionprofit*LV1)
                            {
                                     buytocover(0,open);
                                        PlotString("空离1","空离1",Low-5,Yellow,1);
                                }
                }
End
作者: fl1652546    时间: 2016-1-27 13:46:37

我这样改完之后信号就没有了,麻烦技术人员帮忙看一下哪里有问题




欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/) Powered by Discuz! X2