设为首页收藏本站

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

多头不止损,而空头第二根bar就平仓,是什么原因? [复制链接]

Rank: 3Rank: 3

精华
0
UID
93332
积分
172
帖子
74
主题
22
阅读权限
40
注册时间
2012-1-17
最后登录
2017-11-22
跳转到指定楼层
1#
发表于 2012-5-18 09:55:20 |只看该作者 |倒序浏览
一个简单的股指程序,高于upline开空,低于downline开多,开仓比较顺利,但止损问题很大,多头不止损,而空头第二根bar就平仓,是什么原因?请高手指点
Params
    Numeric offset(10);
    Numeric stoplossSet(5);
Vars
        Numeric EntryPrice;
        NumericSeries upline;
        NumericSeries downline;
        Bool Condition1;
        Bool Condition2;
        BoolSeries bShortStoped ;
        BoolSeries bLongStoped ;
Begin

   
       
        if(CurrentBar == 0 || Date != Date[1])
        {
           bShortStoped = False ;
           bLongStoped = False ;
        } Else
        {
           upline = Close[1] + offset ;
           downline = Close[1] - offset;
       
           Condition1 =( MarketPosition == 0 && High> upline && bShortStoped == False && Time < 0.151000);
           Condition2 = (MarketPosition == 0 && Low< downline && bLongStoped == False && Time < 0.151000);
          
           Commentary("Condition1="+IIFString(Condition1,"True","False"));
           Commentary("Condition2="+IIFString(Condition2,"True","False"));

           PlotNumeric ("upline",upline) ;
           PlotNumeric ("dowmline",downline) ;
        }
       
        if (Condition1)
        {
                EntryPrice=Min(open,upline-0.2);
                SellShort(1,EntryPrice);
        }
       
        if (Condition2)
        {
                EntryPrice = Max(open,downline+0.2);
                Buy(1,EntryPrice);
        }
       
       
        If(MarketPosition==1 /*&& Low <= EntryPrice - StopLossSet */&& BarsSinceEntry>0)
        {
                Sell(1,Min(Open,EntryPrice - StopLossSet));
                bLongStoped = True;
        }
        if(MarketPosition==-1 /*&& High >= EntryPrice + StopLossSet */&& BarsSinceEntry>0)
        {
                BuyToCover(1,Max(EntryPrice + StopLossSet,open));
                bShortStoped = True;
        }
       
        if(Time >= 0.1513)
        {
                BuyToCover(1,Open);
                Sell(1,Open);
        }
       
End
吃得苦中苦,方为人上人

Rank: 10Rank: 10Rank: 10

精华
20
UID
4
积分
22709
帖子
4802
主题
64
阅读权限
255
注册时间
2007-7-20
最后登录
2024-1-15
2#
发表于 2012-5-18 14:15:35 |只看该作者
为什么你的EntryPrice要在不同条件下分别计算?直接用AvgEntryPrice代替试试?

使用道具 举报

Rank: 3Rank: 3

精华
0
UID
93332
积分
172
帖子
74
主题
22
阅读权限
40
注册时间
2012-1-17
最后登录
2017-11-22
3#
发表于 2012-5-18 14:34:24 |只看该作者
nopain 发表于 2012-5-18 14:15
为什么你的EntryPrice要在不同条件下分别计算?直接用AvgEntryPrice代替试试?

谢谢。可试了还是不行啊。。。纠结。开仓部分没什么问题,止损部分问题大

使用道具 举报

Rank: 10Rank: 10Rank: 10

精华
20
UID
4
积分
22709
帖子
4802
主题
64
阅读权限
255
注册时间
2007-7-20
最后登录
2024-1-15
4#
发表于 2012-5-18 15:55:03 |只看该作者
你的upline,dnline计算有问题。
完整代码如下:
  1. Params
  2.     Numeric offset(10);
  3.     Numeric stoplossSet(5);
  4. Vars
  5.     Numeric MyEntryPrice;
  6.     NumericSeries upline;
  7.     NumericSeries downline;
  8.     Bool Condition1;
  9.     Bool Condition2;
  10.     BoolSeries bShortStoped;
  11.     BoolSeries bLongStoped;
  12. Begin
  13.         if(CurrentBar == 0 || Date != Date[1])
  14.         {
  15.                 bShortStoped = False ;
  16.                 bLongStoped = False ;
  17.                 upline = Close[1] + offset;
  18.                 downline = Close[1] - offset;          
  19.         } Else
  20.         {      
  21.                 Condition1 =( MarketPosition == 0 && High> upline && bShortStoped == False && Time < 0.151000);
  22.                 Condition2 = (MarketPosition == 0 && Low< downline && bLongStoped == False && Time < 0.151000);
  23.          
  24.                 Commentary("Condition1="+IIFString(Condition1,"True","False"));
  25.         Commentary("Condition2="+IIFString(Condition2,"True","False"));

  26.         PlotNumeric ("upline",upline) ;
  27.         PlotNumeric ("dowmline",downline) ;
  28.         }
  29.       
  30.         if (Condition1)
  31.         {
  32.                 MyEntryPrice=Min(open,upline-0.2);
  33.                 SellShort(1,MyEntryPrice);
  34.         }
  35.    
  36.         if (Condition2)
  37.         {
  38.                 MyEntryPrice = Max(open,downline+0.2);
  39.                 Buy(1,MyEntryPrice);
  40.         }
  41.       
  42.       
  43.         If(MarketPosition==1 && Low <= AvgEntryPrice - StopLossSet && BarsSinceEntry>0)
  44.         {
  45.                 Sell(1,Min(Open,AvgEntryPrice - StopLossSet));
  46.                 bLongStoped = True;
  47.         }
  48.         if(MarketPosition==-1 && High >= AvgEntryPrice + StopLossSet && BarsSinceEntry>0)
  49.         {
  50.                 BuyToCover(1,Max(AvgEntryPrice + StopLossSet,open));
  51.                 bShortStoped = True;
  52.         }
  53.    
  54.         if(Time >= 0.1513)
  55.         {
  56.                 BuyToCover(1,Open);
  57.                 Sell(1,Open);
  58.         }       
  59. End
复制代码

使用道具 举报

Rank: 3Rank: 3

精华
0
UID
93332
积分
172
帖子
74
主题
22
阅读权限
40
注册时间
2012-1-17
最后登录
2017-11-22
5#
发表于 2012-5-18 17:05:02 |只看该作者
nopain 发表于 2012-5-18 15:55
你的upline,dnline计算有问题。
完整代码如下:

多谢多谢,可以正常止损了。值得好好总结

使用道具 举报

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

bottom

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

GMT+8, 2024-5-9 06:25

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部