Author: Copyright � 2006, Victor Chebotariov
MACD+MA
Indicators Used
Moving average indicatorMACD Histogram
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
MACD+MA
//+------------------------------------------------------------------+
//|                                                      MACD+MA.mq4 |
//|                             Copyright © 2006, Victor Chebotariov |
//|                                      http://www.chebotariov.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Victor Chebotariov"
#property link      "http://www.chebotariov.com/"

extern int period = 14;
extern int ma_shift = 0;
extern int ma_method = 3;//0-3
extern int applied_price_ma = 0;//0-6

extern int fast_ema_period = 12;
extern int slow_ema_period = 26;
extern int applied_price_macd = 0;

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorShortName("MACD+MA");
//---- indicators
   SetIndexStyle(0,DRAW_ARROW,EMPTY,1,Blue);
   SetIndexArrow(0,159);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_ARROW,EMPTY,1,Red);
   SetIndexArrow(1,159);
   SetIndexBuffer(1,ExtMapBuffer2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int i,counted_bars=IndicatorCounted();
//----
   i=Bars-counted_bars-1;
   while(i>=0)
     {
      double MA_0   = iMA(NULL,0,period,ma_shift,ma_method,applied_price_ma,i);
      double MA_1   = iMA(NULL,0,period,ma_shift,ma_method,applied_price_ma,i+1);
      double MACD_0 = iMACD(NULL,0,fast_ema_period,slow_ema_period,9,applied_price_macd,MODE_MAIN,i);
      double MACD_1 = iMACD(NULL,0,fast_ema_period,slow_ema_period,9,applied_price_macd,MODE_MAIN,i+1);

      if(MA_0>MA_1 && MACD_0>MACD_1)
        {
         ExtMapBuffer2[i]=High[i];
        }

      if(MA_0<MA_1 && MACD_0<MACD_1)
        {
         ExtMapBuffer1[i]=Low[i];
        }

      i--;
     }
//----
   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 ---