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

MT4自定义指标 显示均线类型参数及价格的指标



MT4自定义指标MA_Details.mq4在插入均线后能够显示均线类型参数及价格,在某些需要用到均线支撑或阻力的时候很是方便。

插入图表效果如下:

MT4指标

MQL4源码如下:

//+------------------------------------------------------------------+
//|                                        Custom Moving Average.mq4 |
//|                                       Copyright @2013, 125808047 |
//+------------------------------------------------------------------+
#property copyright "www.125808047.com"
#property link      "http://www.125808047.com"

#property indicator_chart_window
#property indicator_buffers 1
//#property indicator_color1 Red
//---- indicator parameters
extern int MA_Period=13;
extern int MA_Shift=0;
extern int MA_Method=0;
extern int MA_Applied=0;
extern int Fontsize=10;
extern color Color_1 = Red;

//---- indicator buffers
double ExtMapBuffer[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int    draw_begin;
   string short_name;
   SetIndexStyle(0,DRAW_LINE,EMPTY,EMPTY,Color_1);
   SetIndexShift(0,MA_Shift);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   if(MA_Period<2) MA_Period=13;
   draw_begin=MA_Period-1;
   
   switch(MA_Method)
   {
      case 1 : short_name="EMA(";  draw_begin=0; break;
      case 2 : short_name="SMMA("; break;
      case 3 : short_name="LWMA("; break;
      default :
         MA_Method=0;
         short_name="SMA(";
   }
   IndicatorShortName(short_name+MA_Period+")");
   SetIndexDrawBegin(0,draw_begin);
   SetIndexBuffer(0,ExtMapBuffer);
   return(0);
  }

int start()
 {
   int limit;
  string short_name;
   int counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for(int i=0; i<limit; i++)
      ExtMapBuffer[i]=iMA(NULL,0,MA_Period,MA_Shift,MA_Method,MA_Applied,i);
    
   switch(MA_Method)
     {
      case 0 : short_name="SMA(";  break;
      case 1 : short_name="EMA(";  break;
      case 2 : short_name="SMMA("; break;
      case 3 : short_name="LWMA(";
     }   
       
double ma_1;
ma_1=iMA(0,0,MA_Period,MA_Shift,MA_Method,MA_Applied,0);
 
   ObjectDelete("MA"+MA_Period);
   ObjectCreate("MA"+MA_Period ,OBJ_TEXT, 0, Time[0], ma_1+0.0010); 
   ObjectSetText("MA"+MA_Period,"                                     "+short_name+ MA_Period+") "+GetMethodText(MA_Applied)+"  "+ (DoubleToStr(ma_1,Digits)) ,Fontsize, "MS Sans Serif", Color_1);  

 
   return(0);
}

string GetMethodText(int MA_Applied)
 {
 switch(MA_Applied)  
   {case 0: return("C"); break;    // Close
    case 1: return("O"); break;    // Open
    case 2: return("H"); break;    // High
    case 3: return("L"); break; }  // Low
    return(0);
  }

如您喜欢此文章请点下面分享按钮↴峰汇在线 » MT4自定义指标 显示均线类型参数及价格的指标
上一篇:
下一篇:
分享到:更多 ()