搜索
查看: 8774|回复: 8

WR交易系统

[复制链接]

发表于 2005-9-26 07:22 | 显示全部楼层

WR交易系统

来自:MACD论坛(bbs.shudaoyoufang.com) 作者:spirit 浏览:8774 回复:8

这是老外写的源码,
里面我略加注释了一下,就应该都能看懂了.
我认为其中为了界定主图K线的上下边界曲线构造的序列数组挺复杂的.
那么下面会给出美股AA的图形,让大家有形像的认识.
在建仓时有这两条曲线的值参与运算得出进场价位.
可以看出它是一种以短周期持仓来抓价格形成背离之后的反弹波幅的策略.



  1. var INTRADAYTRADES: boolean;
  2. var SHORTDAYS, LONGDAYS, LONGPROFITTARGET, SHORTPROFITTARGET, WILLIAMSHIGH, WILLIAMSLOW, EMAPERIOD, ATRPERIOD, START, NLASTVARBAR, MT2, DE, PERIOD, MT, UT, X1, DT, XSERIES, UT2, DT2, BBUPPER, BBLOWER, LOWFACTOR, HIGHFACTOR, P: integer;

  3. {#OptVar5 Default: 3}
  4. {#OptVar4 Default: 27}
  5. {#OptVar3 Default: 115}
  6. {#OptVar2 Default: 85}
  7. {#OptVar1 Default: 15}
  8. {This is where you can adjust most of the
  9. variables to optimize the script }

  10. ShortDays := 2;
  11. LongDays := 2;
  12. LongProfitTarget := 10;
  13. ShortProfitTarget := 5;
  14. WilliamsHigh := 75;
  15. WilliamsLow  := 25;
  16. IntradayTrades := false;

  17. HideVolume;   {Can delete this line if you need volume}

  18. {------------------}



  19. EMAPeriod := 9;
  20. ATRPeriod := 30;
  21. Start := EMAPeriod + ATRPeriod;
  22. nLastVarBar := BarCount() - 1;

  23. {Williams %R}

  24. var X: float;
  25. var PCTRPANE, SMOOTHR, BAR: integer;
  26. PctRPane := CreatePane( 75, true, true );
  27. PlotSeries( WilliamsRSeries( 14 ), PctRPane, 511, #Thick );
  28. SmoothR := WilderMASeries( WilliamsRSeries( 14 ), 4 );
  29. DrawLabel( 'WilliamsR( 14 )', PctRPane );
  30. PlotSeries( SmoothR, PctRPane, #Black, #Thin );

  31. //以WR指标窗口内的WR的值做WMA后所得值,以大于80或小于20为条件,将K线背景改变颜色
  32. for Bar := 20 to BarCount - 1 do
  33. begin
  34.   x := GetSeriesValue( Bar, SmoothR );
  35.   if x < 20 then
  36.     SetBackgroundColor( Bar, #RedBkg )
  37.   else if x > 80 then
  38.     SetBackgroundColor( Bar, #BlueBkg );

  39. end;



  40. mt2 := CreateSeries();
  41. de := #OptVar1 / 10;  {Nr Std Dev's}
  42. period := #OptVar5;   //3


  43. mt := EMASeries(#Close, period);//收盘价3周期EMA
  44. ut := EMASeries(mt, period);//再次EMA
  45. x1 := ((2 * period) / (period + 1)); // 2*3/4
  46. dt := MultiplySeriesValue(ut, x1); //以ut的值乘以x1,再取整数部分,形成新的数组
  47. dt := SubtractSeries(dt, ut);//以每个dt减去ut后,形成新的数组
  48. dt := DivideSeriesValue(dt, ((period - 1) / (period + 1)) );//以dt的每个值除以一个数,得到新的数组

  49. xseries := SubtractSeries(#Close, dt);//以收盘价减去dt的值,得新数组

  50. //用以下循环给mt2数组赋值,应该是没有现成的数组函数
  51. for Bar := period + 1 to BarCount - 1 do
  52. begin
  53. x := abs(GetSeriesValue(Bar, xseries));//取xseries数组元素的绝对值
  54. SetSeriesValue(Bar, mt2, x);
  55. end;

  56. mt2 := EMASeries(mt2, period);//mt2的3周期ema
  57. ut2 := EMASeries(mt2, period);
  58. dt2 := MultiplySeriesValue(ut2, x1);
  59. dt2 := SubtractSeries(dt2, ut2);
  60. dt2 := DivideSeriesValue(dt2, ((period - 1) / (period + 1)) );


  61. xseries := MultiplySeriesValue(dt2, de);//相乘得数组
  62. BBUpper := AddSeries(dt, xseries);//相加得数组
  63. BBLower := SubtractSeries(dt, xseries);//相减得数组


  64. PlotSeries(BBUpper, 0, #Blue, 0);//按BBUpper数组,画指标曲线
  65. PlotSeries(BBLower, 0, #Green, 0);

  66. PlotSeries(dt, 0, #Red, 0);

  67. LowFactor := #OptVar2 / 100; // 85/100
  68. HighFactor := #OptVar3/ 100; // 115/100




  69. { Implement Trading Rules }

  70. {BuyLimitPrice := 0.0; }

  71. InstallStopLoss( 5 );//设定止损为5%
  72. {InstallProfitTarget ( ProfitTarget );}//可选设定止盈语句



  73. //因为有两条均线,所以把开台时间定在了star+1,即两条均线都有效的时候.
  74. for Bar := Start + 1 to nLastVarBar do
  75. begin

  76. ApplyAutoStops( Bar );//自动停损设置成有效状态


  77.     if GetSeriesValue( Bar, WilliamsRSeries( 14 )) < WilliamsLow then
  78. //如果WR指标值<low
  79.     if not LastActivePosition >= 0 then
  80.     ShortAtLimit(Bar + 1, (GetSeriesValue(Bar, BBUpper) * 1.05), '' );
  81. //下根K线限价做空价位选择主图上边界的值与1.05的乘积

  82.     if GetSeriesValue( Bar, WilliamsRSeries( 14 )) > WilliamsHigh then
  83.     if not LastActivePosition >= 0 then
  84.     BuyAtLimit(Bar + 1, (GetSeriesValue(Bar, BBLower) * 0.95), '' );
  85. //下根K线限价做多,价位选择主图下边界的值与0.95的乘积

  86. for P := 0 to PositionCount - 1 do
  87.    begin
  88.         if PositionActive( P ) then             //有仓位吗
  89.         begin
  90.            if PositionLong( P ) then            //是多仓吗
  91.            if bar + 1 - positionEntryBar( p ) > 0 then    //持仓周期>0吗
  92.            if bar + 1 - positionEntryBar( p ) >= LongDays then   //持仓周期>2吗
  93.            begin
  94.               SellAtMarket( Bar + 1, P, 'LongDaysExpired' );//下周期平仓,因持仓周期限制
  95.            end;
  96.            if PositionLong( P ) then
  97.            if bar + 1 - positionEntryBar( p ) > 0 then
  98.            if PositionProfit( P )/PriceClose(Bar) >= LongProfitTarget then  //净利润(美元)与收盘价的比>10
  99.            begin
  100.               SellAtMarket( Bar + 1, P, 'LongProfitTarget' );  //平仓卖出因利润达到
  101.            end;
  102.            if not PositionLong( P )then         //没有多仓,即有空仓
  103.            if bar + 1 - positionEntryBar( p ) > 0 then   //持仓周期>0吗
  104.            if bar + 1 - positionEntryBar( p ) >= ShortDays then    //持仓周期>2吗
  105.            begin;
  106.               CoverAtMarket( Bar + 1, P, 'ShortDaysExpired' );  //下周期平仓,因持仓周期限制
  107.            end;
  108.            if not PositionLong( P )then
  109.            if bar + 1 - positionEntryBar( p ) > 0 then
  110.            if PositionProfit( P )/PriceClose(Bar) >= ShortProfitTarget then   //净利润(美元)与收盘价的比>5
  111.            begin;
  112.               CoverAtMarket( Bar + 1, P, 'ShortProfitTarget' );  //下周期平仓,因做空利润
  113.            end;
  114.            
  115.            if PositionLong( P ) then     //如果有多仓
  116.            if (IntradayTrades) then      //这是开关,前面有赋值语句,默认是false,则下面语句忽略执行
  117.            if PositionProfit( P )/PriceClose(Bar) >= LongProfitTarget then
  118.            begin
  119.               SellAtMarket( Bar + 1, P, 'LongProfitTarget' );
  120.            end;

  121.            if not PositionLong( P )then
  122.            if (IntradayTrades) then
  123.            if PositionProfit( P )/PriceClose(Bar) >= ShortProfitTarget then
  124.            begin;
  125.               CoverAtMarket( Bar + 1, P, 'ShortProfitTarget' );
  126.            end;

  127.         end;
  128.    end;

  129. end;
复制代码

[ Last edited by spirit on 2005-9-26 at 08:06 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
参与人数 1 +6 时间 理由
夕阳武士㊣ + 6 2005-9-26 08:00

查看全部评分

金币:
奖励:
热心:
注册时间:
2002-12-21

回复 使用道具 举报

发表于 2005-9-26 09:03 | 显示全部楼层
太多了,看不懂了
金币:
奖励:
热心:
注册时间:
2004-3-7

回复 使用道具 举报

大盘不是我家开的

发表于 2005-9-26 12:17 | 显示全部楼层
看来的学学,这种编成还没学会
金币:
奖励:
热心:
注册时间:
2002-12-10

回复 使用道具 举报

发表于 2005-9-26 13:01 | 显示全部楼层
学习学习
金币:
奖励:
热心:
注册时间:
2005-8-10

回复 使用道具 举报

发表于 2005-9-26 13:04 | 显示全部楼层
谢谢楼主,学习
金币:
奖励:
热心:
注册时间:
2004-4-28

回复 使用道具 举报

签到天数: 1 天

发表于 2005-9-26 13:32 | 显示全部楼层
谁能把公式转成飞狐的?
金币:
奖励:
热心:
注册时间:
2002-7-3

回复 使用道具 举报

签到天数: 585 天

缠学将上证指数拆解到底艾略特波浪看盘

发表于 2006-2-26 20:29 | 显示全部楼层
okokok
金币:
奖励:
热心:
注册时间:
2003-6-30

回复 使用道具 举报

发表于 2012-5-17 14:05 | 显示全部楼层
#*d1*# 这顶你,这样也可以
金币:
奖励:
热心:
注册时间:
2011-7-17

回复 使用道具 举报

签到天数: 2 天

发表于 2012-5-17 16:02 | 显示全部楼层
没精力看这么长的源码,纯顶。
金币:
奖励:
热心:
注册时间:
2009-5-8

回复 使用道具 举报

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

本版积分规则

本站声明:MACD仅提供交流平台,请交流人员遵守法律法规。
值班电话:18209240771   微信:35550268

举报|意见反馈|手机版|MACD俱乐部

GMT+8, 2025-4-22 02:35 , Processed in 0.035458 second(s), 12 queries , MemCached On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表