#MTF_zlagMACD_v2

Author: Copyright � 2006, Keris2112
#MTF_zlagMACD_v2
Miscellaneous
Implements a curve of type %1
1 Views
0 Downloads
0 Favorites
#MTF_zlagMACD_v2
//+------------------------------------------------------------------+
//|                                             #MTF_zlagMACD_v2.mq4 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Keris2112"
#property link      "http://www.forex-tsd.com"
#property link      "HOH CHEE YEN"
// Raise "Multiplier" to enlarge its lines (HCY)

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Orange
#property indicator_color2 Orange
#property indicator_level1 0
// Added (HCY)
#property indicator_width1 1
#property indicator_style2 2
// Set window range for proper line display (HCY)
#property indicator_maximum 1
#property indicator_minimum -1

//---- input parameters
/* 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 TimeFrame=0;
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalEMA=9;
// For proper line display - raise this number to enlarge its lines (HCY)
extern double Multiplier=2;  
//---- indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];

//---- input parameters
/*************************************************************************
PERIOD_M1   1
PERIOD_M5   5
PERIOD_M15  15
PERIOD_M30  30 
PERIOD_H1   60
PERIOD_H4   240
PERIOD_D1   1440
PERIOD_W1   10080
PERIOD_MN1  43200
You must use the numeric value of the timeframe that you want to use
when you set the TimeFrame' value with the indicator inputs.
**************************************************************************/
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
//   SetIndexStyle(0,DRAW_SECTION,STYLE_SOLID,1);
//   SetIndexStyle(1,DRAW_SECTION,STYLE_SOLID,1);
   // Draw lines only (HCY)
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
/* Original settings (HCY) 
   SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,2);
   SetIndexStyle(1,DRAW_LINE,EMPTY,2);
*/
   SetIndexDrawBegin(0,SlowEMA);
   SetIndexDrawBegin(1,SlowEMA);
   // No value displayed at left corner (HCY)
   SetIndexLabel(0,NULL);
   SetIndexLabel(1,NULL);
/* Original settings (HCY)
   SetIndexLabel(0,"MACD");
   SetIndexLabel(1,"Signal");
*/
   // Show only 2 decimal points (HCY)
   IndicatorDigits(2);

//---- name for DataWindow and indicator subwindow label
   int TF=TimeFrame;
   if (TimeFrame==0) TF=Period();
   switch(TF)
   {
      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";
   } 

   // Set shorter indicator name (HCY)
//   short_name="MzM";
   // Show only TimeFrame (HCY)
   IndicatorShortName(TimeFrameStr);
/* Original settings (HCY) 
   short_name="MTF ZeroLag MACD";
   IndicatorShortName(short_name+ " " + TimeFrameStr+ " | " +FastEMA + ", " + SlowEMA + ", " + SignalEMA+" |  ");  
*/
//----
   return(0);
  }
 
//+------------------------------------------------------------------+
//| MTF Moving Average                                   |
//+------------------------------------------------------------------+
int start()
  {
   datetime TimeArray[];
   int    i,limit,y=0,counted_bars=IndicatorCounted();
    
// Plot defined timeframe on to current timeframe   
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame); 
   
   // Modified (HCY)
   limit=Bars-counted_bars+TimeFrame/Period();
//   limit=Bars-counted_bars;
   for(i=0,y=0;i<limit;i++)
   {
   if (Time[i]<TimeArray[y]) y++; 
   
 /***********************************************************   
   Add your main indicator loop below.  You can reference an existing
      indicator with its iName  or iCustom.
   Rule 1:  Add extern inputs above for all neccesary values   
   Rule 2:  Use 'TimeFrame' for the indicator timeframe
   Rule 3:  Use 'y' for the indicator's shift value
 **********************************************************/  
   
   // For proper line display (HCY)
   ExtMapBuffer1[i]=(iCustom(NULL,TimeFrame,"zlagmacd",FastEMA,SlowEMA,SignalEMA,0,y)*Multiplier);
   ExtMapBuffer2[i]=(iCustom(NULL,TimeFrame,"zlagmacd",FastEMA,SlowEMA,SignalEMA,1,y)*Multiplier);
/* Original (HCY)
   ExtMapBuffer1[i]=iCustom(NULL,TimeFrame,"zlagmacd",FastEMA,SlowEMA,SignalEMA,0,y);
   ExtMapBuffer2[i]=iCustom(NULL,TimeFrame,"zlagmacd",FastEMA,SlowEMA,SignalEMA,1,y);
*/

   }  
     
/* Disabled (HCY)
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   if (TimeFrame>Period()) {
     int PerINT=TimeFrame/Period()+1;
     datetime TimeArr[]; ArrayResize(TimeArr,PerINT);
     ArrayCopySeries(TimeArr,MODE_TIME,Symbol(),Period()); 
     for(i=0;i<PerINT+1;i++) {if (TimeArr[i]>=TimeArray[0]) {
//----
 /************************************************ by Raff   
    Refresh buffers:         buffer[i] = buffer[0];
 ********************************************************/  

/* Disabled (HCY)
   ExtMapBuffer1[i]=ExtMapBuffer1[0];
   ExtMapBuffer2[i]=ExtMapBuffer2[0];

//----
   } } }
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/

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

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---