设为首页收藏本站

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

大师们帮我看看如何修改策略(RSI做多策略) [复制链接]

Rank: 2

精华
0
UID
225252
积分
60
帖子
31
主题
5
阅读权限
30
注册时间
2015-12-17
最后登录
2020-3-19
跳转到指定楼层
1#
发表于 2016-1-25 14:43:54 |只看该作者 |倒序浏览
策略思路:
   RSI 多头策略
  1 多头入场: RSI 上破55, 在下一根Bar开盘价入场。
  2 多头出场: RSI下破45,在下一根bar 开盘价出场。
3 保护性止损: 当价格下破 进场价减一定倍数(初始值为1)的ATR时,止损出场。
4 跟踪止盈(止损): 多头入场后,记录入场后最高点,然后在价格下破 最高点减 一定倍数ATR( 初始值设定为1时) 止盈(止损)出场

另外,如果策略想加上一个再进场,止损后,如果价格突破10日高点,再进场,要怎么写。。。

初学阶段,自己改了几次,越改越不对路了。 只好向大师求教。。。

Params
        Numeric Length(14) ;
        Numeric DnTrend(45) ;
        Numeric UpTrend(55);
        Numeric Lots(0);
        Numeric CoATR(1);
        Numeric ATRLength(14);
        Numeric TrailStopCoATR(1);
       
Vars
        NumericSeries NetChgAvg( 0 );
        NumericSeries TotChgAvg( 0 );
        Numeric SF( 0 );
        NumericSeries Change( 0 );       
        NumericSeries ChgRatio( 0 ) ;
        NumericSeries RSIValue;
        NumericSeries ProtectStopLoss(0);
        NumericSeries HighestAfterEntry(0);
        NumericSeries TrailStopLine(0);
       
Begin
        // 集合竞价和小节休息过滤
                If(!CallAuctionFilter()) Return;
               
        If(CurrentBar <= Length - 1)
        {
                NetChgAvg = ( Close - Close[Length] ) / Length ;
                TotChgAvg = Average( Abs( Close - Close[1] ), Length ) ;
        }Else
        {
                SF = 1/Length;
                Change = Close - Close[1] ;
                NetChgAvg = NetChgAvg[1] + SF * ( Change - NetChgAvg[1] ) ;
                TotChgAvg = TotChgAvg[1] + SF * ( Abs( Change ) - TotChgAvg[1] ) ;       
        }
       
        If( TotChgAvg <> 0 )
        {
                ChgRatio = NetChgAvg / TotChgAvg;
        }else
        {
                ChgRatio = 0 ;
        }       
        RSIValue = 50 * ( ChgRatio + 1 );       
        PlotNumeric("RSI",RSIValue);
        PlotNumeric("UpTrend",UpTrend);
        PlotNumeric("DnTrend",DnTrend);       
       
       
        If (MarketPosition<>1&& RSIValue[1]>UpTrend)
        {
        Buy(Lots,Open);
        ProtectStopLoss=LastEntryPrice-CoATR*AvgTrueRange(ATRLength);
        }
        Commentary("rotectStopLoss"+Text(ProtectStopLoss));
        If(MarketPosition==1&&BarsSinceEntry>0)
        {       
        If (Low<=ProtectStopLoss)
        {
        Sell(0,Min(Open,ProtectStopLoss));
        Commentary("rotectStop");
        }
        }
        If (BarsSinceEntry==0)
        HighestAfterEntry=High;
        Else
        HighestAfterEntry=Max(HighestAfterEntry[1],High);       
        TrailStopLine=HighestAfterEntry-TrailStopCoATR*AvgTrueRange(ATRLength);
        Commentary("TrailStopLine"+Text(TrailStopLine));
        If (MarketPosition==1&&BarsSinceEntry>0)
        {       
        If(Low<=TrailStopLine[1])
        {
        Sell(0,Min(Open,TrailStopLine[1]));
        Commentary("TrailStop");       
        }
        }
        If(MarketPosition==1&&BarsSinceEntry>0)
        {
        If(RSIValue[1]<DnTrend)
        {
        Sell(0,Open);
        Commentary("反手出场");
        }
        }
End

期市新手

TB官方客服

Rank: 1

精华
0
UID
223939
积分
20
帖子
20
主题
0
阅读权限
10
注册时间
2015-11-26
最后登录
2019-8-17
2#
发表于 2016-1-25 16:19:10 |只看该作者
本帖最后由 Allin9999 于 2016-1-25 16:21 编辑

在你的代码基础上做了一些修改,供你参考。再进场部分我就按照方便处理的原则简化处理了,假定RSI跌破UpTrend,就不算再进场了。这个具体写的时候还是要根据自己的策略进行调整。
  1. Params
  2.         Numeric Length(14) ;
  3.         Numeric DnTrend(45) ;
  4.         Numeric UpTrend(55);
  5.         Numeric Lots(0);
  6.         Numeric CoATR(1);
  7.         Numeric ATRLength(14);
  8.         Numeric TrailStopCoATR(1);
  9.         
  10. Vars
  11.         NumericSeries NetChgAvg( 0 );
  12.         NumericSeries TotChgAvg( 0 );
  13.         Numeric SF( 0 );
  14.         NumericSeries Change( 0 );        
  15.         NumericSeries ChgRatio( 0 ) ;
  16.         NumericSeries RSIValue;
  17.         NumericSeries ProtectStopLoss(0);
  18.         NumericSeries HighestAfterEntry(0);
  19.         NumericSeries TrailStopLine(0);

  20.         NumericSeries AtrValue;
  21.         Numeric RangeHigh;
  22.         
  23. Begin
  24.         // 集合竞价和小节休息过滤
  25.         If(!CallAuctionFilter()) Return;
  26.                
  27.         If(CurrentBar <= Length - 1)
  28.         {
  29.                 NetChgAvg = ( Close - Close[Length] ) / Length ;
  30.                 TotChgAvg = Average( Abs( Close - Close[1] ), Length ) ;
  31.         }Else
  32.         {
  33.                 SF = 1/Length;
  34.                 Change = Close - Close[1] ;
  35.                 NetChgAvg = NetChgAvg[1] + SF * ( Change - NetChgAvg[1] ) ;
  36.                 TotChgAvg = TotChgAvg[1] + SF * ( Abs( Change ) - TotChgAvg[1] ) ;        
  37.         }
  38.         
  39.         If( TotChgAvg <> 0 )
  40.         {
  41.                 ChgRatio = NetChgAvg / TotChgAvg;
  42.         }else
  43.         {
  44.                 ChgRatio = 0 ;
  45.         }        
  46.         RSIValue = 50 * ( ChgRatio + 1 );        
  47.         PlotNumeric("RSI",RSIValue);
  48.         PlotNumeric("UpTrend",UpTrend);
  49.         PlotNumeric("DnTrend",DnTrend);        
  50.         

  51.         AtrValue = AvgTrueRange(ATRLength);
  52.         Commentary("AtrValue="+Text(AtrValue));

  53.         RangeHigh = Highest(H[1],10);
  54.                
  55.         If(MarketPosition<>1 && RSIValue[2] < UpTrend And RSIValue[1]>UpTrend)
  56.         {
  57.                 Buy(Lots,Open);
  58.                 ProtectStopLoss=LastEntryPrice-CoATR*AtrValue;
  59.         }
  60.         Else If(MarketPosition<>1 And High >= RangeHigh And RSIValue[1]>UpTrend)
  61.         {
  62.                 Buy(Lots,Max(Open,RangeHigh));
  63.                 ProtectStopLoss=LastEntryPrice-CoATR*AtrValue;
  64.         }
  65.         Commentary("ProtectStopLoss"+Text(ProtectStopLoss));

  66.         If(MarketPosition==1 && BarsSinceEntry>0)
  67.         {
  68.                 If(RSIValue[1]<DnTrend)
  69.                 {
  70.                         Sell(0,Open);
  71.                         Commentary("反手出场");
  72.                 }
  73.         }
  74.                
  75.         If(MarketPosition==1 && BarsSinceEntry>0)
  76.         {
  77.                 If (Low<=ProtectStopLoss)
  78.                 {
  79.                         Sell(0,Min(Open,ProtectStopLoss));
  80.                         Commentary("ProtectStop");
  81.                 }
  82.         }
  83.                
  84.         If (BarsSinceEntry==0)
  85.                 HighestAfterEntry=High;
  86.         Else
  87.                 HighestAfterEntry=Max(HighestAfterEntry[1],High);
  88.                        
  89.         TrailStopLine = HighestAfterEntry - TrailStopCoATR*AtrValue;

  90.         Commentary("TrailStopLine"+Text(TrailStopLine));

  91.         If(MarketPosition==1&&BarsSinceEntry>0)
  92.         {        
  93.                 If(Low<=TrailStopLine[1])
  94.                 {
  95.                         Sell(0,Min(Open,TrailStopLine[1]));
  96.                         Commentary("TrailStop");        
  97.                 }
  98.         }
  99.                
  100. End
复制代码

使用道具 举报

Rank: 2

精华
0
UID
225252
积分
60
帖子
31
主题
5
阅读权限
30
注册时间
2015-12-17
最后登录
2020-3-19
3#
发表于 2016-1-25 21:05:54 |只看该作者
Allin9999 发表于 2016-1-25 16:19
在你的代码基础上做了一些修改,供你参考。再进场部分我就按照方便处理的原则简化处理了,假定RSI跌破UpTre ...

非常感谢!!

使用道具 举报

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

bottom

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

GMT+8, 2024-5-11 03:49

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部