交易危机

 找回密码
 快捷注册(禁q号)

QQ登录

只需一步,快速开始

搜索
广告位
查看: 2291|回复: 5

[均线] 求助 改指标均线显示问题

[复制链接]

6

主题

2064

积分

0

精华

中级操盘手

金钱
2064 美元
权重
4
发表于 2015-4-27 09:57 | 显示全部楼层 |阅读模式
本帖最后由 wccmcd 于 2015-12-4 12:05 编辑

请老师们帮忙
改指标均线显示问题,没有行情的时候(如周六、日停盘)均线显示正常
有行情的时候均线显示不正常,在最后1、2K线处均线向下出一个尾巴,
11.jpg
AllAverages_v2.5 & bands nmc.rar (4.97 KB, 下载次数: 0)

6

主题

2064

积分

0

精华

中级操盘手

金钱
2064 美元
权重
4
 楼主| 发表于 2015-4-27 09:58 | 显示全部楼层
本帖最后由 wccmcd 于 2015-12-4 12:05 编辑

指标源代码:

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

  39. #property copyright "Copyright ?2007-09, TrendLaboratory"
  40. #property indicator_chart_window
  41. #property indicator_buffers 7
  42. #property indicator_color1  Yellow
  43. #property indicator_width1  2  
  44. #property indicator_color2  DeepSkyBlue
  45. #property indicator_width2  2  
  46. #property indicator_color3  Tomato
  47. #property indicator_width3  2  
  48. #property indicator_color4  Gray
  49. #property indicator_color5  Gray
  50. #property indicator_color6  Gray
  51. #property indicator_color7  Gray
  52. #property indicator_style4  STYLE_DOT
  53. #property indicator_style5  STYLE_DOT
  54. #property indicator_style6  STYLE_DOT
  55. #property indicator_style7  STYLE_DOT
  56. //----
  57. extern int     TimeFrame    =  0;
  58. extern int     Price        =  0;
  59. extern int     MA_Period    = 14;
  60. extern int     MA_Shift     =  0;
  61. extern int     MA_Method    =  0;
  62. extern int     Color_Mode   =  1;
  63. extern int     Sound_Mode   =  1; //0-off,1-on(works only with Color_Mode=1)
  64. extern int     Sound_Shift  =  0; //0-open bar(multiple),1-closed bar(once)
  65. extern string  Buy_Sound    =  "alert.wav";
  66. extern string  Sell_Sound   =  "alert2.wav";
  67. extern int     BandType     = 0;
  68. extern double  LevelUp      = 0;
  69. extern double  LevelDown    = 0;
  70. extern double  Level2Up     = 0;
  71. extern double  Level2Down   = 0;
  72. extern string  PriceMode    = "";
  73. extern string  _0           = "Close";
  74. extern string  _1           = "Open";
  75. extern string  _2           = "High";
  76. extern string  _3           = "Low";
  77. extern string  _4           = "Median";
  78. extern string  _5           = "Typical";
  79. extern string  _6           = "Weighted Close";
  80. extern string  _7           = "Heiken Ashi Close";
  81. extern string  _8           = "Heiken Ashi Open";
  82. extern string  _9           = "Heiken Ashi High";
  83. extern string  _10          = "Heiken Ashi Low";
  84. extern string  MAMode       = "";
  85. extern string  __0          = "SMA";
  86. extern string  __1          = "EMA";
  87. extern string  __2          = "Wilder";
  88. extern string  __3          = "LWMA";
  89. extern string  __4          = "SineWMA";
  90. extern string  __5          = "TriMA";
  91. extern string  __6          = "LSMA";
  92. extern string  __7          = "SMMA";
  93. extern string  __8          = "HMA";
  94. extern string  __9          = "ZeroLagEMA";
  95. extern string  __10         = "DEMA";
  96. extern string  __11         = "T3";
  97. extern string  __12         = "ITrend";
  98. extern string  __13         = "Median";
  99. extern string  __14         = "GeoMean";
  100. extern string  __15         = "REMA";
  101. extern string  __16         = "ILRS";
  102. extern string  __17         = "IE/2";
  103. extern string  __18         = "TriMAgen";
  104. extern string  __19         = "VWMA";
  105. extern string  __20         = "JSmooth";
  106. double MA[];
  107. double Up[];
  108. double Dn[];
  109. double levUp[];
  110. double levDn[];
  111. double levUp2[];
  112. double levDn2[];
  113. //----
  114. double tmp[][6];
  115. double haClose[], haOpen[], haHigh[], haLow[];
  116. int    draw_begin, mBars, pBars, mcnt_bars;
  117. string short_name;
  118. int    sUp = 0, sDn =0;   
  119. //+------------------------------------------------------------------+
  120. //| Custom indicator initialization function                         |
  121. //+------------------------------------------------------------------+
  122. int init()
  123. {
  124. //----
  125.    IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
  126.    SetIndexStyle(0,DRAW_LINE);
  127.    if(TimeFrame == 0 || TimeFrame < Period()) TimeFrame = Period();
  128.    SetIndexShift(0,MA_Shift*TimeFrame/Period());
  129.    
  130.    draw_begin=MA_Period*TimeFrame/Period();
  131. //----
  132.    switch(MA_Method)
  133.    {
  134.    case 1 : short_name="EMA(";  break;
  135.    case 2 : short_name="Wilder("; break;
  136.    case 3 : short_name="LWMA("; break;
  137.    case 4 : short_name="SineWMA("; break;
  138.    case 5 : short_name="TriMA("; break;
  139.    case 6 : short_name="LSMA("; break;
  140.    case 7 : short_name="SMMA("; break;
  141.    case 8 : short_name="HMA("; break;
  142.    case 9 : short_name="ZeroLagEMA("; break;
  143.    case 10: short_name="DEMA(";  break;
  144.    case 11: short_name="T3(";  break;
  145.    case 12: short_name="InstTrend(";  break;
  146.    case 13: short_name="Median(";  break;
  147.    case 14: short_name="GeometricMean("; break;
  148.    case 15: short_name="REMA(";  break;
  149.    case 16: short_name="ILRS(";  break;
  150.    case 17: short_name="IE/2(";  break;
  151.    case 18: short_name="TriMA_gen("; break;
  152.    case 19: short_name="VWMA("; break;
  153.    case 20: short_name="JSmooth("; break;
  154.    default: MA_Method=0; short_name="SMA(";
  155.    }
  156.    
  157.    switch(TimeFrame)
  158.    {
  159.    case 1     : string TF = "M1"; break;
  160.    case 5     : TF = "M5"; break;
  161.    case 15    : TF = "M15"; break;
  162.    case 30    : TF = "M30"; break;
  163.    case 60    : TF = "H1"; break;
  164.    case 240   : TF = "H4"; break;
  165.    case 1440  : TF = "D1"; break;
  166.    case 10080 : TF = "W1"; break;
  167.    case 43200 : TF = "MN1"; break;
  168.    default    : TF = "Current";
  169.    }
  170.    
  171.    IndicatorShortName(short_name+MA_Period+")"+" "+TF);
  172.    SetIndexDrawBegin(0,draw_begin);
  173.    SetIndexLabel(0,short_name+MA_Period+")"+" "+TF);
  174. //----
  175.    SetIndexBuffer(0,MA);
  176. //----
  177.    if(Color_Mode == 1)
  178.    {
  179.    SetIndexStyle(1,DRAW_LINE);
  180.    SetIndexStyle(2,DRAW_LINE);
  181.    SetIndexShift(1,MA_Shift*TimeFrame/Period());
  182.    SetIndexShift(2,MA_Shift*TimeFrame/Period());
  183.    SetIndexDrawBegin(1,draw_begin);
  184.    SetIndexDrawBegin(2,draw_begin);
  185.    SetIndexLabel(1,short_name+MA_Period+")"+" "+TF+" UpTrend");
  186.    SetIndexLabel(2,short_name+MA_Period+")"+" "+TF+" DnTrend");
  187.    SetIndexBuffer(1,Up);
  188.    SetIndexBuffer(2,Dn);
  189.    SetIndexBuffer(3,levUp);
  190.    SetIndexBuffer(4,levDn);
  191.    SetIndexBuffer(5,levUp2);
  192.    SetIndexBuffer(6,levDn2);
  193.    }
  194. //----   
  195.    return(0);
  196. }
  197. //+------------------------------------------------------------------+
  198. //| AllAverages_v2.5                                                 |
  199. //+------------------------------------------------------------------+
  200. int start()
  201. {
  202.    int limit, y, i, shift, cnt_bars=IndicatorCounted();
  203.    double aPrice[], mMA[], mUp[], mDn[];
  204.   
  205.    if(TimeFrame!=Period()) mBars = iBars(NULL,TimeFrame); else mBars = Bars;   
  206.    
  207.    if(mBars != pBars)
  208.    {
  209.    ArrayResize(aPrice,mBars);
  210.    ArrayResize(aPrice,mBars);   
  211.    
  212.    ArrayResize(mMA,mBars);
  213.    if(MA_Method==10 || MA_Method==11 || MA_Method==20) ArrayResize(tmp,mBars);
  214.       if(Color_Mode ==1)
  215.       {
  216.       ArrayResize(mUp,mBars);
  217.       ArrayResize(mDn,mBars);
  218.       }
  219.       if(Price > 6 && Price <= 10)
  220.       {
  221.       ArrayResize(haClose,mBars);
  222.       ArrayResize(haOpen,mBars);
  223.       ArrayResize(haHigh,mBars);
  224.       ArrayResize(haLow,mBars);
  225.       }
  226.    pBars = mBars;
  227.    }  
  228.    
  229.    if(cnt_bars<1)
  230.    {
  231.       for(i=1;i<=draw_begin;i++)
  232.       {
  233.       MA[Bars-i]=iMA(NULL,TimeFrame,1,0,0,Price,Bars-i);
  234.       Up[Bars-i]=EMPTY_VALUE;
  235.       Dn[Bars-i]=EMPTY_VALUE;
  236.       }
  237.    mcnt_bars = 0;
  238.    
  239.    }
  240. //----
  241.    if(mcnt_bars > 0) mcnt_bars--;
  242.    
  243.    for(y=mcnt_bars;y<mBars;y++)
  244.    {
  245.       if(Price <= 6) aPrice[y] = iMA(NULL,TimeFrame,1,0,0,Price,mBars-y-1);   
  246.       else
  247.       if(Price > 6 && Price <= 10) aPrice[y] = HeikenAshi(TimeFrame,Price-7,mBars-y-1);
  248.       
  249.       switch(MA_Method)
  250.       {
  251.       case 1 : mMA[y] = EMA(aPrice[y],mMA,MA_Period,y); break;
  252.       case 2 : mMA[y] = Wilder(aPrice,mMA,MA_Period,y); break;  
  253.       case 3 : mMA[y] = LWMA(aPrice,MA_Period,y); break;
  254.       case 4 : mMA[y] = SineWMA(aPrice,MA_Period,y); break;
  255.       case 5 : mMA[y] = TriMA(aPrice,MA_Period,y); break;
  256.       case 6 : mMA[y] = LSMA(aPrice,MA_Period,y); break;
  257.       case 7 : mMA[y] = SMMA(aPrice,mMA,MA_Period,y); break;
  258.       case 8 : mMA[y] = HMA(aPrice,MA_Period,y); break;
  259.       case 9 : mMA[y] = ZeroLagEMA(aPrice,mMA,MA_Period,y); break;
  260.       case 10: mMA[y] = DEMA(0,aPrice[y],MA_Period,1,y); break;
  261.       case 11: mMA[y] = T3(aPrice[y],MA_Period,0.7,y); break;
  262.       case 12: mMA[y] = ITrend(aPrice,mMA,MA_Period,y); break;
  263.       case 13: mMA[y] = Median(aPrice,MA_Period,y); break;
  264.       case 14: mMA[y] = GeoMean(aPrice,MA_Period,y); break;
  265.       case 15: mMA[y] = REMA(aPrice[y],mMA,MA_Period,0.5,y); break;
  266.       case 16: mMA[y] = ILRS(aPrice,MA_Period,y); break;
  267.       case 17: mMA[y] = IE2(aPrice,MA_Period,y); break;
  268.       case 18: mMA[y] = TriMA_gen(aPrice,MA_Period,y); break;
  269.       case 19: mMA[y] = VWMA(aPrice,MA_Period,y); break;
  270.       case 20: mMA[y] = JSmooth(aPrice[y],MA_Period,1,y); break;
  271.       default: mMA[y] = SMA(aPrice,MA_Period,y); break;
  272.       }
  273.    
  274.       if(Color_Mode == 1)
  275.       {
  276.          if(mMA[y] > mMA[y-1]) {mUp[y] = mMA[y]; mDn[y] = EMPTY_VALUE;}
  277.          else
  278.          if(mMA[y] < mMA[y-1]) {mUp[y] = EMPTY_VALUE; mDn[y] = mMA[y];}
  279.          else
  280.          {mUp[y] = EMPTY_VALUE; mDn[y] = EMPTY_VALUE;}
  281.       
  282.          if(Sound_Mode == 1 && y == mBars-1)
  283.          {
  284.             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])
  285.             {
  286.             if(Sound_Shift > 0) {sUp = 1; sDn = 0;}
  287.             PlaySound(Buy_Sound);
  288.             }
  289.             else
  290.             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])
  291.             {
  292.             if(Sound_Shift > 0) {sUp = 0; sDn = 1;}
  293.             PlaySound(Sell_Sound);
  294.             }
  295.          }
  296.       }
  297.    
  298.       if(TimeFrame == Period())
  299.       {
  300.       MA[mBars-y-1] = mMA[y];
  301.          if(Color_Mode == 1)
  302.          {  
  303.          Up[mBars-y-1] = mUp[y];
  304.          Dn[mBars-y-1] = mDn[y];
  305.          }
  306.          
  307.          double useValue = Point;
  308.             if (BandType == 1) useValue = iStdDev(NULL,0,MA_Period,0,MODE_SMA,Price,mBars-y-1);
  309.             if (BandType == 2) useValue = iATR(NULL,0,MA_Period,mBars-y-1);
  310.             if (LevelUp    >0) levUp[mBars-y-1] =MA[mBars-y-1]+useValue*LevelUp;
  311.             if (LevelDown  >0) levDn[mBars-y-1] =MA[mBars-y-1]-useValue*LevelDown;
  312.             if (Level2Up   >0) levUp2[mBars-y-1]=MA[mBars-y-1]+useValue*Level2Up;
  313.             if (Level2Down >0) levDn2[mBars-y-1]=MA[mBars-y-1]-useValue*Level2Down;
  314.       }
  315.       
  316.    }
  317.    mcnt_bars = mBars-1;
  318.    
  319.    if(TimeFrame > Period())
  320.    {
  321.       if(cnt_bars>0) cnt_bars--;
  322.       limit = Bars-cnt_bars+TimeFrame/Period()-1;
  323.       
  324.       for(shift=0,y=0;shift<limit;shift++)
  325.       {
  326.       if (Time[shift] < iTime(NULL,TimeFrame,y)) y++;
  327.       MA[shift] = mMA[mBars-y-1];
  328.          if(Color_Mode == 1)
  329.          {
  330.          Up[shift] = mUp[mBars-y-1];
  331.          Dn[shift] = mDn[mBars-y-1];
  332.          }
  333.          useValue = Point;
  334.             int tfShift = iBarShift(NULL,TimeFrame,Time[shift]);
  335.             if (BandType == 1) useValue = iStdDev(NULL,TimeFrame,MA_Period,0,MODE_SMA,Price,tfShift);
  336.             if (BandType == 2) useValue = iATR(NULL,TimeFrame,MA_Period,tfShift);
  337.             if (LevelUp    >0) levUp[shift] =MA[shift]+useValue*LevelUp;
  338.             if (LevelDown  >0) levDn[shift] =MA[shift]-useValue*LevelDown;
  339.             if (Level2Up   >0) levUp2[shift]=MA[shift]+useValue*Level2Up;
  340.             if (Level2Down >0) levDn2[shift]=MA[shift]-useValue*Level2Down;
  341.       }
  342.    }
  343.    
  344. //----
  345.    return(0);
  346. }
  347. // MA_Method=0: SMA - Simple Moving Average
  348. double SMA(double& array[],int per,int bar)
  349. {
  350.    double Sum = 0;
  351.    for(int i = 0;i < per;i++) Sum += array[bar-i];
  352.    
  353.    return(Sum/per);
  354. }               
  355. // MA_Method=1: EMA - Exponential Moving Average
  356. double EMA(double price,double& array[],int per,int bar)
  357. {
  358.    if(bar == 2) double ema = price;
  359.    else
  360.    if(bar > 2) ema = array[bar-1] + 2.0/(1+per)*(price - array[bar-1]);
  361.    
  362.    return(ema);
  363. }
  364. // MA_Method=2: Wilder - Wilder Exponential Moving Average
  365. double Wilder(double& array1[],double& array2[],int per,int bar)
  366. {
  367.    if(bar == per) double wilder = SMA(array1,per,bar);
  368.    else
  369.    if(bar > per) wilder = array2[bar-1] + (array1[bar] - array2[bar-1])/per;
  370.    
  371.    return(wilder);
  372. }
  373. // MA_Method=3: LWMA - Linear Weighted Moving Average
  374. double LWMA(double& array[],int per,int bar)
  375. {
  376.    double Sum = 0;
  377.    double Weight = 0;
  378.    
  379.       for(int i = 0;i < per;i++)
  380.       {
  381.       Weight+= (per - i);
  382.       Sum += array[bar-i]*(per - i);
  383.       }
  384.    if(Weight>0) double lwma = Sum/Weight;
  385.    else lwma = 0;
  386.    return(lwma);
  387. }
  388. // MA_Method=4: SineWMA - Sine Weighted Moving Average
  389. double SineWMA(double& array[],int per,int bar)
  390. {
  391.    double pi = 3.1415926535;
  392.    double Sum = 0;
  393.    double Weight = 0;
  394.   
  395.       for(int i = 0;i < per-1;i++)
  396.       {
  397.       Weight+= MathSin(pi*(i+1)/(per+1));
  398.       Sum += array[bar-i]*MathSin(pi*(i+1)/(per+1));
  399.       }
  400.    if(Weight>0) double swma = Sum/Weight;
  401.    else swma = 0;
  402.    return(swma);
  403. }
  404. // MA_Method=5: TriMA - Triangular Moving Average
  405. double TriMA(double& array[],int per,int bar)
  406. {
  407.    double sma;
  408.    int len = MathCeil((per+1)*0.5);
  409.    
  410.    double sum=0;
  411.    for(int i = 0;i < len;i++)
  412.    {
  413.    sma = SMA(array,len,bar-i);
  414.    sum += sma;
  415.    }
  416.    double trima = sum/len;
  417.    
  418.    return(trima);
  419. }
  420. // MA_Method=6: LSMA - Least Square Moving Average (or EPMA, Linear Regression Line)
  421. double LSMA(double& array[],int per,int bar)
  422. {   
  423.    double Sum=0;
  424.    for(int i=per; i>=1; i--) Sum += (i-(per+1)/3.0)*array[bar-per+i];
  425.    double lsma = Sum*6/(per*(per+1));
  426.    return(lsma);
  427. }
  428. // MA_Method=7: SMMA - Smoothed Moving Average
  429. double SMMA(double& array1[],double& array2[],int per,int bar)
  430. {
  431.    if(bar == per) double smma = SMA(array1,per,bar);
  432.    else
  433.    if(bar > per)
  434.    {
  435.    double Sum = 0;
  436.    for(int i = 0;i < per;i++) Sum += array1[bar-i-1];
  437.    smma = (Sum - array2[bar-1] + array1[bar])/per;
  438.    }
  439.    return(smma);
  440. }               
  441. // MA_Method=8: HMA - Hull Moving Average by Alan Hull
  442. double HMA(double& array[],int per,int bar)
  443. {
  444.    double ttmp[];
  445.    int len =  MathSqrt(per);
  446.    ArrayResize(ttmp,len);
  447.    
  448.    if(bar == per) double hma = array[bar];
  449.    else
  450.    if(bar > per)
  451.    {
  452.    for(int i = 0; i < len;i++) ttmp[len-i-1] = 2*LWMA(array,per/2,bar-i) - LWMA(array,per,bar-i);  
  453.    hma = LWMA(ttmp,len,len-1);
  454.    }  
  455.    return(hma);
  456. }
  457. // MA_Method=9: ZeroLagEMA - Zero-Lag Exponential Moving Average
  458. double ZeroLagEMA(double& array1[],double& array2[],int per,int bar)
  459. {
  460.    double alfa = 2.0/(1+per);
  461.    int lag = 0.5*(per - 1);
  462.    
  463.    if(bar == lag) double zema = array1[bar];
  464.    else
  465.    if(bar > lag) zema = alfa*(2*array1[bar] - array1[bar-lag]) + (1-alfa)*array2[bar-1];
  466.    
  467.    return(zema);
  468. }
  469. // MA_Method=10: DEMA - Double Exponential Moving Average by Patrick Mulloy
  470. double DEMA(int num,double price,int per,double v,int bar)
  471. {
  472.    if(bar == 2) {double dema = price; tmp[bar][num] = dema; tmp[bar][num+1] = dema;}
  473.    else
  474.    if(bar > 2)
  475.    {
  476.    tmp[bar][num] = tmp[bar-1][num] + 2.0/(1+per)*(price - tmp[bar-1][num]);
  477.    tmp[bar][num+1] = tmp[bar-1][num+1] + 2.0/(1+per)*(tmp[bar][num] - tmp[bar-1][num+1]);
  478.    dema = (1+v)*tmp[bar][num] - v*tmp[bar][num+1];
  479.    }
  480.    return(dema);
  481. }
  482. // MA_Method=11: T3 by T.Tillson
  483. double T3(double price,int per,double v,int bar)
  484. {
  485.    if(bar == 2)
  486.    {
  487.    double T3 = price;
  488.    for(int k=0;k<=5;k++) tmp[bar][k] = T3;
  489.    }
  490.    else
  491.    if(bar > 2)
  492.    {
  493.    double dema1 = DEMA(0,price,per,v,bar);
  494.    double dema2 = DEMA(2,dema1,per,v,bar);
  495.    T3 = DEMA(4,dema2,per,v,bar);
  496.    }
  497.    return(T3);
  498. }
  499. // MA_Method=12: ITrend - Instantaneous Trendline by J.Ehlers
  500. double ITrend(double& price[],double& array[],int per,int bar)
  501. {
  502.    double alfa = 2.0/(per+1);
  503.    if(bar > 7)
  504.    double it = (alfa - 0.25*alfa*alfa)*price[bar]+ 0.5*alfa*alfa*price[bar-1]-(alfa - 0.75*alfa*alfa)*price[bar-2]+
  505.    2*(1-alfa)*array[bar-1] - (1-alfa)*(1-alfa)*array[bar-2];
  506.    else
  507.    it = (price[bar] + 2*price[bar-1]+ price[bar-2])/4;
  508.    
  509.    return(it);
  510. }
  511. // MA_Method=13: Median - Moving Median
  512. double Median(double& price[],int per,int bar)
  513. {
  514.    double array[];
  515.    ArrayResize(array,per);
  516.    
  517.    for(int i = 0; i < per;i++) array[i] = price[bar-i];
  518.    ArraySort(array);
  519.    
  520.    int num = MathRound((per-1)/2);
  521.    if(MathMod(per,2)>0) double median = array[num]; else median = 0.5*(array[num]+array[num+1]);
  522.    
  523.    return(median);
  524. }
  525. // MA_Method=14: GeoMean - Geometric Mean
  526. double GeoMean(double& price[],int per,int bar)
  527. {
  528.    double gmean = MathPow(price[bar],1.0/per);
  529.    for(int i = 1; i < per;i++) gmean *= MathPow(price[bar-i],1.0/per);
  530.    
  531.    return(gmean);
  532. }
  533. // MA_Method=15: REMA - Regularized EMA by Chris Satchwell
  534. double REMA(double price,double& array[],int per,double lambda,int bar)
  535. {
  536.    double alpha =  2.0/(per + 1);
  537.    if(bar <= 3) double rema = price;
  538.    else
  539.    if(bar > 3)
  540.    rema = (array[bar-1]*(1+2*lambda) + alpha*(price - array[bar-1]) - lambda*array[bar-2])/(1+lambda);
  541.    
  542.    return(rema);
  543. }
  544. // MA_Method=16: ILRS - Integral of Linear Regression Slope
  545. double ILRS(double& price[],int per,int bar)
  546. {
  547.    double sum = per*(per-1)*0.5;
  548.    double sum2 = (per-1)*per*(2*per-1)/6.0;
  549.      
  550.    double sum1 = 0;
  551.    double sumy = 0;
  552.       for(int i=0;i<per;i++)
  553.       {
  554.       sum1 += i*price[bar-i];
  555.       sumy += price[bar-i];
  556.       }
  557.    double num1 = per*sum1 - sum*sumy;
  558.    double num2 = sum*sum - per*sum2;
  559.    
  560.    if(num2 != 0) double slope = num1/num2; else slope = 0;
  561.    double ilrs = slope + SMA(price,per,bar);
  562.    
  563.    return(ilrs);
  564. }
  565. // MA_Method=17: IE/2 - Combination of LSMA and ILRS
  566. double IE2(double& price[],int per,int bar)
  567. {
  568.    double ie = 0.5*(ILRS(price,per,bar) + LSMA(price,per,bar));
  569.       
  570.    return(ie);
  571. }

  572. // MA_Method=18: TriMAgen - Triangular Moving Average Generalized by J.Ehlers
  573. double TriMA_gen(double& array[],int per,int bar)
  574. {
  575.    int len1 = MathFloor((per+1)*0.5);
  576.    int len2 = MathCeil((per+1)*0.5);
  577.    double sum=0;
  578.    for(int i = 0;i < len2;i++) sum += SMA(array,len1,bar-i);
  579.    double trimagen = sum/len2;
  580.    
  581.    return(trimagen);
  582. }
  583. // MA_Method=19: VWMA - Volume Weighted Moving Average
  584. double VWMA(double& array[],int per,int bar)
  585. {
  586.    double Sum = 0;
  587.    double Weight = 0;
  588.    
  589.       for(int i = 0;i < per;i++)
  590.       {
  591.       Weight+= Volume[mBars-bar-1+i];
  592.       Sum += array[bar-i]*Volume[mBars-bar-1+i];
  593.       }
  594.    if(Weight>0) double vwma = Sum/Weight;
  595.    else vwma = 0;
  596.    return(vwma);
  597. }
  598. // MA_Method=20: JSmooth - Smoothing by Mark Jurik
  599. double JSmooth(double price,int per,double pow,int bar)
  600. {
  601.    double beta = 0.45*(per-1)/(0.45*(per-1)+2);
  602.         double alpha = MathPow(beta,pow);
  603.         if(bar == 2) {tmp[bar][4] = price; tmp[bar][0] = price; tmp[bar][2] = price;}
  604.         else
  605.    if(bar > 2)
  606.    {
  607.         tmp[bar][0] = (1-alpha)*price + alpha*tmp[bar-1][0];
  608.         tmp[bar][1] = (price - tmp[bar][0])*(1-beta) + beta*tmp[bar-1][1];
  609.         tmp[bar][2] = tmp[bar][0] + tmp[bar][1];
  610.         tmp[bar][3] = (tmp[bar][2] - tmp[bar-1][4])*MathPow((1-alpha),2) + MathPow(alpha,2)*tmp[bar-1][3];
  611.         tmp[bar][4] = tmp[bar-1][4] + tmp[bar][3];
  612.    }
  613.    return(tmp[bar][4]);
  614. }
  615. // HeikenAshi Price:  7 - Close,8 - Open,9 - High,10 - Low
  616. double HeikenAshi(int tf,int price,int bar)
  617. {
  618.    if(bar == iBars(NULL,TimeFrame)- 1)
  619.    {
  620.    haClose[bar] = iClose(NULL,tf,bar);
  621.    haOpen[bar]  = iOpen(NULL,tf,bar);
  622.    haHigh[bar]  = iHigh(NULL,tf,bar);
  623.    haLow[bar]   = iLow(NULL,tf,bar);
  624.    }
  625.    else
  626.    {
  627.    haClose[bar] = (iOpen(NULL,tf,bar)+iHigh(NULL,tf,bar)+iLow(NULL,tf,bar)+iClose(NULL,tf,bar))/4;
  628.    haOpen[bar]  = (haOpen[bar+1]+haClose[bar+1])/2;
  629.    haHigh[bar]  = MathMax(iHigh(NULL,tf,bar),MathMax(haOpen[bar], haClose[bar]));
  630.    haLow[bar]   = MathMin(iLow(NULL,tf,bar),MathMin(haOpen[bar], haClose[bar]));
  631.    }
  632.    
  633.    switch(price)
  634.    {
  635.    case 0: return(haClose[bar]);break;
  636.    case 1: return(haOpen[bar]);break;
  637.    case 2: return(haHigh[bar]);break;
  638.    case 3: return(haLow[bar]);break;
  639.    }
  640.    return(iClose(NULL,tf,bar));
  641. }   
复制代码

   
                       

6

主题

2064

积分

0

精华

中级操盘手

金钱
2064 美元
权重
4
 楼主| 发表于 2015-4-28 15:59 | 显示全部楼层
本帖最后由 wccmcd 于 2015-12-4 12:05 编辑

请老师们帮忙{:soso_e163:}

6

主题

2064

积分

0

精华

中级操盘手

金钱
2064 美元
权重
4
 楼主| 发表于 2015-5-1 07:41 | 显示全部楼层
本帖最后由 wccmcd 于 2015-12-4 12:05 编辑

{:soso_e132:}{:soso_e132:}

30

主题

1万

积分

0

精华

操盘专家

金钱
13785 美元
权重
1
发表于 2016-11-3 08:41 | 显示全部楼层
就是越长说明计算的越复杂。调用越多。在这上面找问题,还是问原作者吧

4

主题

2427

积分

0

精华

中级操盘手

金钱
2427 美元
权重
0
发表于 2016-12-26 09:04 | 显示全部楼层
楼主辛苦了!
您需要登录后才可以回帖 登录 | 快捷注册(禁q号)

本版积分规则

QQ|黄金吧|黄金论坛|手机版|指标下载|非农|目录|交易危机

版权所有: ©2014-2021 fx3q.com Powered by Discuz! X3
浙ICP备: ICP14039028

浙公网安备 33011802001420号

风险提示:杠杆风险高,交易要谨慎 声明:坛友发言和回复均为个人观点,不代表论坛立场。
若有侵权请联系fx3q@qq.com删除

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