有您的持续关注
我们会做得更好

很实用的副图指标MA_Trend



MA_Trend指标在副图呈现行情的波动方向,并用不同的颜色区分涨跌。

MA_Trend指标图表效果如下:MA_Trend指标

MA_Trend指标MQL4源码如下:

//+------------------------------------------------------------------+
//|                                                     MA_Trend.mq4 |
//|                                Copyright @2014, Gehtsoft USA LLC |
//|                                            http://fxcodebase.com |
//+------------------------------------------------------------------+
#property copyright "Copyright @2014, Gehtsoft USA LLC"
#property link      "http://fxcodebase.com"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Blue

extern int Method=0;  // 0 - SMA
                      // 1 - EMA
                      // 2 - SMMA
                      // 3 - LWMA
extern int Start_Period=10;
extern int Step_Period=10;
extern int Count_Of_MAs=50;
extern int Price=0;    // Applied price
                       // 0 - Close
                       // 1 - Open
                       // 2 - High
                       // 3 - Low
                       // 4 - Median
                       // 5 - Typical
                       // 6 - Weighted  

double L[], Up[], Dn[];

int init()
{
 IndicatorShortName("MA Trend oscillator");
 IndicatorDigits(Digits);
 SetIndexStyle(0,DRAW_LINE);
 SetIndexBuffer(0,L);
 SetIndexStyle(1,DRAW_HISTOGRAM);
 SetIndexBuffer(1,Up);
 SetIndexStyle(2,DRAW_HISTOGRAM);
 SetIndexBuffer(2,Dn);

 return(0);
}

int deinit()
{
   Comment("www.125808047.com");
 return(0);
}

int start()
{
 if(Bars<=3) return(0);
 int ExtCountedBars=IndicatorCounted();
 if (ExtCountedBars<0) return(-1);
 int limit=Bars-2;
 if(ExtCountedBars>2) limit=Bars-ExtCountedBars-1;
 int pos;
 int i;
 double Sum;
 double Pr, MA;
 int Length;
 pos=limit;
 while(pos>=0)
 {
  Sum=0.;
  Pr=iMA(NULL, 0, 1, 0, MODE_SMA, Price, pos);
  for (i=1;i<=Count_Of_MAs;i++)
  {
   Length=Start_Period+(i-1)*Step_Period;
   MA=iMA(NULL, 0, Length, 0, Method, Price, pos);
   if (Pr>MA)
   {
    Sum++;
   }
   else
   {
    if (Pr<MA)
    {
     Sum--;
    }
   }
  }
  
  L[pos]=Sum/Count_Of_MAs;
  if (L[pos]>0.)
  {
   Up[pos]=L[pos];
   Dn[pos]=0.;
  }
  else
  {
   Up[pos]=0.;
   Dn[pos]=L[pos];
  }

  pos--;
 } 
 return(0);
}

如您喜欢此文章请点下面分享按钮↴峰汇在线 » 很实用的副图指标MA_Trend
上一篇:
下一篇:
分享到:更多 ()