PatternMACD

Author: Copyright � 2011, cmillion@narod.ru
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
PatternMACD
//+------------------------------------------------------------------+
//|                                                  PatternMACD.mq4 |
//|                              Copyright © 2011, Khlystov Vladimir |
//|                                         http://cmillion.narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, cmillion@narod.ru"
#property link      "http://cmillion.narod.ru"

#property  indicator_separate_window
#property  indicator_buffers 6
#property  indicator_color1  Silver
#property  indicator_color2  Red
#property  indicator_color3  Red
#property  indicator_color4  Blue
#property  indicator_color5  Blue
#property  indicator_color6  Red
#property  indicator_width1  2
#property  indicator_width5  1
#property  indicator_width6  1
#property  indicator_level1 0.0015 
#property  indicator_level2 0.0030 
#property  indicator_level3 0.0045 
#property  indicator_level4 -0.0015
#property  indicator_level5 -0.0030 
#property  indicator_level6 -0.0045 
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
extern bool DrawInfo = true;
//---- indicator buffers
double     MacdBuffer[];
double     SignalBuffer[];
double     BufferUp[];
double     BufferDn[];
double     BufferBuy[];
double     BufferSell[];

double Dn0,Dn1,Dn2,Up0,Up1,Up2;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexDrawBegin(1,SignalSMA);
   IndicatorDigits(Digits+1);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,217);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,218);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,233);
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexArrow(5,234);
//---- indicator buffers mapping
   SetIndexBuffer(0,MacdBuffer);
   SetIndexBuffer(1,SignalBuffer);
   SetIndexBuffer(2,BufferUp);
   SetIndexBuffer(3,BufferDn);
   SetIndexBuffer(4,BufferBuy);
   SetIndexBuffer(5,BufferSell);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
   SetIndexLabel(0,"MACD");
   SetIndexLabel(1,"Signal");
   SetIndexLabel(4,"Buy");
   SetIndexLabel(5,"Sell");
//---- initialization done
   if (DrawInfo) ObjectsDeleteAll();
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for(int i=0; i<limit; i++)
   {
      MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
   }
   for(i=limit; i>=0; i--)
   {
      if (BufferUp[i+1]==EMPTY_VALUE && MacdBuffer[i+2] < MacdBuffer[i+1] && MacdBuffer[i+1] > MacdBuffer[i]) {BufferUp[i+1]=MacdBuffer[i+1];Up2=Up1;Up1=Up0;Up0=MacdBuffer[i+1];}
      if (BufferDn[i+1]==EMPTY_VALUE && MacdBuffer[i+2] > MacdBuffer[i+1] && MacdBuffer[i+1] < MacdBuffer[i]) {BufferDn[i+1]=MacdBuffer[i+1];Dn2=Dn1;Dn1=Dn0;Dn0=MacdBuffer[i+1];}
      if (BufferUp[i+1]!=EMPTY_VALUE)
      {
         if (Up1 > 0.0045 && Up0 > 0.0030 && Up0 < 0.0045 && Dn0>0) {BufferSell[i]=MacdBuffer[i];Text(Red,"À",i);}   //ïàòòåðí À
         if (Dn0 < -0.0030 && Dn0 > -0.0045 && Up0 < -0.0015 && Up0 > -0.0030) {BufferSell[i]=MacdBuffer[i];Text(Red,"Ñ",i);}   //ïàòòåðí C
         if (Up2 < Up1 && Up1 > Up0 && Up0 > 0.0000 && Up1 > 0.0045 && Up2 > 0.0000 && Dn0 > 0.0030 && Dn1 > 0.0030/* && Dn0 < 0.0045 && Dn1 < 0.0045*/) {BufferSell[i]=MacdBuffer[i];Text(Red,"ã & ï",i);} //ãîëîâà è ïëå÷è
         if (Up1 > Up0 && Up0 > 0.0045 && Dn0 > 0.0045) {BufferSell[i]=MacdBuffer[i];Text(Red,"äâ",i);} //äâîéíàÿ âåðøèíà
         if (Up0 > -0.0015 && Up0 < -0.0000 && Dn0 < -0.0015) {BufferSell[i]=MacdBuffer[i];Text(Red,"ð0",i);} //ðàçâîðîò ó íîëÿ
      }
      if (BufferDn[i+1]!=EMPTY_VALUE)
      {
         if (Dn1 < -0.0045 && Dn0 < -0.0030 && Dn0 > -0.0045 && Up0 < 0) {BufferBuy[i]=MacdBuffer[i];Text(Blue,"D",i);}  //ïàòòåðí D
         if (Up0 > 0.0030 && Up0 < 0.0045 && Dn0 > 0.0015 && Dn0 < 0.0030) {BufferBuy[i]=MacdBuffer[i];Text(Blue,"B",i);}  //ïàòòåðí B
         if (Dn2 > Dn1 && Dn1 < Dn0 && Dn0 < -0.0000 && Dn1 < -0.0045 && Dn2 < -0.0000 && Up0 < -0.0030 && Up1 < -0.0030/* && Up0 > -0.0045 && Up1 > -0.0045*/) {BufferBuy[i]=MacdBuffer[i];Text(Blue,"ã & ï",i);} //ãîëîâà è ïëå÷è
         if (Dn1 < Dn0 && Dn0 < -0.0045 && Up0 < -0.0045) {BufferBuy[i]=MacdBuffer[i];Text(Blue,"ää",i);} //äâîéíîå äíî
         if (Dn0 < 0.0015 && Dn0 > 0.0000 && Up0 > 0.0015) {BufferBuy[i]=MacdBuffer[i];Text(Blue,"ð0",i);} //ðàçâîðîò ó íîëÿ
      }
   }
   //Comment("Up2 ",Up2," Up1 ",Up1," Up0 ",Up0,"    Dn2 ",Dn2," Dn1 ",Dn1," Dn0 ",Dn0);
   for(i=0; i<limit; i++)
      SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);


   return(0);
  }
//+------------------------------------------------------------------+
void Text(color COLOR,string Name, int i)
{
   if (!DrawInfo) return;
   string name = Time[i];
   ObjectDelete("s"+name);                     
   ObjectCreate("s"+name,OBJ_ARROW,0,Time[i],Open[i],0,0,0,0);                     
   if (COLOR==Blue) ObjectSet   ("s"+name,OBJPROP_ARROWCODE,233);
   if (COLOR==Red) ObjectSet   ("s"+name,OBJPROP_ARROWCODE,234);
   ObjectSet   ("s"+name,OBJPROP_COLOR, COLOR);

   ObjectDelete(name);
   ObjectCreate(name, OBJ_TEXT,0,Time[i],Open[i]-High[i]+Low[i],0,0,0,0);
   ObjectSetText(name, Name,10, "Times New Roman", COLOR);
//   ObjectSet(name, OBJPROP_ANGLE
}
//-----------------------------------------------------------

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 ---