danningham penetration.afl
上传用户:shiqiang
上传日期:2009-06-12
资源大小:1289k
文件大小:4k
源码类别:

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    danningham penetration
  4. //  Author/Uploader: N. Sagi 
  5. //  E-mail:          april4000@hotmail.co.il
  6. //  Date/Time Added: 2004-03-17 13:48:49
  7. //  Origin:          
  8. //  Keywords:        danningham penetration vbscript
  9. //  Level:           semi-advanced
  10. //  Flags:           system
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=345
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=345
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  this furmula try to simulate the
  17. //
  18. //  danningham penetration method, using
  19. //
  20. //  vbscript inside it.
  21. //
  22. //  if you find a way to improve it,
  23. //
  24. //  you can send the improvment back to me :)
  25. //
  26. //------------------------------------------------------------------------------
  27. ////////////////////////////////////////////////
  28. //danningham penetration writen by SAGI. 2004.//
  29. //APRIL4000@hotmail.co.il                     //
  30. ////////////////////////////////////////////////
  31. EnableScript("vbscript");
  32. //ApplyStop( 0, 1, Optimize( "loss", 2, 0, 3, 0.5 ), 0 );
  33. //ApplyStop( 2, 1, Optimize( "trailing", 2, 0, 15, 0.5 ), 0 );
  34. //ApplyStop( 1, 1, Optimize( "profit", 2, 0, 15, 0.5 ), 0 );
  35. ApplyStop( 0, 1, 3, 0 );//loss
  36. //ApplyStop( 2, 1, 2, 0 );//trailing
  37. //ApplyStop( 1, 1, 2, 0 );//profit
  38. //ApplyStop( 3, 1, 2, 0 );//bars
  39. Buy=Short=Sell=Cover=O;
  40. //start vbscript
  41. <%
  42. pbuy = AFL("buy")
  43. pshort = AFL("short")
  44. psell = AFL("sell")
  45. pcover = AFL("cover")
  46. pclose=AFL("close")
  47. popen=AFL("open")
  48. phigh=AFL("high")
  49. plow=AFL("low")
  50. Dayflag=0
  51. Dayopen=0
  52. Dayhigh=0
  53. Daylow=0
  54. Dayclose=0
  55. stoploos=0
  56. '
  57. Dayflags=0
  58. Dayopens=0
  59. Dayhighs=0
  60. Daylows=0
  61. Daycloses=0
  62. stoplooss=0
  63.  for i = 0 to UBound( pbuy )
  64. '=====Long============
  65.      'init arrays
  66.      pbuy ( i )=0
  67.      psell ( i )=0
  68.      
  69.      select Case Dayflag
  70.      Case 0
  71.       Dayflag=1
  72.       Dayopen=popen(i)
  73.       Dayhigh=phigh(i)
  74.       Daylow=plow(i)
  75.       Dayclose=pclose(i)
  76.      Case 1
  77.       if phigh(i)>dayhigh then
  78.        Dayopen=popen(i)
  79.        Dayhigh=phigh(i)
  80.        Daylow=plow(i)
  81.        Dayclose=pclose(i)
  82.       else
  83.        if phigh(i)<Daylow then
  84.         Dayflag=2
  85.         Dayopen=popen(i)
  86.         Dayhigh=phigh(i)
  87.         Daylow=plow(i)
  88.         Dayclose=pclose(i)
  89.         psell(i)=1
  90.         stoploos=0
  91.        end if
  92.       end if
  93.      Case 2
  94.       if plow(i)<Daylow then
  95.        Dayopen=popen(i)
  96.        Dayhigh=phigh(i)
  97.        Daylow=plow(i)
  98.        Dayclose=pclose(i)
  99.       else
  100.        if pclose(i)>Dayclose then
  101.         pbuy(i)=1
  102.         stoploos=plow(i)
  103.         Dayflag=0
  104.         Dayopen=0
  105.         Dayhigh=0
  106.         Daylow=0
  107.         Dayclose=0
  108.        end if
  109.       end if
  110.      end select
  111.      if stoploos>0 then
  112.       if stoploos > pclose(i) then
  113.        psell(i)=1
  114.        stoploos=0
  115.       end if
  116.      end if
  117.  
  118. '===========Short==============
  119. 'init arrays
  120.      
  121.      pshort ( i )=0
  122.      pcover ( i )=0
  123.      select Case Dayflags
  124.      Case 0
  125.       Dayflags=1
  126.       Dayopens=popen(i)
  127.       Dayhighs=phigh(i)
  128.       Daylows=plow(i)
  129.       Daycloses=pclose(i)
  130.      Case 1
  131.       if plow(i)<daylows then
  132.        Dayopens=popen(i)
  133.        Dayhighs=phigh(i)
  134.        Daylows=plow(i)
  135.        Daycloses=pclose(i)
  136.       else
  137.        if plow(i)>Dayhighs then
  138.         Dayflags=2
  139.         Dayopens=popen(i)
  140.         Dayhighs=phigh(i)
  141.         Daylows=plow(i)
  142.         Daycloses=pclose(i)
  143.         pcover(i)=1
  144.         stoplooss=0
  145.        end if
  146.       end if
  147.      Case 2
  148.       if phigh(i)>Dayhighs then
  149.        Dayopens=popen(i)
  150.        Dayhighs=phigh(i)
  151.        Daylows=plow(i)
  152.        Daycloses=pclose(i)
  153.       else
  154.        if pclose(i)<Daycloses then
  155.         pshort(i)=1
  156.         stoplooss=phigh(i)
  157.         Dayflags=0
  158.         Dayopens=0
  159.         Dayhighs=0
  160.         Daylows=0
  161.         Daycloses=0
  162.        end if
  163.       end if
  164.      end select
  165.      if stoplooss>0 then
  166.       if stoplooss < pclose(i) then
  167.        pcover(i)=1
  168.        stoplooss=0
  169.       end if
  170.      end if
  171.  next
  172. AFL("pbuy")=pbuy 
  173. AFL("pshort")=pshort 
  174. AFL("psell")=psell 
  175. AFL("pcover")=pcover
  176. %>
  177. //end vbscript
  178. //shot the signals
  179. Buy=pbuy AND (MA(C,9)>Ref(MA(C,9),-1)OR MA(C,20)>Ref(MA(C,20),-1));
  180. Sell=0 ;
  181. Short=pshort AND (MA(C,9)<Ref(MA(C,9),-1)OR MA(C,20)<Ref(MA(C,20),-1));
  182. Cover=0 ;
  183.   
  184.  
  185.  
  186.    
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.            
  194.    
  195.  
  196.  
  197.          
  198.  
  199.  
  200.          
  201.      
  202.  
  203.    
  204.