智能交易网,程序化交易,自动交易,量化交易

 找回密码
 注册

QQ登录

只需一步,快速开始

手机短信登录

参加MT4智能交易编程培训,7课免费在线试听MT4指标,EA代写,或EA指标加密账户远程验证服务 最完善商业MT4跟单系统(0.1秒极速响应不漏单)
为论坛做贡献有奖学金,奖学金可直接换真钱 扫本站微信公 众号部分视频课程指标EA免费得智能交易网MT4操盘神器,扫公众号免费得
查看: 1847|回复: 2

求助 改指标均线显示问题

[复制链接]
发表于 2015-4-28 08:08:15 | 显示全部楼层 |阅读模式
改指标均线显示问题,没有行情的时候(如周六、日停盘)均线显示正常
有行情的时候均线显示不正常,在最后1、2K线处均线向下出一个尾巴
11.jpg

AllAverages_v2.5 & bands nmc.mq4

21.65 KB, 下载次数: 136

回复

使用道具 举报

 楼主| 发表于 2015-4-28 08:11:31 | 显示全部楼层
指标源代码:

  1. //+------------------------------------------------------------------+
  2. //|                                             AllAverages_v2.5.mq4 |
  3. //|                             Copyright ?2007-09, TrendLaboratory |
  4. //|            [url]http://finance.groups.yahoo.com/group/TrendLaboratory[/url] |
  5. //|                                   E-mail: [email]igorad2003@yahoo.co.uk[/email] |
  6. //+------------------------------------------------------------------+
  7. // List of MAs:
  8. // MA_Method= 0: SMA        - Simple Moving Average
  9. // MA_Method= 1: EMA        - Exponential Moving Average
  10. // MA_Method= 2: Wilder     - Wilder Exponential Moving Average
  11. // MA_Method= 3: LWMA       - Linear Weighted Moving Average
  12. // MA_Method= 4: SineWMA    - Sine Weighted Moving Average
  13. // MA_Method= 5: TriMA      - Triangular Moving Average
  14. // MA_Method= 6: LSMA       - Least Square Moving Average (or EPMA, Linear Regression Line)
  15. // MA_Method= 7: SMMA       - Smoothed Moving Average
  16. // MA_Method= 8: HMA        - Hull Moving Average by Alan Hull
  17. // MA_Method= 9: ZeroLagEMA - Zero-Lag Exponential Moving Average
  18. // MA_Method=10: DEMA       - Double Exponential Moving Average by Patrick Mulloy
  19. // MA_Method=11: T3         - T3 by T.Tillson
  20. // MA_Method=12: ITrend     - Instantaneous Trendline by J.Ehlers
  21. // MA_Method=13: Median     - Moving Median
  22. // MA_Method=14: GeoMean    - Geometric Mean
  23. // MA_Method=15: REMA       - Regularized EMA by Chris Satchwell
  24. // MA_Method=16: ILRS       - Integral of Linear Regression Slope
  25. // MA_Method=17: IE/2       - Combination of LSMA and ILRS
  26. // MA_Method=18: TriMAgen   - Triangular Moving Average generalized by J.Ehlers
  27. // MA_Method=19: VWMA       - Volume Weighted Moving Average
  28. // MA_Method=20: JSmooth    - Smoothing by Mark Jurik
  29. // List of Prices:
  30. // Price    = 0 - Close  
  31. // Price    = 1 - Open  
  32. // Price    = 2 - High  
  33. // Price    = 3 - Low  
  34. // Price    = 4 - Median Price   = (High+Low)/2  
  35. // Price    = 5 - Typical Price  = (High+Low+Close)/3  
  36. // Price    = 6 - Weighted Close = (High+Low+Close*2)/4
  37. // Price    = 7 - Heiken Ashi Close  
  38. // Price    = 8 - Heiken Ashi Open
  39. // Price    = 9 - Heiken Ashi High
  40. // Price    =10 - Heiken Ashi Low

  41. #property copyright "Copyright ?2007-09, TrendLaboratory"
  42. #property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"

  43. #property indicator_chart_window
  44. #property indicator_buffers 7
  45. #property indicator_color1  Yellow
  46. #property indicator_width1  2  
  47. #property indicator_color2  DeepSkyBlue
  48. #property indicator_width2  2  
  49. #property indicator_color3  Tomato
  50. #property indicator_width3  2  
  51. #property indicator_color4  Gray
  52. #property indicator_color5  Gray
  53. #property indicator_color6  Gray
  54. #property indicator_color7  Gray
  55. #property indicator_style4  STYLE_DOT
  56. #property indicator_style5  STYLE_DOT
  57. #property indicator_style6  STYLE_DOT
  58. #property indicator_style7  STYLE_DOT

  59. //----
  60. extern int     TimeFrame    =  0;
  61. extern int     Price        =  0;
  62. extern int     MA_Period    = 14;
  63. extern int     MA_Shift     =  0;
  64. extern int     MA_Method    =  0;
  65. extern int     Color_Mode   =  1;
  66. extern int     Sound_Mode   =  1; //0-off,1-on(works only with Color_Mode=1)
  67. extern int     Sound_Shift  =  0; //0-open bar(multiple),1-closed bar(once)
  68. extern string  Buy_Sound    =  "alert.wav";
  69. extern string  Sell_Sound   =  "alert2.wav";
  70. extern int     BandType     = 0;
  71. extern double  LevelUp      = 0;
  72. extern double  LevelDown    = 0;
  73. extern double  Level2Up     = 0;
  74. extern double  Level2Down   = 0;

  75. extern string  PriceMode    = "";
  76. extern string  _0           = "Close";
  77. extern string  _1           = "Open";
  78. extern string  _2           = "High";
  79. extern string  _3           = "Low";
  80. extern string  _4           = "Median";
  81. extern string  _5           = "Typical";
  82. extern string  _6           = "Weighted Close";
  83. extern string  _7           = "Heiken Ashi Close";
  84. extern string  _8           = "Heiken Ashi Open";
  85. extern string  _9           = "Heiken Ashi High";
  86. extern string  _10          = "Heiken Ashi Low";
  87. extern string  MAMode       = "";
  88. extern string  __0          = "SMA";
  89. extern string  __1          = "EMA";
  90. extern string  __2          = "Wilder";
  91. extern string  __3          = "LWMA";
  92. extern string  __4          = "SineWMA";
  93. extern string  __5          = "TriMA";
  94. extern string  __6          = "LSMA";
  95. extern string  __7          = "SMMA";
  96. extern string  __8          = "HMA";
  97. extern string  __9          = "ZeroLagEMA";
  98. extern string  __10         = "DEMA";
  99. extern string  __11         = "T3";
  100. extern string  __12         = "ITrend";
  101. extern string  __13         = "Median";
  102. extern string  __14         = "GeoMean";
  103. extern string  __15         = "REMA";
  104. extern string  __16         = "ILRS";
  105. extern string  __17         = "IE/2";
  106. extern string  __18         = "TriMAgen";
  107. extern string  __19         = "VWMA";
  108. extern string  __20         = "JSmooth";

  109. double MA[];
  110. double Up[];
  111. double Dn[];
  112. double levUp[];
  113. double levDn[];
  114. double levUp2[];
  115. double levDn2[];

  116. //----
  117. double tmp[][6];
  118. double haClose[], haOpen[], haHigh[], haLow[];
  119. int    draw_begin, mBars, pBars, mcnt_bars;
  120. string short_name;
  121. int    sUp = 0, sDn =0;   
  122. //+------------------------------------------------------------------+
  123. //| Custom indicator initialization function                         |
  124. //+------------------------------------------------------------------+
  125. int init()
  126. {
  127. //----
  128.    IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
  129.    SetIndexStyle(0,DRAW_LINE);
  130.    if(TimeFrame == 0 || TimeFrame < Period()) TimeFrame = Period();
  131.    SetIndexShift(0,MA_Shift*TimeFrame/Period());
  132.    
  133.    draw_begin=MA_Period*TimeFrame/Period();
  134. //----
  135.    switch(MA_Method)
  136.    {
  137.    case 1 : short_name="EMA(";  break;
  138.    case 2 : short_name="Wilder("; break;
  139.    case 3 : short_name="LWMA("; break;
  140.    case 4 : short_name="SineWMA("; break;
  141.    case 5 : short_name="TriMA("; break;
  142.    case 6 : short_name="LSMA("; break;
  143.    case 7 : short_name="SMMA("; break;
  144.    case 8 : short_name="HMA("; break;
  145.    case 9 : short_name="ZeroLagEMA("; break;
  146.    case 10: short_name="DEMA(";  break;
  147.    case 11: short_name="T3(";  break;
  148.    case 12: short_name="InstTrend(";  break;
  149.    case 13: short_name="Median(";  break;
  150.    case 14: short_name="GeometricMean("; break;
  151.    case 15: short_name="REMA(";  break;
  152.    case 16: short_name="ILRS(";  break;
  153.    case 17: short_name="IE/2(";  break;
  154.    case 18: short_name="TriMA_gen("; break;
  155.    case 19: short_name="VWMA("; break;
  156.    case 20: short_name="JSmooth("; break;
  157.    default: MA_Method=0; short_name="SMA(";
  158.    }
  159.    
  160.    switch(TimeFrame)
  161.    {
  162.    case 1     : string TF = "M1"; break;
  163.    case 5     : TF = "M5"; break;
  164.    case 15    : TF = "M15"; break;
  165.    case 30    : TF = "M30"; break;
  166.    case 60    : TF = "H1"; break;
  167.    case 240   : TF = "H4"; break;
  168.    case 1440  : TF = "D1"; break;
  169.    case 10080 : TF = "W1"; break;
  170.    case 43200 : TF = "MN1"; break;
  171.    default    : TF = "Current";
  172.    }
  173.    
  174.    IndicatorShortName(short_name+MA_Period+")"+" "+TF);
  175.    SetIndexDrawBegin(0,draw_begin);
  176.    SetIndexLabel(0,short_name+MA_Period+")"+" "+TF);
  177. //----
  178.    SetIndexBuffer(0,MA);
  179. //----
  180.    if(Color_Mode == 1)
  181.    {
  182.    SetIndexStyle(1,DRAW_LINE);
  183.    SetIndexStyle(2,DRAW_LINE);
  184.    SetIndexShift(1,MA_Shift*TimeFrame/Period());
  185.    SetIndexShift(2,MA_Shift*TimeFrame/Period());
  186.    SetIndexDrawBegin(1,draw_begin);
  187.    SetIndexDrawBegin(2,draw_begin);
  188.    SetIndexLabel(1,short_name+MA_Period+")"+" "+TF+" UpTrend");
  189.    SetIndexLabel(2,short_name+MA_Period+")"+" "+TF+" DnTrend");
  190.    SetIndexBuffer(1,Up);
  191.    SetIndexBuffer(2,Dn);
  192.    SetIndexBuffer(3,levUp);
  193.    SetIndexBuffer(4,levDn);
  194.    SetIndexBuffer(5,levUp2);
  195.    SetIndexBuffer(6,levDn2);
  196.    }
  197. //----   
  198.    return(0);
  199. }
  200. //+------------------------------------------------------------------+
  201. //| AllAverages_v2.5                                                 |
  202. //+------------------------------------------------------------------+
  203. int start()
  204. {
  205.    int limit, y, i, shift, cnt_bars=IndicatorCounted();
  206.    double aPrice[], mMA[], mUp[], mDn[];
  207.   
  208.    if(TimeFrame!=Period()) mBars = iBars(NULL,TimeFrame); else mBars = Bars;   
  209.    
  210.    if(mBars != pBars)
  211.    {
  212.    ArrayResize(aPrice,mBars);
  213.    ArrayResize(aPrice,mBars);   
  214.    
  215.    ArrayResize(mMA,mBars);
  216.    if(MA_Method==10 || MA_Method==11 || MA_Method==20) ArrayResize(tmp,mBars);
  217.       if(Color_Mode ==1)
  218.       {
  219.       ArrayResize(mUp,mBars);
  220.       ArrayResize(mDn,mBars);
  221.       }
  222.       if(Price > 6 && Price <= 10)
  223.       {
  224.       ArrayResize(haClose,mBars);
  225.       ArrayResize(haOpen,mBars);
  226.       ArrayResize(haHigh,mBars);
  227.       ArrayResize(haLow,mBars);
  228.       }
  229.    pBars = mBars;
  230.    }  
  231.    
  232.    if(cnt_bars<1)
  233.    {
  234.       for(i=1;i<=draw_begin;i++)
  235.       {
  236.       MA[Bars-i]=iMA(NULL,TimeFrame,1,0,0,Price,Bars-i);
  237.       Up[Bars-i]=EMPTY_VALUE;
  238.       Dn[Bars-i]=EMPTY_VALUE;
  239.       }
  240.    mcnt_bars = 0;
  241.    
  242.    }
  243. //----
  244.    if(mcnt_bars > 0) mcnt_bars--;
  245.    
  246.    for(y=mcnt_bars;y<mBars;y++)
  247.    {
  248.       if(Price <= 6) aPrice[y] = iMA(NULL,TimeFrame,1,0,0,Price,mBars-y-1);   
  249.       else
  250.       if(Price > 6 && Price <= 10) aPrice[y] = HeikenAshi(TimeFrame,Price-7,mBars-y-1);
  251.       
  252.       switch(MA_Method)
  253.       {
  254.       case 1 : mMA[y] = EMA(aPrice[y],mMA,MA_Period,y); break;
  255.       case 2 : mMA[y] = Wilder(aPrice,mMA,MA_Period,y); break;  
  256.       case 3 : mMA[y] = LWMA(aPrice,MA_Period,y); break;
  257.       case 4 : mMA[y] = SineWMA(aPrice,MA_Period,y); break;
  258.       case 5 : mMA[y] = TriMA(aPrice,MA_Period,y); break;
  259.       case 6 : mMA[y] = LSMA(aPrice,MA_Period,y); break;
  260.       case 7 : mMA[y] = SMMA(aPrice,mMA,MA_Period,y); break;
  261.       case 8 : mMA[y] = HMA(aPrice,MA_Period,y); break;
  262.       case 9 : mMA[y] = ZeroLagEMA(aPrice,mMA,MA_Period,y); break;
  263.       case 10: mMA[y] = DEMA(0,aPrice[y],MA_Period,1,y); break;
  264.       case 11: mMA[y] = T3(aPrice[y],MA_Period,0.7,y); break;
  265.       case 12: mMA[y] = ITrend(aPrice,mMA,MA_Period,y); break;
  266.       case 13: mMA[y] = Median(aPrice,MA_Period,y); break;
  267.       case 14: mMA[y] = GeoMean(aPrice,MA_Period,y); break;
  268.       case 15: mMA[y] = REMA(aPrice[y],mMA,MA_Period,0.5,y); break;
  269.       case 16: mMA[y] = ILRS(aPrice,MA_Period,y); break;
  270.       case 17: mMA[y] = IE2(aPrice,MA_Period,y); break;
  271.       case 18: mMA[y] = TriMA_gen(aPrice,MA_Period,y); break;
  272.       case 19: mMA[y] = VWMA(aPrice,MA_Period,y); break;
  273.       case 20: mMA[y] = JSmooth(aPrice[y],MA_Period,1,y); break;
  274.       default: mMA[y] = SMA(aPrice,MA_Period,y); break;
  275.       }
  276.    
  277.       if(Color_Mode == 1)
  278.       {
  279.          if(mMA[y] > mMA[y-1]) {mUp[y] = mMA[y]; mDn[y] = EMPTY_VALUE;}
  280.          else
  281.          if(mMA[y] < mMA[y-1]) {mUp[y] = EMPTY_VALUE; mDn[y] = mMA[y];}
  282.          else
  283.          {mUp[y] = EMPTY_VALUE; mDn[y] = EMPTY_VALUE;}
  284.       
  285.          if(Sound_Mode == 1 && y == mBars-1)
  286.          {
  287.             if(((Sound_Shift > 0 && sUp == 0) || Sound_Shift == 0) && mMA[y-Sound_Shift] > mMA[y-1-Sound_Shift] && mMA[y-1-Sound_Shift] <= mMA[y-2-Sound_Shift])
  288.             {
  289.             if(Sound_Shift > 0) {sUp = 1; sDn = 0;}
  290.             PlaySound(Buy_Sound);
  291.             }
  292.             else
  293.             if(((Sound_Shift > 0 && sDn == 0) || Sound_Shift == 0) && mMA[y-Sound_Shift] < mMA[y-1-Sound_Shift] && mMA[y-1-Sound_Shift] >= mMA[y-2-Sound_Shift])
  294.             {
  295.             if(Sound_Shift > 0) {sUp = 0; sDn = 1;}
  296.             PlaySound(Sell_Sound);
  297.             }
  298.          }
  299.       }
  300.    
  301.       if(TimeFrame == Period())
  302.       {
  303.       MA[mBars-y-1] = mMA[y];
  304.          if(Color_Mode == 1)
  305.          {  
  306.          Up[mBars-y-1] = mUp[y];
  307.          Dn[mBars-y-1] = mDn[y];
  308.          }
  309.          
  310.          double useValue = Point;
  311.             if (BandType == 1) useValue = iStdDev(NULL,0,MA_Period,0,MODE_SMA,Price,mBars-y-1);
  312.             if (BandType == 2) useValue = iATR(NULL,0,MA_Period,mBars-y-1);
  313.             if (LevelUp    >0) levUp[mBars-y-1] =MA[mBars-y-1]+useValue*LevelUp;
  314.             if (LevelDown  >0) levDn[mBars-y-1] =MA[mBars-y-1]-useValue*LevelDown;
  315.             if (Level2Up   >0) levUp2[mBars-y-1]=MA[mBars-y-1]+useValue*Level2Up;
  316.             if (Level2Down >0) levDn2[mBars-y-1]=MA[mBars-y-1]-useValue*Level2Down;
  317.       }
  318.       
  319.    }
  320.    mcnt_bars = mBars-1;
  321.    
  322.    if(TimeFrame > Period())
  323.    {
  324.       if(cnt_bars>0) cnt_bars--;
  325.       limit = Bars-cnt_bars+TimeFrame/Period()-1;
  326.       
  327.       for(shift=0,y=0;shift<limit;shift++)
  328.       {
  329.       if (Time[shift] < iTime(NULL,TimeFrame,y)) y++;
  330.       MA[shift] = mMA[mBars-y-1];
  331.          if(Color_Mode == 1)
  332.          {
  333.          Up[shift] = mUp[mBars-y-1];
  334.          Dn[shift] = mDn[mBars-y-1];
  335.          }
  336.          useValue = Point;
  337.             int tfShift = iBarShift(NULL,TimeFrame,Time[shift]);
  338.             if (BandType == 1) useValue = iStdDev(NULL,TimeFrame,MA_Period,0,MODE_SMA,Price,tfShift);
  339.             if (BandType == 2) useValue = iATR(NULL,TimeFrame,MA_Period,tfShift);
  340.             if (LevelUp    >0) levUp[shift] =MA[shift]+useValue*LevelUp;
  341.             if (LevelDown  >0) levDn[shift] =MA[shift]-useValue*LevelDown;
  342.             if (Level2Up   >0) levUp2[shift]=MA[shift]+useValue*Level2Up;
  343.             if (Level2Down >0) levDn2[shift]=MA[shift]-useValue*Level2Down;
  344.       }
  345.    }
  346.    
  347. //----
  348.    return(0);
  349. }

  350. // MA_Method=0: SMA - Simple Moving Average
  351. double SMA(double& array[],int per,int bar)
  352. {
  353.    double Sum = 0;
  354.    for(int i = 0;i < per;i++) Sum += array[bar-i];
  355.    
  356.    return(Sum/per);
  357. }               
  358. // MA_Method=1: EMA - Exponential Moving Average
  359. double EMA(double price,double& array[],int per,int bar)
  360. {
  361.    if(bar == 2) double ema = price;
  362.    else
  363.    if(bar > 2) ema = array[bar-1] + 2.0/(1+per)*(price - array[bar-1]);
  364.    
  365.    return(ema);
  366. }
  367. // MA_Method=2: Wilder - Wilder Exponential Moving Average
  368. double Wilder(double& array1[],double& array2[],int per,int bar)
  369. {
  370.    if(bar == per) double wilder = SMA(array1,per,bar);
  371.    else
  372.    if(bar > per) wilder = array2[bar-1] + (array1[bar] - array2[bar-1])/per;
  373.    
  374.    return(wilder);
  375. }
  376. // MA_Method=3: LWMA - Linear Weighted Moving Average
  377. double LWMA(double& array[],int per,int bar)
  378. {
  379.    double Sum = 0;
  380.    double Weight = 0;
  381.    
  382.       for(int i = 0;i < per;i++)
  383.       {
  384.       Weight+= (per - i);
  385.       Sum += array[bar-i]*(per - i);
  386.       }
  387.    if(Weight>0) double lwma = Sum/Weight;
  388.    else lwma = 0;
  389.    return(lwma);
  390. }
  391. // MA_Method=4: SineWMA - Sine Weighted Moving Average
  392. double SineWMA(double& array[],int per,int bar)
  393. {
  394.    double pi = 3.1415926535;
  395.    double Sum = 0;
  396.    double Weight = 0;
  397.   
  398.       for(int i = 0;i < per-1;i++)
  399.       {
  400.       Weight+= MathSin(pi*(i+1)/(per+1));
  401.       Sum += array[bar-i]*MathSin(pi*(i+1)/(per+1));
  402.       }
  403.    if(Weight>0) double swma = Sum/Weight;
  404.    else swma = 0;
  405.    return(swma);
  406. }
  407. // MA_Method=5: TriMA - Triangular Moving Average
  408. double TriMA(double& array[],int per,int bar)
  409. {
  410.    double sma;
  411.    int len = MathCeil((per+1)*0.5);
  412.    
  413.    double sum=0;
  414.    for(int i = 0;i < len;i++)
  415.    {
  416.    sma = SMA(array,len,bar-i);
  417.    sum += sma;
  418.    }
  419.    double trima = sum/len;
  420.    
  421.    return(trima);
  422. }
  423. // MA_Method=6: LSMA - Least Square Moving Average (or EPMA, Linear Regression Line)
  424. double LSMA(double& array[],int per,int bar)
  425. {   
  426.    double Sum=0;
  427.    for(int i=per; i>=1; i--) Sum += (i-(per+1)/3.0)*array[bar-per+i];
  428.    double lsma = Sum*6/(per*(per+1));
  429.    return(lsma);
  430. }
  431. // MA_Method=7: SMMA - Smoothed Moving Average
  432. double SMMA(double& array1[],double& array2[],int per,int bar)
  433. {
  434.    if(bar == per) double smma = SMA(array1,per,bar);
  435.    else
  436.    if(bar > per)
  437.    {
  438.    double Sum = 0;
  439.    for(int i = 0;i < per;i++) Sum += array1[bar-i-1];
  440.    smma = (Sum - array2[bar-1] + array1[bar])/per;
  441.    }
  442.    return(smma);
  443. }               
  444. // MA_Method=8: HMA - Hull Moving Average by Alan Hull
  445. double HMA(double& array[],int per,int bar)
  446. {
  447.    double ttmp[];
  448.    int len =  MathSqrt(per);
  449.    ArrayResize(ttmp,len);
  450.    
  451.    if(bar == per) double hma = array[bar];
  452.    else
  453.    if(bar > per)
  454.    {
  455.    for(int i = 0; i < len;i++) ttmp[len-i-1] = 2*LWMA(array,per/2,bar-i) - LWMA(array,per,bar-i);  
  456.    hma = LWMA(ttmp,len,len-1);
  457.    }  

  458.    return(hma);
  459. }
  460. // MA_Method=9: ZeroLagEMA - Zero-Lag Exponential Moving Average
  461. double ZeroLagEMA(double& array1[],double& array2[],int per,int bar)
  462. {
  463.    double alfa = 2.0/(1+per);
  464.    int lag = 0.5*(per - 1);
  465.    
  466.    if(bar == lag) double zema = array1[bar];
  467.    else
  468.    if(bar > lag) zema = alfa*(2*array1[bar] - array1[bar-lag]) + (1-alfa)*array2[bar-1];
  469.    
  470.    return(zema);
  471. }
  472. // MA_Method=10: DEMA - Double Exponential Moving Average by Patrick Mulloy
  473. double DEMA(int num,double price,int per,double v,int bar)
  474. {
  475.    if(bar == 2) {double dema = price; tmp[bar][num] = dema; tmp[bar][num+1] = dema;}
  476.    else
  477.    if(bar > 2)
  478.    {
  479.    tmp[bar][num] = tmp[bar-1][num] + 2.0/(1+per)*(price - tmp[bar-1][num]);
  480.    tmp[bar][num+1] = tmp[bar-1][num+1] + 2.0/(1+per)*(tmp[bar][num] - tmp[bar-1][num+1]);
  481.    dema = (1+v)*tmp[bar][num] - v*tmp[bar][num+1];
  482.    }
  483.    return(dema);
  484. }
  485. // MA_Method=11: T3 by T.Tillson
  486. double T3(double price,int per,double v,int bar)
  487. {
  488.    if(bar == 2)
  489.    {
  490.    double T3 = price;
  491.    for(int k=0;k<=5;k++) tmp[bar][k] = T3;
  492.    }
  493.    else
  494.    if(bar > 2)
  495.    {
  496.    double dema1 = DEMA(0,price,per,v,bar);
  497.    double dema2 = DEMA(2,dema1,per,v,bar);
  498.    T3 = DEMA(4,dema2,per,v,bar);
  499.    }
  500.    return(T3);
  501. }
  502. // MA_Method=12: ITrend - Instantaneous Trendline by J.Ehlers
  503. double ITrend(double& price[],double& array[],int per,int bar)
  504. {
  505.    double alfa = 2.0/(per+1);
  506.    if(bar > 7)
  507.    double it = (alfa - 0.25*alfa*alfa)*price[bar]+ 0.5*alfa*alfa*price[bar-1]-(alfa - 0.75*alfa*alfa)*price[bar-2]+
  508.    2*(1-alfa)*array[bar-1] - (1-alfa)*(1-alfa)*array[bar-2];
  509.    else
  510.    it = (price[bar] + 2*price[bar-1]+ price[bar-2])/4;
  511.    
  512.    return(it);
  513. }
  514. // MA_Method=13: Median - Moving Median
  515. double Median(double& price[],int per,int bar)
  516. {
  517.    double array[];
  518.    ArrayResize(array,per);
  519.    
  520.    for(int i = 0; i < per;i++) array[i] = price[bar-i];
  521.    ArraySort(array);
  522.    
  523.    int num = MathRound((per-1)/2);
  524.    if(MathMod(per,2)>0) double median = array[num]; else median = 0.5*(array[num]+array[num+1]);
  525.    
  526.    return(median);
  527. }
  528. // MA_Method=14: GeoMean - Geometric Mean
  529. double GeoMean(double& price[],int per,int bar)
  530. {
  531.    double gmean = MathPow(price[bar],1.0/per);
  532.    for(int i = 1; i < per;i++) gmean *= MathPow(price[bar-i],1.0/per);
  533.    
  534.    return(gmean);
  535. }
  536. // MA_Method=15: REMA - Regularized EMA by Chris Satchwell
  537. double REMA(double price,double& array[],int per,double lambda,int bar)
  538. {
  539.    double alpha =  2.0/(per + 1);
  540.    if(bar <= 3) double rema = price;
  541.    else
  542.    if(bar > 3)
  543.    rema = (array[bar-1]*(1+2*lambda) + alpha*(price - array[bar-1]) - lambda*array[bar-2])/(1+lambda);
  544.    
  545.    return(rema);
  546. }
  547. // MA_Method=16: ILRS - Integral of Linear Regression Slope
  548. double ILRS(double& price[],int per,int bar)
  549. {
  550.    double sum = per*(per-1)*0.5;
  551.    double sum2 = (per-1)*per*(2*per-1)/6.0;
  552.      
  553.    double sum1 = 0;
  554.    double sumy = 0;
  555.       for(int i=0;i<per;i++)
  556.       {
  557.       sum1 += i*price[bar-i];
  558.       sumy += price[bar-i];
  559.       }
  560.    double num1 = per*sum1 - sum*sumy;
  561.    double num2 = sum*sum - per*sum2;
  562.    
  563.    if(num2 != 0) double slope = num1/num2; else slope = 0;
  564.    double ilrs = slope + SMA(price,per,bar);
  565.    
  566.    return(ilrs);
  567. }
  568. // MA_Method=17: IE/2 - Combination of LSMA and ILRS
  569. double IE2(double& price[],int per,int bar)
  570. {
  571.    double ie = 0.5*(ILRS(price,per,bar) + LSMA(price,per,bar));
  572.       
  573.    return(ie);
  574. }

  575. // MA_Method=18: TriMAgen - Triangular Moving Average Generalized by J.Ehlers
  576. double TriMA_gen(double& array[],int per,int bar)
  577. {
  578.    int len1 = MathFloor((per+1)*0.5);
  579.    int len2 = MathCeil((per+1)*0.5);
  580.    double sum=0;
  581.    for(int i = 0;i < len2;i++) sum += SMA(array,len1,bar-i);
  582.    double trimagen = sum/len2;
  583.    
  584.    return(trimagen);
  585. }

  586. // MA_Method=19: VWMA - Volume Weighted Moving Average
  587. double VWMA(double& array[],int per,int bar)
  588. {
  589.    double Sum = 0;
  590.    double Weight = 0;
  591.    
  592.       for(int i = 0;i < per;i++)
  593.       {
  594.       Weight+= Volume[mBars-bar-1+i];
  595.       Sum += array[bar-i]*Volume[mBars-bar-1+i];
  596.       }
  597.    if(Weight>0) double vwma = Sum/Weight;
  598.    else vwma = 0;
  599.    return(vwma);
  600. }

  601. // MA_Method=20: JSmooth - Smoothing by Mark Jurik
  602. double JSmooth(double price,int per,double pow,int bar)
  603. {
  604.    double beta = 0.45*(per-1)/(0.45*(per-1)+2);
  605.         double alpha = MathPow(beta,pow);
  606.         if(bar == 2) {tmp[bar][4] = price; tmp[bar][0] = price; tmp[bar][2] = price;}
  607.         else
  608.    if(bar > 2)
  609.    {
  610.         tmp[bar][0] = (1-alpha)*price + alpha*tmp[bar-1][0];
  611.         tmp[bar][1] = (price - tmp[bar][0])*(1-beta) + beta*tmp[bar-1][1];
  612.         tmp[bar][2] = tmp[bar][0] + tmp[bar][1];
  613.         tmp[bar][3] = (tmp[bar][2] - tmp[bar-1][4])*MathPow((1-alpha),2) + MathPow(alpha,2)*tmp[bar-1][3];
  614.         tmp[bar][4] = tmp[bar-1][4] + tmp[bar][3];
  615.    }
  616.    return(tmp[bar][4]);
  617. }

  618. // HeikenAshi Price:  7 - Close,8 - Open,9 - High,10 - Low
  619. double HeikenAshi(int tf,int price,int bar)
  620. {
  621.    if(bar == iBars(NULL,TimeFrame)- 1)
  622.    {
  623.    haClose[bar] = iClose(NULL,tf,bar);
  624.    haOpen[bar]  = iOpen(NULL,tf,bar);
  625.    haHigh[bar]  = iHigh(NULL,tf,bar);
  626.    haLow[bar]   = iLow(NULL,tf,bar);
  627.    }
  628.    else
  629.    {
  630.    haClose[bar] = (iOpen(NULL,tf,bar)+iHigh(NULL,tf,bar)+iLow(NULL,tf,bar)+iClose(NULL,tf,bar))/4;
  631.    haOpen[bar]  = (haOpen[bar+1]+haClose[bar+1])/2;
  632.    haHigh[bar]  = MathMax(iHigh(NULL,tf,bar),MathMax(haOpen[bar], haClose[bar]));
  633.    haLow[bar]   = MathMin(iLow(NULL,tf,bar),MathMin(haOpen[bar], haClose[bar]));
  634.    }
  635.    
  636.    switch(price)
  637.    {
  638.    case 0: return(haClose[bar]);break;
  639.    case 1: return(haOpen[bar]);break;
  640.    case 2: return(haHigh[bar]);break;
  641.    case 3: return(haLow[bar]);break;
  642.    }
  643.    return(iClose(NULL,tf,bar));
  644. }   
复制代码

回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-4-28 15:56:38 | 显示全部楼层
求老师,帮忙给改改
回复 支持 反对

使用道具 举报

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

本版积分规则

小黑屋|手机版|sitemap|智能交易网,程序化交易,自动交易,量化交易 ( 苏ICP备08108698号,苏州智德金网络科技股份有限公司版权所有 )

GMT+8, 2019-10-23 14:49 , Processed in 0.112477 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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