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

多周期MACD共振指标 MACD_4in1_v2

MACD_4in1_v2指标创建多周期MACD快线和慢线,可以在同步金叉或死叉时参考交易信号。

MACD_4in1_v2指标图表:MACD_4in1_v2指标

MACD_4in1_v2指标源码:

//+------------------------------------------------------------------+
//|                                                 MACD_4in1_v2.mq4 |
//|                       Copyright @2006, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright @2006, MetaQuotes Software Corp."
#property link      "http://www.125808047.com/"

#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 DeepSkyBlue
#property indicator_color4 DeepSkyBlue
#property indicator_color5 LawnGreen
#property indicator_color6 LawnGreen
#property indicator_color7 Orange
#property indicator_color8 Orange
#property indicator_width1 1
#property indicator_style2 2
#property indicator_width3 1
#property indicator_style4 2
#property indicator_width5 1
#property indicator_style6 2
#property indicator_width7 1
#property indicator_style8 2
#property indicator_level1 0

extern double TF1_Factor=12;
extern double TF2_Factor=6;
extern double TF3_Factor=2;
extern double TF4_Factor=1;

extern int TF1=240;
extern int TF2=60;
extern int TF3=15;
extern int TF4=5;

extern color TF1_Color=Red;
extern color TF2_Color=DeepSkyBlue;
extern color TF3_Color=LawnGreen;
extern color TF4_Color=Orange;

string Legend_Font="Arial Bold";
int Legend_FontSize=8;
int Legend_StartAt=90;
int Legend_Space=25;
int Legend_YPosition=0;
int LegendXPos=0;

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

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];

string IndicatorName="MACD_4in1";
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
  string GetTimeFrameStr(int TimeFrame) 
  {
   if (TimeFrame==0) TimeFrame=Period();
   switch(TimeFrame)
     {
      case 1 : string TimeFrameStr="M1"; break;
      case 5 : TimeFrameStr="M5"; break;
      case 15 : TimeFrameStr="M15"; break;
      case 30 : TimeFrameStr="M30"; break;
      case 60 : TimeFrameStr="H1"; break;
      case 240 : TimeFrameStr="H4"; break;
      case 1440 : TimeFrameStr="D1"; break;
      case 10080 : TimeFrameStr="W1"; break;
      case 43200 : TimeFrameStr="MN1"; break;
      default : TimeFrameStr="CUR";
     }
   return(TimeFrameStr);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
  void ShowLegend(int TimeFrame,string LegendName,color LegendColor) 
  {
   if (TimeFrame==0) TimeFrame=Period();
   string TimeFrameStr=GetTimeFrameStr(TimeFrame);
   ObjectCreate(LegendName, OBJ_LABEL, WindowFind(IndicatorName), 0, 0);
     if (Period()==TimeFrame) 
     {
      ObjectSetText(LegendName, TimeFrameStr, Legend_FontSize+Legend_FontSize/3, Legend_Font, LegendColor);
      ObjectSet(LegendName, OBJPROP_CORNER, 0);
      ObjectSet(LegendName, OBJPROP_XDISTANCE, LegendXPos);
      ObjectSet(LegendName, OBJPROP_YDISTANCE, Legend_YPosition);
      LegendXPos=LegendXPos+Legend_Space+Legend_Space/4;
     }
     else 
     {
      ObjectSetText(LegendName, TimeFrameStr, Legend_FontSize, Legend_Font, LegendColor);
      ObjectSet(LegendName, OBJPROP_CORNER, 0);
      ObjectSet(LegendName, OBJPROP_XDISTANCE, LegendXPos);
      ObjectSet(LegendName, OBJPROP_YDISTANCE, Legend_YPosition);
      LegendXPos=LegendXPos+Legend_Space;
     }
   if (StringLen(TimeFrameStr)>2) LegendXPos=LegendXPos+Legend_Space/3;
   return;
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorName=IndicatorName+" ("+GetTimeFrameStr(Period())+")";
   IndicatorShortName(IndicatorName);

   SetIndexStyle(0,DRAW_LINE,EMPTY,EMPTY,TF1_Color);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexLabel(0,NULL);
   SetIndexStyle(1,DRAW_LINE,EMPTY,EMPTY,TF1_Color);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel(1,NULL);
   SetIndexStyle(2,DRAW_LINE,EMPTY,EMPTY,TF2_Color);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexLabel(2,NULL);
   SetIndexStyle(3,DRAW_LINE,EMPTY,EMPTY,TF2_Color);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexLabel(3,NULL);
   SetIndexStyle(4,DRAW_LINE,EMPTY,EMPTY,TF3_Color);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexLabel(4,NULL);
   SetIndexStyle(5,DRAW_LINE,EMPTY,EMPTY,TF3_Color);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexLabel(5,NULL);
   SetIndexStyle(6,DRAW_LINE,EMPTY,EMPTY,TF4_Color);
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexLabel(6,NULL);
   SetIndexStyle(7,DRAW_LINE,EMPTY,EMPTY,TF4_Color);
   SetIndexBuffer(7,ExtMapBuffer8);
   SetIndexLabel(7,NULL);
   LegendXPos=Legend_StartAt;
   ShowLegend(TF1, "MACD4in1_TF1", TF1_Color);
   ShowLegend(TF2, "MACD4in1_TF2", TF2_Color);
   ShowLegend(TF3, "MACD4in1_TF3", TF3_Color);
   ShowLegend(TF4, "MACD4in1_TF4", TF4_Color);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("MACD4in1_TF1");
   ObjectDelete("MACD4in1_TF2");
   ObjectDelete("MACD4in1_TF3");
   ObjectDelete("MACD4in1_TF4");
   Comment("www.125808047.com");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int    counted_bars=IndicatorCounted();
     for(int i=Bars;i>=0;i--)
     {
      ExtMapBuffer1[i]=(iMACD(NULL,TF1,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,i)/TF1_Factor);
      ExtMapBuffer2[i]=(iMACD(NULL,TF1,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,i)/TF1_Factor);
      ExtMapBuffer3[i]=(iMACD(NULL,TF2,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,i)/TF2_Factor);
      ExtMapBuffer4[i]=(iMACD(NULL,TF2,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,i)/TF2_Factor);
      ExtMapBuffer5[i]=(iMACD(NULL,TF3,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,i)/TF3_Factor);
      ExtMapBuffer6[i]=(iMACD(NULL,TF3,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,i)/TF3_Factor);
      ExtMapBuffer7[i]=(iMACD(NULL,TF4,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,i)/TF4_Factor);
      ExtMapBuffer8[i]=(iMACD(NULL,TF4,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,i)/TF4_Factor);
     }
    return(0); }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 多周期MACD共振指标 MACD_4in1_v2
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏