欢迎您光临博庭社区!

 找回密码
 立即注册
查看: 11221|回复: 27

Easy Language 海龟交易转成金魔方   [复制链接]

Rank: 9Rank: 9Rank: 9

发表于 2013-8-19 21:29:41 |显示全部楼层
Easy LanguageTradeStation证券公司所开发的专属编程语言,并内建于TradeStation 交易平台上。该语言主要被用来创建金融图表上的客制化指标,以及创建金融市场的算法交易逻辑,是国际上用来表达量化交易使用的最广泛的语言。除了TradeStation外,国外的MultiCharts平台也完全兼容Easy Language,因此Easy Language有大量可用于实战的策略,是学习,研究,甚至交易的很好资源。

金语言在设计思想上很接近Easy Language,因此Easy Language的策略可以很容易地转换成金魔方的策略。
尤其是在转换工具的帮助下更是毫不费力。点击这里下载转换工具

以下抛砖引玉,用公式转换器转换了一个 Easy Language策略,Turtle,传说中的海龟?转换后没任何修改的运行结果,可见转换是轻松可行的。
原策略代码如下
  1. //Turtle 20-Day Breakout
  2. //Replica //////////////////////////////////////

  3. vars: N(0),StopLoss(1),DV(0),BB(0),AccountBalance(0),DollarRisk
  4. (0),LTT(0),
  5. Tracker(0),LastTrade(0),HBP(0),LBP(0); input: InitialBalance
  6. (100000),Length(20);

  7. if marketposition = 0 then begin
  8. BB = 0;
  9. N = xAverage( TrueRange, Length );
  10. DV = N * BigPointValue;

  11. AccountBalance = InitialBalance;
  12. DollarRisk = AccountBalance * .01;
  13. LTT = IntPortion(DollarRisk/DV);
  14. StopLoss = 2 * DV * LTT;

  15. if LastTrade = -1 then begin
  16. buy LTT shares next bar highest(h,20) or higher;
  17. buy LTT shares next bar highest(h,20) + (0.5*N) or higher;
  18. buy LTT shares next bar highest(h,20) + (1.0*N) or higher;
  19. buy LTT shares next bar highest(h,20) + (1.5*N) or higher;
  20. sellshort LTT shares next bar lowest(l,20) or lower;
  21. sellshort LTT shares next bar lowest(l,20) - (0.5*N) or lower;
  22. sellshort LTT shares next bar lowest(l,20) - (1.0*N) or lower;
  23. sellshort LTT shares next bar lowest(l,20) - (1.5*N) or lower;
  24. end;

  25. if LastTrade = 1 then begin
  26. buy LTT shares next bar highest(h,55) or higher;
  27. buy LTT shares next bar highest(h,55) + (0.5*N) or higher;
  28. buy LTT shares next bar highest(h,55) + (1.0*N) or higher;
  29. buy LTT shares next bar highest(h,55) + (1.5*N) or higher;
  30. sellshort LTT shares next bar lowest(l,55) or lower;
  31. sellshort LTT shares next bar lowest(l,55) - (0.5*N) or lower;
  32. sellshort LTT shares next bar lowest(l,55) - (1.0*N) or lower;
  33. sellshort LTT shares next bar lowest(l,55) - (1.5*N) or lower;
  34. end;

  35. end;

  36. // PREVIOUS TRADE TRACKER
  37. if HBP = 0 and h > highest(h,19)[1] then begin
  38. Tracker = 1; HBP = h; LBP = 0;
  39. end;

  40. if LBP = 0 and l < lowest(l,19)[1] then begin
  41. Tracker = -1; LBP = l; HBP = 0;
  42. end;

  43. if Tracker = 1 then begin
  44. if l < HBP - (2*N) then LastTrade = -1;
  45. if h > HBP + (4*N) then LastTrade = 1;
  46. end;

  47. if Tracker = -1 then begin
  48. if h > LBP + (2*N) then LastTrade = -1;
  49. if l < LBP - (4*N) then LastTrade = 1;
  50. end;

  51. // LONG 20
  52. if LastTrade = -1 and marketposition = 1 then begin
  53. BB = BB + 1;
  54. if currentshares = LTT then begin
  55. buy LTT shares next bar highest(h,20)[BB] + (0.5*N) or higher;
  56. buy LTT shares next bar highest(h,20)[BB] + (1.0*N) or higher;
  57. buy LTT shares next bar highest(h,20)[BB]+ (1.5*N) or higher;
  58. end;

  59. if currentshares = LTT * 2 then begin
  60. buy LTT shares next bar highest(h,20)[BB] + (1.0*N) or higher;
  61. buy LTT shares next bar highest(h,20)[BB] + (1.5*N) or higher;
  62. end;

  63. if currentshares = LTT * 3 then
  64. buy LTT shares next bar highest(h,20)[BB] + (1.5*N) or higher;
  65. end;

  66. // LONG 55
  67. if LastTrade = 1 and marketposition = 1 then begin
  68. BB = BB + 1;
  69. if currentshares = LTT then begin
  70. buy LTT shares next bar highest(h,55)[BB] + (0.5*N) or higher;
  71. buy LTT shares next bar highest(h,55)[BB] + (1.0*N) or higher;
  72. buy LTT shares next bar highest(h,55)[BB]+ (1.5*N) or higher;
  73. end;
  74. if currentshares = LTT * 2 then begin
  75. buy LTT shares next bar highest(h,55)[BB] + (1.0*N) or higher;
  76. buy LTT shares next bar highest(h,55)[BB] + (1.5*N) or higher;
  77. end;
  78. if currentshares = LTT * 3 then
  79. buy LTT shares next bar highest(h,55)[BB] + (1.5*N) or higher;
  80. end;
  81. sell ("out-S") next bar lowest(l,10) or lower;

  82. // SHORT 20
  83. if LastTrade = -1 and marketposition = -1 then begin
  84. BB = BB + 1;
  85. if currentshares = LTT then begin
  86. sellshort LTT shares next bar lowest(l,20)[BB] - (0.5*N) or lower;
  87. sellshort LTT shares next bar lowest(l,20)[BB] - (1.0*N) or lower;
  88. sellshort LTT shares next bar lowest(l,20)[BB] - (1.5*N) or lower;
  89. end;
  90. if currentshares = LTT * 2 then begin
  91. sellshort LTT shares next bar lowest(l,20)[BB] - (1.0*N) or lower;
  92. sellshort LTT shares next bar lowest(l,20)[BB] - (1.5*N) or lower;
  93. end;
  94. if currentshares = LTT * 3 then
  95. sellshort LTT shares next bar lowest(l,20)[BB] - (1.5*N) or lower;
  96. end;

  97. // SHORT 55
  98. if LastTrade = 1 and marketposition = -1 then begin
  99. BB = BB + 1;
  100. if currentshares = LTT then begin
  101. sellshort LTT shares next bar lowest(l,55)[BB] - (0.5*N) or lower;
  102. sellshort LTT shares next bar lowest(l,55)[BB] - (1.0*N) or lower;
  103. sellshort LTT shares next bar lowest(l,55)[BB] - (1.5*N) or lower;
  104. end;
  105. if currentshares = LTT * 2 then begin
  106. sellshort LTT shares next bar lowest(l,55)[BB] - (1.0*N) or lower;
  107. sellshort LTT shares next bar lowest(l,55)[BB] - (1.5*N) or lower;
  108. end;
  109. if currentshares = LTT * 3 then
  110. sellshort LTT shares next bar lowest(l,55)[BB] - (1.5*N) or lower;
  111. end;
  112. buytocover ("out-B") next bar highest(h,10) or higher;

  113. // STOPS
  114. if currentshares = (2 * LTT) then StopLoss = DV * 3.5 * LTT;
  115. if currentshares = (3 * LTT) then StopLoss = DV * 4.5 * LTT;
  116. if currentshares = (4 * LTT) then StopLoss = DV * 5.0 * LTT;
  117. setstoploss (StopLoss);

  118. // COMMENTARY
  119. commentary ("LTT: ",LTT,Newline);
  120. commentary ("CurrentShares: ",CurrentShares,Newline);
  121. commentary ("StopLoss: ",StopLoss,Newline);
  122. commentary ("AccountBalance:",AccountBalance,NewLine);
  123. commentary ("LastTrade: ",LastTrade,NewLine);
复制代码
转成金魔方
  1. /// Turtle 20-Day Breakout  
  2. //Replica //////////////////////////////////////  

  3. Variable: N(0 ),StopLoss(1 ),DV(0 ),BB(0 ),AccountBalance(0 ),DollarRisk
  4. (0 ),LTT(0 ),  
  5. Tracker(0 ),LastTrade(0 ),HBP(0 ),LBP(0 ); Input: InitialBalance
  6. (100000 ),Length(20 );  

  7. if MarketPosition  = 0  then begin
  8.   BB := 0 ;
  9.   N := EMA( TrueRange , Length  ) ;
  10.   DV := N * BigPointValue ;
  11.   
  12.   AccountBalance := InitialBalance ;
  13.   DollarRisk := AccountBalance * .01 ;
  14.   LTT := IntPart(DollarRisk/DV ) ;
  15.   StopLoss := 2 * DV * LTT ;
  16.   
  17.   if LastTrade  = -1  then   begin
  18.     Buy('', LTT , HHV(H ,20 ), 0, OT_Stop, OB_NextBar,  '');
  19.     Buy('', LTT , HHV(H ,20 ) + (0.5*N ), 0, OT_Stop, OB_NextBar,  '');
  20.     Buy('', LTT , HHV(H ,20 ) + (1.0*N ), 0, OT_Stop, OB_NextBar,  '');
  21.     Buy('', LTT , HHV(H ,20 ) + (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  22.     SellShort('', LTT , LLV(L ,20 ), 0, OT_Stop, OB_NextBar,  '');
  23.     SellShort('', LTT , LLV(L ,20 ) - (0.5*N ), 0, OT_Stop, OB_NextBar,  '');
  24.     SellShort('', LTT , LLV(L ,20 ) - (1.0*N ), 0, OT_Stop, OB_NextBar,  '');
  25.     SellShort('', LTT , LLV(L ,20 ) - (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  26.   end;
  27.   
  28.   if LastTrade  = 1  then   begin
  29.     Buy('', LTT , HHV(H ,55 ), 0, OT_Stop, OB_NextBar,  '');
  30.     Buy('', LTT , HHV(H ,55 ) + (0.5*N ), 0, OT_Stop, OB_NextBar,  '');
  31.     Buy('', LTT , HHV(H ,55 ) + (1.0*N ), 0, OT_Stop, OB_NextBar,  '');
  32.     Buy('', LTT , HHV(H ,55 ) + (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  33.     SellShort('', LTT , LLV(L ,55 ), 0, OT_Stop, OB_NextBar,  '');
  34.     SellShort('', LTT , LLV(L ,55 ) - (0.5*N ), 0, OT_Stop, OB_NextBar,  '');
  35.     SellShort('', LTT , LLV(L ,55 ) - (1.0*N ), 0, OT_Stop, OB_NextBar,  '');
  36.     SellShort('', LTT , LLV(L ,55 ) - (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  37.   end;
  38.   
  39. end;  

  40. // PREVIOUS TRADE TRACKER  
  41. if HBP  = 0  and H  > HHV(H ,19 )[1 ]  then begin
  42.   Tracker := 1 ; HBP := H ; LBP := 0 ;
  43. end;  

  44. if LBP  = 0  and L  < LLV(L ,19 )[1 ]  then begin
  45.   Tracker := -1 ; LBP := L ; HBP := 0 ;
  46. end;  

  47. if Tracker  = 1  then begin
  48.   if L  < HBP - (2*N )  then     LastTrade := -1 ;
  49.   if H  > HBP + (4*N )  then     LastTrade := 1 ;
  50. end;  

  51. if Tracker  = -1  then begin
  52.   if H  > LBP + (2*N )  then     LastTrade := -1 ;
  53.   if L  < LBP - (4*N )  then     LastTrade := 1 ;
  54. end;  

  55. // LONG 20  
  56. if LastTrade  = -1  and MarketPosition  = 1  then begin
  57.   BB := BB + 1 ;
  58.   if CurrentContracts  = LTT  then   begin
  59.     Buy('', LTT , HHV(H ,20 )[BB ] + (0.5*N ), 0, OT_Stop, OB_NextBar,  '');
  60.     Buy('', LTT , HHV(H ,20 )[BB ] + (1.0*N ), 0, OT_Stop, OB_NextBar,  '');
  61.     Buy('', LTT , HHV(H ,20 )[BB ]+ (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  62.   end;
  63.   
  64.   if CurrentContracts  = LTT * 2  then   begin
  65.     Buy('', LTT , HHV(H ,20 )[BB ] + (1.0*N ), 0, OT_Stop, OB_NextBar,  '');
  66.     Buy('', LTT , HHV(H ,20 )[BB ] + (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  67.   end;
  68.   
  69.   if CurrentContracts  = LTT * 3  then
  70.     Buy('', LTT , HHV(H ,20 )[BB ] + (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  71. end;  

  72. // LONG 55  
  73. if LastTrade  = 1  and MarketPosition  = 1  then begin
  74.   BB := BB + 1 ;
  75.   if CurrentContracts  = LTT  then   begin
  76.     Buy('', LTT , HHV(H ,55 )[BB ] + (0.5*N ), 0, OT_Stop, OB_NextBar,  '');
  77.     Buy('', LTT , HHV(H ,55 )[BB ] + (1.0*N ), 0, OT_Stop, OB_NextBar,  '');
  78.     Buy('', LTT , HHV(H ,55 )[BB ]+ (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  79.   end;
  80.   if CurrentContracts  = LTT * 2  then   begin
  81.     Buy('', LTT , HHV(H ,55 )[BB ] + (1.0*N ), 0, OT_Stop, OB_NextBar,  '');
  82.     Buy('', LTT , HHV(H ,55 )[BB ] + (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  83.   end;
  84.   if CurrentContracts  = LTT * 3  then
  85.     Buy('', LTT , HHV(H ,55 )[BB ] + (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  86. end;  
  87. Sell('', DEFAULT, LLV(L ,10 ), 0, OT_Stop, OB_NextBar, 'out-S');  

  88. // SHORT 20  
  89. if LastTrade  = -1  and MarketPosition  = -1  then begin
  90.   BB := BB + 1 ;
  91.   if CurrentContracts  = LTT  then   begin
  92.     SellShort('', LTT , LLV(L ,20 )[BB ] - (0.5*N ), 0, OT_Stop, OB_NextBar,  '');
  93.     SellShort('', LTT , LLV(L ,20 )[BB ] - (1.0*N ), 0, OT_Stop, OB_NextBar,  '');
  94.     SellShort('', LTT , LLV(L ,20 )[BB ] - (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  95.   end;
  96.   if CurrentContracts  = LTT * 2  then   begin
  97.     SellShort('', LTT , LLV(L ,20 )[BB ] - (1.0*N ), 0, OT_Stop, OB_NextBar,  '');
  98.     SellShort('', LTT , LLV(L ,20 )[BB ] - (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  99.   end;
  100.   if CurrentContracts  = LTT * 3  then
  101.     SellShort('', LTT , LLV(L ,20 )[BB ] - (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  102. end;  

  103. // SHORT 55  
  104. if LastTrade  = 1  and MarketPosition  = -1  then begin
  105.   BB := BB + 1 ;
  106.   if CurrentContracts  = LTT  then   begin
  107.     SellShort('', LTT , LLV(L ,55 )[BB ] - (0.5*N ), 0, OT_Stop, OB_NextBar,  '');
  108.     SellShort('', LTT , LLV(L ,55 )[BB ] - (1.0*N ), 0, OT_Stop, OB_NextBar,  '');
  109.     SellShort('', LTT , LLV(L ,55 )[BB ] - (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  110.   end;
  111.   if CurrentContracts  = LTT * 2  then   begin
  112.     SellShort('', LTT , LLV(L ,55 )[BB ] - (1.0*N ), 0, OT_Stop, OB_NextBar,  '');
  113.     SellShort('', LTT , LLV(L ,55 )[BB ] - (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  114.   end;
  115.   if CurrentContracts  = LTT * 3  then
  116.     SellShort('', LTT , LLV(L ,55 )[BB ] - (1.5*N ), 0, OT_Stop, OB_NextBar,  '');
  117. end;  
  118. BuyToCover('', DEFAULT, HHV(H ,10 ), 0, OT_Stop, OB_NextBar, 'out-B');  

  119. // STOPS  
  120. if CurrentContracts  = (2 * LTT )  then   StopLoss := DV * 3.5 * LTT ;  
  121. if CurrentContracts  = (3 * LTT )  then   StopLoss := DV * 4.5 * LTT ;  
  122. if CurrentContracts  = (4 * LTT )  then   StopLoss := DV * 5.0 * LTT ;  
  123. SetStopLoss (StopLoss ) ;  

  124. // COMMENTARY  
  125. Comment ('LTT: ' ,LTT ,'' ) ;  
  126. Comment ('CurrentShares: ' ,CurrentContracts ,'' ) ;  
  127. Comment ('StopLoss: ' ,StopLoss ,'' ) ;  
  128. Comment ('AccountBalance:' ,AccountBalance ,'' ) ;  
  129. Comment ('LastTrade: ' ,LastTrade ,'' ) ;
复制代码


没经过任何修改的策略在金魔方运行结果,收益不高,但是一个正期望的策略









附件: 你需要登录才可以下载或查看附件。没有帐号?立即注册

使用道具 举报

Rank: 6Rank: 6

发表于 2013-8-28 12:41:00 |显示全部楼层
收藏,学习,研究!

使用道具 举报

Rank: 4

发表于 2013-8-31 19:51:43 |显示全部楼层
学习,学习!

使用道具 举报

Rank: 2

发表于 2013-9-4 16:06:21 |显示全部楼层
收藏,学习,研究!

使用道具 举报

Rank: 2

发表于 2013-9-9 23:32:28 |显示全部楼层
收藏,学习,研究!
太棒了 收益稳定就好退休金就靠这系统了

使用道具 举报

Rank: 2

发表于 2013-9-27 19:08:21 |显示全部楼层
好     嘞

使用道具 举报

Rank: 4

发表于 2013-9-27 20:38:23 |显示全部楼层
学习,学习

使用道具 举报

Rank: 2

发表于 2013-10-12 07:55:00 |显示全部楼层
学习,学习

使用道具 举报

Rank: 2

发表于 2013-10-23 11:54:35 |显示全部楼层
你好,可否编为交易系统或五彩K线模式?

使用道具 举报

Rank: 6Rank: 6

发表于 2013-10-30 06:20:51 |显示全部楼层
收藏学习下

使用道具 举报

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

bottom

Archiver|http://www.patiosoft.com

GMT+8, 2017-12-11 08:38 , Processed in 0.169393 second(s), 12 queries .

花生网 Copyrigh©2012

和讯信息科技有限公司 ALL Rights Reserved 版权所有 复制必究

回顶部