MTF_MACD_4x1v3M





//+------------------------------------------------------------------+
//|   MTF_MACD_4x1v3M               CJA Hoh  zlagMACD_4in1_v2.mq4 ik |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|    MTF_MACD_CJA_4x1v3M                 http://www.metaquotes.net |
//|                MACD 4in1  "CJA";   mod  v2"HOH CHEE YEN" RD fxbs |
//|                ForexTSD.com 2007                marynarz15@wp.pl |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property link      "CJA"
#property link      "HOH CHEE YEN"
/* Legend's settings can be "extern" to be adjustable in MT4.
   Use TF1_Color etc. and not indicator's color to synchronize 
   indicator and legend's colors. Switch timeframe for immediate
   update if it's not. (HCY)
*/
#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 4
#property indicator_style2 2
#property indicator_width3 3
#property indicator_style4 2
#property indicator_width5 2
#property indicator_style6 2
#property indicator_width7 1
#property indicator_style8 2
#property indicator_level1 0

// Different Currencies may need different Factors to help
// separate the different MACD lines - raise the Factor # on the 
// largest moving MACD lines to enlarge the view of the other 3 MACD Timeframes.
//extern double TF1_Factor=12;
//extern double TF2_Factor=6;
//extern double TF3_Factor=2;
//extern double TF4_Factor=1;
/* Original setings (HCY)
extern double    MACD_FactorH1 =12;
extern double    MACD_FactorM15=6;
extern double    MACD_FactorM5=2;
extern double    MACD_FactorM1=1;
*/
// Definable timeframes (HCY)
extern int TF1=1440;
extern int TF2=240;
extern int TF3=60;
extern int TF4=30;
// Synchronize indicator's and legend's color (HCY)
extern color TF1_Color=Red;
extern color TF2_Color=DeepSkyBlue;
extern color TF3_Color=LawnGreen;
extern color TF4_Color=Orange;
//---- Below can be "extern" to be adjustable in MT4 (HCY)------//
string Legend_Font="Arial Bold";
int Legend_FontSize=8;
int Legend_StartAt=95;
int Legend_Space=25;
int Legend_YPosition=0;
//--------------------------------------------------------------//
int LegendXPos=0;

//---- input parameters
// Definable settings for each timeframe (HCY)
/* Settings for different periods (Own preferences): (HCY)
MN,WK,D1:22,11,8 -- D1:11,22,8
WK,D1,H4:30,13,10 -- H4:13,30,10
D1,H4,H1:24,11,8 -- H1:11,24,8
H4,H1,M15:15,7,5 -- M15:7,15,5
H1,M15,M5:12(or 13),6,4 -- M5:6,12,4
M15,M5,M1:15,7,5 -- M1:7,15,5
*/
extern int TF1_FastEMA=12;
extern int TF1_SlowEMA=26;
extern int TF1_SignalSMA=9; 
extern int TF2_FastEMA=12;
extern int TF2_SlowEMA=26;
extern int TF2_SignalSMA=9; 
extern int TF3_FastEMA=12;
extern int TF3_SlowEMA=26;
extern int TF3_SignalSMA=9; 
extern int TF4_FastEMA=12;
extern int TF4_SlowEMA=26;
extern int TF4_SignalSMA=9; 
/* Original settings (HCY)
extern int       FastEMA=12;  //8  Faster settings
extern int       SlowEMA=26;  //17   //35,5,5//Valeo:5,8,5
extern int       SignalSMA=9; //9 
*/

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

// Indicator name (HCY)
string IndicatorName = "MACD_4x1";
// Set shorter indicator name (HCY)
//string IndicatorName = "zM4in1";

// Show proper timeframe string (HCY)
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);
   }

// Show legend (HCY)
void ShowLegend(int TimeFrame,string LegendName,color LegendColor) {
   if (TimeFrame==0) TimeFrame=Period();
   string TimeFrameStr=GetTimeFrameStr(TimeFrame);
   // Enlarge legend for current timeframe (HCY)
   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 (0);
   }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorName=IndicatorName+" ("+GetTimeFrameStr(Period())+")";
   IndicatorShortName(IndicatorName);
//---- indicators
   // Synchronize legend and line's colors (HCY)
   SetIndexStyle(0,DRAW_LINE,EMPTY,EMPTY,TF1_Color);
//   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   // No value displayed at left corner (HCY)
   SetIndexLabel(0,NULL);
   // Synchronize legend and line's colors (HCY)
   SetIndexStyle(1,DRAW_LINE,EMPTY,EMPTY,TF1_Color);
//   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   // No value displayed at left corner (HCY)
   SetIndexLabel(1,NULL);
   // Synchronize legend and line's colors (HCY)
   SetIndexStyle(2,DRAW_LINE,EMPTY,EMPTY,TF2_Color);
//   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);
   // No value displayed at left corner (HCY)
   SetIndexLabel(2,NULL);
   // Synchronize legend and line's colors (HCY)
   SetIndexStyle(3,DRAW_LINE,EMPTY,EMPTY,TF2_Color);
//   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,ExtMapBuffer4);
   // No value displayed at left corner (HCY)
   SetIndexLabel(3,NULL);
   // Synchronize legend and line's colors (HCY)
   SetIndexStyle(4,DRAW_LINE,EMPTY,EMPTY,TF3_Color);
//   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,ExtMapBuffer5);
   // No value displayed at left corner (HCY)
   SetIndexLabel(4,NULL);
   // Synchronize legend and line's colors (HCY)
   SetIndexStyle(5,DRAW_LINE,EMPTY,EMPTY,TF3_Color);
//   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,ExtMapBuffer6);
   // No value displayed at left corner (HCY)
   SetIndexLabel(5,NULL);
   // Synchronize legend and line's colors (HCY)
   SetIndexStyle(6,DRAW_LINE,EMPTY,EMPTY,TF4_Color);
//   SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(6,ExtMapBuffer7);
   // No value displayed at left corner (HCY)
   SetIndexLabel(6,NULL);
   // Synchronize legend and line's colors (HCY)
   SetIndexStyle(7,DRAW_LINE,EMPTY,EMPTY,TF4_Color);
//   SetIndexStyle(7,DRAW_LINE);
   SetIndexBuffer(7,ExtMapBuffer8);
   // No value displayed at left corner (HCY)
   SetIndexLabel(7,NULL);

   // Show legends. (HCY)
   // Note: MT4 is not always sensitive to unload this indicator and initialize to change
   // legend and line colors. Simply switch timeframe for immediate update. (HCY)
   LegendXPos=Legend_StartAt;
   ShowLegend(TF1, "MACD4x1_TF1", TF1_Color);
   ShowLegend(TF2, "MACD4x1_TF2", TF2_Color);
   ShowLegend(TF3, "MACD4x1_TF3", TF3_Color);
   ShowLegend(TF4, "MACD4x1_TF4", TF4_Color);
 

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   // Delete Legends (HCY)
   ObjectDelete("MACD4x1_TF1");
   ObjectDelete("MACD4x1_TF2");
   ObjectDelete("MACD4x1_TF3");
   ObjectDelete("MACD4x1_TF4");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   datetime TimeArray1[],TimeArray2[],TimeArray3[],TimeArray4[];
   int    i,shift,limit,y1=0,y2=0,y3=0,y4=0,counted_bars=IndicatorCounted();
    
   ArrayCopySeries(TimeArray1,MODE_TIME,Symbol(),TF1); 
   ArrayCopySeries(TimeArray2,MODE_TIME,Symbol(),TF2); 
   ArrayCopySeries(TimeArray3,MODE_TIME,Symbol(),TF3); 
   ArrayCopySeries(TimeArray4,MODE_TIME,Symbol(),TF4); 
  
   limit=Bars-counted_bars+TF4/Period();
   
   for(i=0,y1=0,y2=0,y3=0,y4=0;i<limit;i++)
   {
if (Time[i]<TimeArray1[y1]) y1++; 
if (Time[i]<TimeArray2[y2]) y2++; 
if (Time[i]<TimeArray3[y3]) y3++; 
if (Time[i]<TimeArray4[y4]) y4++; 
if (TF1<=Period()) TF1=Period();
if(TF2<=Period())TF2=Period();
if(TF3<=Period())TF3=Period();
if (TF4<=Period())TF4=Period();

      // Definable timeframes (HCY)
  //Original settings (HCY)
      ExtMapBuffer1[i]=(iMACD(NULL,TF1,TF1_FastEMA,TF1_SlowEMA,TF1_SignalSMA,PRICE_CLOSE,MODE_MAIN,y1)); 
      ExtMapBuffer2[i]=(iMACD(NULL,TF1,TF1_FastEMA,TF1_SlowEMA,TF1_SignalSMA,PRICE_CLOSE,MODE_SIGNAL,y1));  
      ExtMapBuffer3[i]=(iMACD(NULL,TF2,TF2_FastEMA,TF2_SlowEMA,TF2_SignalSMA,PRICE_CLOSE,MODE_MAIN,y2)); 
      ExtMapBuffer4[i]=(iMACD(NULL,TF2,TF2_FastEMA,TF2_SlowEMA,TF2_SignalSMA,PRICE_CLOSE,MODE_SIGNAL,y2)); 
      ExtMapBuffer5[i]=(iMACD(NULL,TF3,TF3_FastEMA,TF3_SlowEMA,TF3_SignalSMA,PRICE_CLOSE,MODE_MAIN,y3)); 
      ExtMapBuffer6[i]=(iMACD(NULL,TF3,TF3_FastEMA,TF3_SlowEMA,TF3_SignalSMA,PRICE_CLOSE,MODE_SIGNAL,y3)); 
      ExtMapBuffer7[i]=(iMACD(NULL,TF4,TF4_FastEMA,TF4_SlowEMA,TF4_SignalSMA,PRICE_CLOSE,MODE_MAIN,y4)); 
      ExtMapBuffer8[i]=(iMACD(NULL,TF4,TF4_FastEMA,TF4_SlowEMA,TF4_SignalSMA,PRICE_CLOSE,MODE_SIGNAL,y4));  

        
      } 
    }
//----
   return(0);
  
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar


Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:

MACD Histogram


Custom Indicators Used:

Order Management characteristics:

Other Features: