诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

另类MACD指标 Combined_MA_Signal.mq4

Combined_MA_Signal指标创建另类MACD。

图表:Combined_MA_Signal指标

源码:

//+------------------------------------------------------------------+
//|                                           Combined_MA_Signal.mq4 |
//|                                                  Edi Dimitrovski |
//+------------------------------------------------------------------+
#property copyright "Edi Dimitrovski"
#property link      "http://www.125808047.com"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 LightSeaGreen
#property indicator_color2 Silver
#property indicator_color3 Green
#property indicator_color4 Red
#property indicator_width3 1
#property indicator_width4 1
#property indicator_level1 0

extern int       Signal=8;
extern bool      Slow=0;
extern bool      Repaint=0;
extern double    FilterPoints=8;

double ExtSilverBuffer[];
double ExtGreenBuffer[];
double ExtBlueBuffer[];
double ExtRedBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
   SetIndexDrawBegin(0,Signal);
   SetIndexDrawBegin(1,Signal);
   SetIndexDrawBegin(2,Signal);
   SetIndexDrawBegin(3,Signal);
   IndicatorDigits(Digits+1);

   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(2,241);
   SetIndexArrow(3,242);

   SetIndexBuffer(0,ExtSilverBuffer);
   SetIndexBuffer(1,ExtGreenBuffer);
   SetIndexBuffer(2,ExtBlueBuffer);
   SetIndexBuffer(3,ExtRedBuffer);
   SetIndexEmptyValue(2,0.0);
   SetIndexEmptyValue(3,0.0);
   IndicatorShortName("CMA("+Signal+","+Slow+","+Repaint+")");
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Moving Average of Oscillator                                     |
//+------------------------------------------------------------------+
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[])
  {
   int count, limit;
   double dif,buf1,buf2;
   int counted_bars=IndicatorCounted();

   if(counted_bars<0) return(-1);

   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for(int i=0; i<limit; i++)
    {
     ExtGreenBuffer[i]=0.0;
     ExtSilverBuffer[i]=0.0;
     buf1=0;
     buf2=0;
     count=Signal;
     while(count>0)
      {
       dif=
          iMA(NULL,0,(count*2),0,3,0,i)
         -iMA(NULL,0,(count*3),0,3,4,i)
         +iMA(NULL,0,(count*2),0,3,4,i)
         -iMA(NULL,0,(count*3),0,3,1,i);
       if(count>=Signal/2)ExtGreenBuffer[i]+=dif;
       if(dif!=0.0)dif/=(count+1)/2;
       if(count+1<=Signal)ExtSilverBuffer[i]+=dif;
       count--;
      }
    }

   for(i=0; i<limit; i++)
    {
     if ((ExtGreenBuffer[i]>ExtGreenBuffer[i+1] || ExtGreenBuffer[i]>0.0)
      && ExtSilverBuffer[i]>ExtSilverBuffer[i+1]+Point*FilterPoints && 
          (ExtSilverBuffer[i]>0.0 || !Slow) && 
           (!(ExtRedBuffer[i]<0.0)
             || Repaint)) ExtBlueBuffer[i]=2*Point;
     else if ((ExtGreenBuffer[i]<ExtGreenBuffer[i+1] || ExtGreenBuffer[i]<0.0)
      && ExtSilverBuffer[i]+Point*FilterPoints<ExtSilverBuffer[i+1] && 
          (ExtSilverBuffer[i]<0.0 || !Slow) && 
           (!(ExtBlueBuffer[i]>0.0)
             || Repaint)) ExtRedBuffer[i]=-2*Point;
    }
   return(rates_total);
  }
打赏
版权所有转载请注明标题及链接:峰汇在线 » 另类MACD指标 Combined_MA_Signal.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏