Author: amds
Indicators Used
Moving average indicatorMoving Average of Oscillator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
MACD_chart
//+---------------------------------------------------------+
//|                                         MACD ãðàôèê.mq4 |
//|                                  Copyright © 2007, amds |
//|    Çàäà÷à âñÿêîãî ðàçóìíîãî ÷åëîâåêà çàêëþ÷àåòñÿ â òîì, |
//| ÷òîáû ñìîòðåòü â ëèöî ôàêòàì, à íå â ðîæó ãàëëþöèíàöèÿì |
//+---------------------------------------------------------+
#property copyright "amds"
#property link      ""
//----
#property indicator_chart_window
#property indicator_buffers 5
//---- style
#property indicator_color1 Blue
#property indicator_color2 LightGray
#property indicator_color3 RoyalBlue
#property indicator_color4 FireBrick
#property indicator_color5 Red
#property indicator_style5 2
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
//---- parameters
extern bool showMACD   = true;
extern bool showCandle = true;
extern int  fastMA     = 12;
extern int  slowMA     = 26;
extern int  signal     =  9;
extern int  method_MA  =  1;
extern int  price_MA   =  0;
extern int  TF         =  0;
//---- buffers
double Fast[],Slow[],Signal[],Up[],Dn[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(5);
   IndicatorDigits(Digits);
   IndicatorShortName("MACD ãðàôèê");

   if(showMACD==true)
     {
      SetIndexBuffer(0,Fast);
      SetIndexStyle(0,DRAW_LINE);
      SetIndexLabel(0,"EMA1");

      SetIndexBuffer(1,Slow);
      SetIndexStyle(1,DRAW_LINE);
      SetIndexLabel(1,"EMA2");

      SetIndexBuffer(4,Signal);
      SetIndexStyle(4,DRAW_LINE);
      SetIndexLabel(4,"Signal");
      SetIndexDrawBegin(4,slowMA);
     }
   else
     {
      SetIndexBuffer(0,Fast);
      SetIndexStyle(0,DRAW_NONE);
      SetIndexLabel(0,NULL);

      SetIndexBuffer(1,Slow);
      SetIndexStyle(1,DRAW_NONE);
      SetIndexLabel(1,NULL);

      SetIndexBuffer(4,Signal);
      SetIndexStyle(4,DRAW_NONE);
      SetIndexLabel(4,NULL);
      SetIndexDrawBegin(4,slowMA);
     }

   if(showCandle==true)
     {
      SetIndexBuffer(2,Up);
      SetIndexStyle(2,DRAW_HISTOGRAM);
      SetIndexLabel(2,NULL);
      SetIndexDrawBegin(2,slowMA);

      SetIndexBuffer(3,Dn);
      SetIndexStyle(3,DRAW_HISTOGRAM);
      SetIndexLabel(3,NULL);
      SetIndexDrawBegin(3,slowMA);
     }
   else
     {
      SetIndexBuffer(2,Up);
      SetIndexStyle(2,DRAW_NONE);
      SetIndexLabel(2,NULL);
      SetIndexDrawBegin(2,slowMA);

      SetIndexBuffer(3,Dn);
      SetIndexStyle(3,DRAW_NONE);
      SetIndexLabel(3,NULL);
      SetIndexDrawBegin(3,slowMA);
     }

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| MACD ãðàôèê                                                      |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted(),limit,N;

   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   if(counted_bars==0) limit-=2;
   if(TF<=Period()) TF=Period(); N=TF/Period();

//====== ïåðâûé öèêë for îïðåäåëåíèå ñðåäíèõ ======||
   for(int i=0; i<limit; i++)
     {
      Fast[i] = iMA(NULL, 0, fastMA*N, 0, method_MA, price_MA, i);
      Slow[i] = iMA(NULL, 0, slowMA*N, 0, method_MA, price_MA, i);

      Signal[i]=Fast[i]-iOsMA(NULL,0,fastMA*N,slowMA*N,signal*N,price_MA,i);
     }

//==== âòîðîé öèêë for âèçóàëèçàöèÿ íàïðàâëåíèÿ ñèãíàëüíîé ëèíèè MACD ====|| 
   for(i=0; i<limit; i++)

      if(Signal[i]<Signal[i+1] && Signal[i]<Signal[i+2] && Signal[i+1]<Signal[i+2])
        {
         Dn[i] = High[i];
         Up[i] = Low [i];
        }

   else
   if(Signal[i]>Signal[i+1] && Signal[i]>Signal[i+2] && Signal[i+1]>Signal[i+2])
     {
      Dn[i] = Low [i];
      Up[i] = High[i];
     }

   else
     {Up[i]=EMPTY_VALUE; Dn[i]=EMPTY_VALUE;}
//----
   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 ---