老王吧 发表于 2017-12-27 11:52:01

MACD_LSMA_EMA



//+------------------------------------------------------------------+
//|                                                MACD_LSMA_EMA.mq4 |
//|                                     Copyright @2007, Robert Hill |
//+------------------------------------------------------------------+
#property copyright "下载更多外汇EA,外汇指标,交易系统,就到【外汇EA之家】"
#property link      "http://www.eazhijia.com"

#propertyindicator_separate_window
#propertyindicator_buffers 4
#propertyindicator_color1Aqua
#propertyindicator_color2Red
#propertyindicator_color3Green
#propertyindicator_color4Red

input int FastEMA=12;
input int SlowEMA=26;
input int SignalSMA=9;

double   MACD_buffer[];
double   Signal_buffer[];
double HistogramBufferUp[];
double HistogramBufferDown[];
bool   ExtParameters=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
   IndicatorDigits(Digits+1);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(0,MACD_buffer);
   SetIndexDrawBegin(0,SlowEMA);
   SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(1,Signal_buffer);
   SetIndexDrawBegin(1,SignalSMA);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexBuffer(2,HistogramBufferUp);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexBuffer(3,HistogramBufferDown);
   IndicatorDigits(Digits+1);

   IndicatorShortName("MACD_LSMA_EMA("+IntegerToString(FastEMA)+","+IntegerToString(SlowEMA)+","+IntegerToString(SignalSMA)+")");
   SetIndexLabel(0,"MACD");
   SetIndexLabel(1,"Signal");
   SetIndexLabel(2,"Histogram");
   if(FastEMA<=1 || SlowEMA<=1 || SignalSMA<=1 || FastEMA>=SlowEMA)
   {
      Print("Wrong input parameters");
      ExtParameters=false;
      return(INIT_FAILED);
   }
   else
      ExtParameters=true;
   Comment("www.eazhijia.com");
    return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------------+
//| LSMA - Least Squares Moving Average function calculation               |
//| LSMA_In_Color Indicator plots the end of the linear regression line    |
//+------------------------------------------------------------------------+
double LSMA(int Rperiod, int shift)
{
   int i;
   double sum;
   int length;
   double lengthvar;
   double tmp;
   double wt;

   length = Rperiod;
   sum = 0;
   for(i = length; i >= 1; i--)
   {
   lengthvar = length + 1;
   lengthvar /= 3;
   tmp = 0;
   tmp = ( i - lengthvar)*Close;
   sum+=tmp;
    }
    wt = MathFloor(sum*6/(length*(length+1))/Point)*Point;
    return(wt);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   double temp;
   int i,limit;
//---
   if(rates_total<=SignalSMA || !ExtParameters)
      return(0);
//--- last counted bar will be recounted
   limit=rates_total-prev_calculated;
   if(prev_calculated>0)
      limit++;

   for(i=0; i<limit; i++)
      MACD_buffer=LSMA(FastEMA,i)-LSMA(SlowEMA,i);

   for(i=0; i<limit; i++)
      Signal_buffer=iMAOnArray(MACD_buffer,Bars,SignalSMA,0,MODE_EMA,i);

   for(i=0; i<limit; i++)
   {
      HistogramBufferUp = 0;
      HistogramBufferDown = 0;
      temp = MACD_buffer - Signal_buffer;
      if (temp >= 0)
      HistogramBufferUp = temp;
      else
      HistogramBufferDown = temp;
   }
    return(rates_total);
}


hnut060 发表于 2018-5-25 00:39:39

好东西!!!!!!!!!!

xing5202 发表于 2018-9-18 11:00:36

貌似有点意思

hov33snu 发表于 2020-6-5 22:21:35

相当不错,感谢无私分享精神!

亮台凯 发表于 2020-7-16 12:55:45

学习了,不错

王┢┦apΡy 发表于 2020-7-20 22:55:24

帮你顶下哈!!

medley 发表于 2020-7-24 12:25:25

帮你顶下哈!!

你的太在乎 发表于 2020-8-16 11:02:16

谢谢楼主分享

QQ1397379127 发表于 2020-8-20 22:33:43

学习了,不错

cvllt74614 发表于 2020-9-1 11:49:10

学习了,不错
页: [1] 2
查看完整版本: MACD_LSMA_EMA