设为首页收藏本站

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

关于盈利之后暂停交易一段时间的问题,急求! [复制链接]

Rank: 1

精华
0
UID
131362
积分
32
帖子
20
主题
9
阅读权限
10
注册时间
2012-7-25
最后登录
2021-1-22
跳转到指定楼层
1#
发表于 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

期市新手

TB官方客服

Rank: 1

精华
0
UID
223934
积分
18
帖子
18
主题
0
阅读权限
10
注册时间
2015-11-26
最后登录
2016-5-12
2#
发表于 2016-1-26 16:45:55 |只看该作者
建立一个序列变量,比如delaybars(0).
1、在盈利平仓时,将delaybars=50.
2、然后在程序开始阶段,写上一句,delaybars=delaybars-1;
3、开仓条件中补上 delaybars==0的附加条件。

使用道具 举报

Rank: 1

精华
0
UID
131362
积分
32
帖子
20
主题
9
阅读权限
10
注册时间
2012-7-25
最后登录
2021-1-22
3#
发表于 2016-1-27 09:46:27 |只看该作者
能否在我的程序上加一下,根据你的描述我加上后没有信号了

使用道具 举报

Rank: 1

精华
0
UID
131362
积分
32
帖子
20
主题
9
阅读权限
10
注册时间
2012-7-25
最后登录
2021-1-22
4#
发表于 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

使用道具 举报

Rank: 1

精华
0
UID
131362
积分
32
帖子
20
主题
9
阅读权限
10
注册时间
2012-7-25
最后登录
2021-1-22
5#
发表于 2016-1-27 13:46:37 |只看该作者
我这样改完之后信号就没有了,麻烦技术人员帮忙看一下哪里有问题

使用道具 举报

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

bottom

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

GMT+8, 2024-4-25 20:57

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部