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

标题: 反应趋势交易系统(RTS) [打印本页]

作者: duck_arrow    时间: 2013-5-16 14:12:15     标题: 反应趋势交易系统(RTS)

本帖最后由 duck_arrow 于 2014-10-29 13:33 编辑

最近市场可能比较震荡,农产品有许多震荡交易系统比较适用!所以在研究反应趋势交易系统(RTS)即The Reaction Trend System 由J.WELLES WILDER发明。本人粗糙简略地写了下代码:
  1. Params
  2.         Numeric NumATRs(1);
  3.         Numeric ATRLength(10);
  4.         //Track Stop Profit or Loss
  5.         Numeric StopATRLength(10);
  6.         Numeric StopLossPcnt(3);     //价格止损控制
  7.         Numeric InitialStop(2);     // 初始止损          
  8.         Numeric BreakEvenStop(2);   // 保本止损         
  9.         Numeric TrailStop(2);       // 追踪止损,回撤ATR的倍数       
  10.         //PriceOffset
  11.         Numeric Offset(10);       
  12. Vars
  13.         NumericSeries TPrice;
  14.         //Track Stop Loss or Profit
  15.         NumericSeries HigherAfterEntry;
  16.         NumericSeries LowerAfterEntry;
  17.         NumericSeries HighestAfterEntry;
  18.         NumericSeries LowestAfterEntry;
  19.         BoolSeries          bLongTrailingStoped;
  20.         BoolSeries          bShortTrailingStoped;
  21.         Numeric       MyExitPrice;                          // Exit Market Price
  22.         //Stop Position
  23.         Numeric       MyPrice;
  24.         Numeric       MinPoint;               // 一个最小变动单位,也就是一跳
  25.         Numeric       StopLine;
  26.         Numeric       StopLossBuffSet(15);    //止损位Buffer
  27.         NumericSeries ATRValue;               //记录ATR值
  28.         Numeric       PriceOffset;                          //Buy or Sell Price Buffer
  29.         //RTS Variables
  30.         Numeric HBOP;  //高价突破点
  31.         Numeric LBOP;  //低价突破点
  32.         Numeric SellPoint;  //卖点
  33.         Numeric BuyPoint;  //买点
  34. Begin
  35.         //Price Offset
  36.         PriceOffset = Offset * MinMove * PriceScale;
  37.        
  38.         //Track Stop Profit or Loss
  39.         MinPoint = MinMove*PriceScale;
  40.         ATRValue = AvgTrueRange(StopATRLength);
  41.        
  42.         //KeltnerChannel Variables
  43.         TPrice = (High[1] + Low[1] + Close[1])/3;
  44.         HBOP = 2 * TPrice - 2 * Low[1] + High[1];
  45.         LBOP = 2 * TPrice - 2 * High[1] + Low[1];
  46.         SellPoint = TPrice * 2 - Low[1];   // Sell Point
  47.         BuyPoint = TPrice * 2 - High[1]; //Buy Point

  48.         PlotNumeric("HBOP",HBOP);
  49.         PlotNumeric("LBOP",LBOP);
  50.         PlotNumeric("SellPoint", SellPoint);
  51.         PlotNumeric("BuyPoint", BuyPoint);
  52.        
  53.         If (Open < HBOP And Open > LBOP)
  54.         {
  55.                 //Long Futures High greater than UpperBand
  56.                 If(MarketPosition != 1 And High > BuyPoint)
  57.                 {
  58.                         MyPrice = BuyPoint;
  59.                         If(Open > MyPrice) MyPrice = Open;
  60.                         //Buy(1, Q_BidPrice + PriceOffset);
  61.                         //Buy(1, MyPrice + PriceOffset);
  62.                         SellShort(1, MyPrice - PriceOffset);
  63.                 }
  64.                 //Short Futures Low less than LowerBand
  65.                 If(MarketPosition != -1 And Low < SellPoint)
  66.                 {
  67.                         MyPrice = SellPoint;               
  68.                         If(Open < MyPrice) MyPrice = Open;
  69.                         //SellShort(1, Q_AskPrice - PriceOffset);
  70.                         //SellShort(1, MyPrice - PriceOffset);
  71.                         Buy(1, MyPrice + PriceOffset);
  72.                        
  73.                 }
  74.                
  75.         }  Else If(Open > HBOP) {
  76.                 //Long Futures High greater than UpperBand
  77.                 If(MarketPosition != 1)
  78.                 {
  79.                         MyPrice =  HBOP;
  80.                         If(Open > MyPrice) MyPrice = Open;
  81.                         //Buy(1, Q_BidPrice + PriceOffset);
  82.                         Buy(1, MyPrice + PriceOffset);
  83.                 }
  84.         } Else If(Open < LBOP) {
  85.                 //Short Futures Low less than LowerBand
  86.                 If(MarketPosition != -1)
  87.                 {
  88.                         MyPrice = LBOP;               
  89.                         If(Open < MyPrice) MyPrice = Open;
  90.                         //SellShort(1, Q_AskPrice - PriceOffset);
  91.                         SellShort(1, MyPrice - PriceOffset);
  92.                 }       
  93.         }

  94.         /* Set Loss Postion */
  95.         MinPoint = MinMove * PriceScale;
  96.         Myprice = EntryPrice * (1 - StopLossPcnt * 0.01);
  97.         If(MarketPosition==1 and Low <= Myprice and BarsSinceEntry>0)
  98.         {
  99.                 Myprice=Min(Myprice,Open);
  100.                 Sell(0, Myprice - stopLossBuffSet * MinPoint);
  101.                 Commentary("Price Pcnt Stop Loss");
  102.         }
  103.         Myprice = EntryPrice * (1 + StopLossPcnt * 0.01);
  104.         If(MarketPosition==-1 and High>=Myprice and BarsSinceEntry>0)
  105.         {
  106.                 Myprice=Max(Myprice,Open);
  107.                 BuyToCover(0, Myprice + stopLossBuffSet * MinPoint);
  108.                 Commentary("Price Pcnt Stop Loss");
  109.         }
  110.         /* Set Loss Postion */
  111. End
复制代码
代码中应该还需要计算Buy Day(B), Sell Dya(S), 还有Oday。但是不知道如何计算得出当前Bar应该是 B or S or O。如果得出当前Bar是 B就做Long操作。如果是S就做Short操作。本人在恒温器策略中得到启示见原帖:http://bbs.tb18.net/thread-24916-1-1.html
恒温器中是这样确定的。
                keyofday=(HighD(0)+LowD(0)+CloseD(0))/3;
                If(Date<>Date[1]){
                If(CloseD(1)>keyofday[1])
                {
                selleasierday=1;//空头日
                }Else{
                buyeasierday=1;//多头日
                }
希望大家给点建议!!!
作者: ggyyff    时间: 2013-5-16 18:30:06

先顶了 再看
作者: ypxyls    时间: 2013-5-17 06:33:52

牛!
作者: topgun0791    时间: 2016-7-17 11:34:15

不理想




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