设为首页收藏本站

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

请管理帮忙看看为什么不止损 [复制链接]

Rank: 1

精华
0
UID
224840
积分
49
帖子
30
主题
13
阅读权限
10
注册时间
2015-12-10
最后登录
2019-10-11
跳转到指定楼层
1#
发表于 2016-1-25 11:34:18 |只看该作者 |倒序浏览
这个总是不启动止损,只是在14:55平仓。另外,要想实盘测试,应该改动哪些呢?谢谢
Begin
   
       
        TrailingStop2=(HighestAfterEntry-MyEntryPrice)*0.8;
        TrailingStop3=(MyEntryPrice-LowestAfterEntry)*0.45;
        MidLine = AverageFC(Close,Length);
        Band = StandardDev(Close,Length,2);
        UpLine = MidLine + Offset * Band;
        DownLine = MidLine - Offset * Band;
        PlotNumeric("UpLine",UpLine);
        PlotNumeric("DownLine",DownLine);
        PlotNumeric("MidLine",MidLine);
        MA8=XAverage(Close,L8);
        MA20=XAverage(Close,L20);
        PlotNumeric("MA8",MA8);
        PlotNumeric("MA20",MA20);
       
       
        集合竞价和小节休息过滤
        If(!CallAuctionFilter()) Return;
       
       
        If(Time>=0.1455){//如果要实盘测试,把Time改为CurrentTime
                If(MarketPosition == 1)
                Sell(0,Close);
                If(MarketPosition == -1)
                BuyToCover(0,Close);
                return;
                        }
                                               
        If(BarsSinceEntry==0) //条件满足,开仓bar
        {
            HighestAfterEntry=Close;
            LowestAfterEntry=Close;//赋初值为新价格
        If(MarketPosition<>0)//有持仓时执行如下代码
            {
            HighestAfterEntry=Max(HighestAfterEntry,AvgEntryPrice);//开仓bar,将开仓价和当时的收盘价的较大值保留到HighestAfterEntry
            LowestAfterEntry=Min(LowestAfterEntry,AvgEntryPrice);同上,较小值保留
            }
        }Else  //非开仓bar时进行以下运算
           {
            HighestAfterEntry=Max(HighestAfterEntry,High);//记录下当前bar的最高点,用于下一个bar的跟踪止损判断
            LowestAfterEntry=Min(LowestAfterEntry,Low);//同上,最低点
            }
            Commentary("HighestAfterEntry="+Text(HighestAfterEntry));
       
            Commentary("LowestAfterEntry="+Text(LowestAfterEntry));
       
            MinPoint=MinMove*PriceScale;
            MyEntryPrice=AvgEntryPrice;
               
       
        If(MarketPosition==1 And BarsSinceEntry>=1)//有多仓的情况
        {
            If(HighestAfterEntry[1]>=MyEntryPrice + TrailingStart2*minpoint)//第二级跟踪止损
                {
                        If(Low<=HighestAfterEntry[1]-TrailingStop2);
                    {
                MyExitPrice=HighestAfterEntry[1]-TrailingStop2);
                        If(Open<MyExitPrice)MyExitPrice=Open;//如果该bar跳空触发,则用开盘价代替
                Sell(0,MyExitPrice);
                                Return;
            }
         }Else If(HighestAfterEntry[1]>=MyEntryPrice + TrailingStart1*minpoint)//第一级跟踪止损的条件
                    {
                            If(Low<=HighestAfterEntry[1]-TrailingStop1*MinPoint);
                        {
                             MyExitPrice=HighestAfterEntry[1]-TrailingStop1*minpoint;
                                 If(Open<MyExitPrice)MyExitPrice=Open;//如果该bar跳空,则用开盘价代替
                                 Sell(0,myexitprice);
                                         Return;
                         }
                 }Else If(Low<=MyEntryPrice-StopLossSet*MinPoint)//初始止损设置
                {
                     MyExitPrice=MyEntryPrice-StopLossSet*MinPoint;
                     if(Open<MyExitPrice)MyExitPrice=Open; //如果该bar跳空,则用开盘价代替
                     Sell(0,MyExitPrice);
                                         return;
                                         
                 }
         }Else If(MarketPosition==-1 And BarsSinceEntry>=1)//有空仓的情况
         {
                 If(LowestAfterEntry[1]<=MyEntryPrice-TrailingStart2*MinPoint) //第二级跟踪止损
                 {
                                If(High>=LowestAfterEntry[1]+TrailingStop3)
                                {
                                        MyExitPrice=LowestAfterEntry[1]+TrailingStop3);
                                        If(Open>MyExitPrice)MyExitPrice=Open;//跳空,开盘价代替
                                        BuyToCover(0,MyExitPrice);
                                        return;
                                }
                 }Else If(LowestAfterEntry[1]<=MyEntryPrice-TrailingStart1*MinPoint)//第一级跟踪止损条件
                  {
                            If(High>=LowestAfterEntry[1]+TrailingStop1*MinPoint)
                                {
                                        MyExitPrice=LowestAfterEntry[1]+TrailingStop1*MinPoint;
                                        If(Open>MyExitPrice)MyExitPrice=Open;  //跳空,开盘价代替
                                        BuyToCover(0,MyExitPrice);
                                        return;
                                }
                 }Else If(High>=MyEntryPrice + StopLossSet*MinPoint)
                 {
                                        MyExitPrice=MyEntryPrice + StopLossSet*MinPoint;
                                        If(Open>MyExitPrice)MyExitPrice=Open;  //跳空,开盘价代替
                                        BuyToCover(0,MyExitPrice);
                                        return;
                                       
                  }
                  
        }
               
        Con1=CrossOver(MA8,MidLine);
        Con2=Crossunder(MA8,MidLine);
       
        If (Con1 && High>MA8 && High>MA20 && MarketPosition == 0 && Vol > 0)//满足买入准备条件后ENTRYBAR数目内,且大于等于买入多头触发价,多单入场
                       
                Buy(0,Close);
        Else If (Con2 && Low<MA8 && LOW<MA20 && MarketPosition == 0 && Vol > 0) //如果T为1,发一次空单
            SellShort(0,Close);
               
               
          
               
                 
                 End
                         
                                             
       

Rank: 1

精华
0
UID
226180
积分
8
帖子
8
主题
0
阅读权限
10
注册时间
2016-1-4
最后登录
2016-3-29
2#
发表于 2016-2-4 19:37:41 |只看该作者
Begin
   
        
        TrailingStop2=(HighestAfterEntry-MyEntryPrice)*0.8;
        TrailingStop3=(MyEntryPrice-LowestAfterEntry)*0.45;
        MidLine = AverageFC(Close,Length);
        Band = StandardDev(Close,Length,2);
        UpLine = MidLine + Offset * Band;
        DownLine = MidLine - Offset * Band;
        PlotNumeric("UpLine",UpLine);
        PlotNumeric("DownLine",DownLine);
        PlotNumeric("MidLine",MidLine);
        MA8=XAverage(Close,L8);
        MA20=XAverage(Close,L20);
        PlotNumeric("MA8",MA8);
        PlotNumeric("MA20",MA20);
        
        
        集合竞价和小节休息过滤
        If(!CallAuctionFilter()) Return;
        
        
        If(Time>=0.1455){//如果要实盘测试,把Time改为CurrentTime
                If(MarketPosition == 1)
                Sell(0,Close);
                If(MarketPosition == -1)
                BuyToCover(0,Close);
                return;
                        }
                                                
        If(BarsSinceEntry==0) //条件满足,开仓bar
        {
            HighestAfterEntry=Close;
            LowestAfterEntry=Close;//赋初值为新价格
        If(MarketPosition<>0)//有持仓时执行如下代码
            {
            HighestAfterEntry=Max(HighestAfterEntry,AvgEntryPrice);//开仓bar,将开仓价和当时的收盘价的较大值保留到HighestAfterEntry
            LowestAfterEntry=Min(LowestAfterEntry,AvgEntryPrice);同上,较小值保留
            }
        }Else  //非开仓bar时进行以下运算
           {
            HighestAfterEntry=Max(HighestAfterEntry,High);//记录下当前bar的最高点,用于下一个bar的跟踪止损判断
            LowestAfterEntry=Min(LowestAfterEntry,Low);//同上,最低点
            }
            Commentary("HighestAfterEntry="+Text(HighestAfterEntry));
        
            Commentary("LowestAfterEntry="+Text(LowestAfterEntry));
        
            MinPoint=MinMove*PriceScale;
            MyEntryPrice=AvgEntryPrice;
               
        
        If(MarketPosition==1 And BarsSinceEntry>=1)//有多仓的情况
        {
            If(HighestAfterEntry[1]>=MyEntryPrice + TrailingStart2*minpoint)//第二级跟踪止损
                {
                        If(Low<=HighestAfterEntry[1]-TrailingStop2);
看到这里发现有个分号,不知道是啥意思。

使用道具 举报

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

bottom

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

GMT+8, 2024-5-13 14:06

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部