Author: Konstantin Drozdov 2013,
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
MACDAK
//+------------------------------------------------------------------+
//|                                                       MACDAK.mq4 |
//|                                         Konstantin Drozdov 2013, |
//|                                                 drozdov.09@bk.ru |
//+------------------------------------------------------------------+
#property copyright "Konstantin Drozdov 2013,"
#property link      "drozdov.09@bk.ru"

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Green
#property indicator_color4 Green
#property indicator_color5 Crimson
#property indicator_color6 Crimson
#property indicator_color7 MediumBlue
#property indicator_color8 MediumBlue

#property  indicator_width1  2
#property  indicator_width2  2
#property  indicator_width3  1
#property  indicator_width4  1
#property  indicator_width5  1
#property  indicator_width6  1
#property  indicator_width7  1
#property  indicator_width8  1

//--- input parameters
extern int       Ma_1=13;
extern int       Ma_2=26;
extern string   _Price = "0-CLOSE,1-OPEN,2-HIGH,3-LOW,4-MEDIAN,5-TYPICAL,6-WEIGHTED";
extern int       Price_1=0;
extern int       Price_2=0;
extern string   _Metod = "0-SMA,1-EMA,2-SMMA,3-LWMA";
extern int       Metod_1=1;
extern int       Metod_2=1;
extern string   _Per = "0-òåê,1-1ìèí.,5-5ìèí.,15-15ìèí.,";
extern string   _Per1 = "60-1÷àñ,240-4ñàñà,1440-äåíü";
extern int       Per = 0;
extern string   _All = "âêë/âûêë àëåðòîâ";
extern bool      All = true;

int i,limit;
double m,m1,m2,ma,ma1,ma2,mac,mac1,mac2;
static bool al = false,flag = true;
 
//--- buffers
double BufferRed[];
double BufferBlue[];
double BufferGreen[];
double Buffer_1Green[];
double BufferCrimson[];
double Buffer_1Crimson[];
double BufferMediumBlue[];
double Buffer_1MediumBlue[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,BufferRed);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,BufferBlue);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(2,BufferGreen);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexBuffer(3,Buffer_1Green);
   SetIndexStyle(4,DRAW_HISTOGRAM);
   SetIndexBuffer(4,BufferCrimson);
   SetIndexStyle(5,DRAW_HISTOGRAM);
   SetIndexBuffer(5,Buffer_1Crimson);
   SetIndexStyle(6,DRAW_HISTOGRAM);
   SetIndexBuffer(6,BufferMediumBlue);
   SetIndexStyle(7,DRAW_HISTOGRAM);
   SetIndexBuffer(7,Buffer_1MediumBlue);
//----
   IndicatorDigits(Digits+1);
   IndicatorShortName(" MACDAC ");
   if(Metod_1<0 || Metod_1>3)Alert(" Metod äîëæåí áûòü îò 0 äî 3 ","\n"," (0-SMA,1-EMA,2-SMMA,3-LWMA) ");
   if(Metod_2<0 || Metod_2>3)Alert(" Metod äîëæåí áûòü îò 0 äî 3 ","\n"," (0-SMA,1-EMA,2-SMMA,3-LWMA) ");
   if(Price_1<0 || Price_1>6)Alert(" Price äîëæåí áûòü îò 0 äî 6 ","\n"," (0-CLOSE,1-OPEN,2-HIGH,3-LOW,4-MEDIAN,5-TYPICAL,6-WEIGHTED) ");
   if(Price_2<0 || Price_2>6)Alert(" Price äîëæåí áûòü îò 0 äî 6 ","\n"," (0-CLOSE,1-OPEN,2-HIGH,3-LOW,4-MEDIAN,5-TYPICAL,6-WEIGHTED) ");
//===================================================================$

//===================================================================$
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   int limit,i;
   int    counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

//----
   for(i=0; i<limit; i++)
   {
    m = iMA(NULL,Per,Ma_1,0,Metod_1,Price_1,i);
    m1 = iMA(NULL,Per,Ma_1,0,Metod_1,Price_1,i+1);
    m2 = iMA(NULL,Per,Ma_1,0,Metod_1,Price_1,i+2);
    ma = iMA(NULL,Per,Ma_2,0,Metod_2,Price_2,i);
    ma1 = iMA(NULL,Per,Ma_2,0,Metod_2,Price_2,i+1);
    ma2 = iMA(NULL,Per,Ma_2,0,Metod_2,Price_2,i+2);
    mac = m-ma;
    mac1 = m1-ma1;
    mac2 = m2-ma2;
    BufferRed[i] = m;
    BufferBlue[i] = ma;
    
//----
   if(m>m1 && mac1<mac && (mac1-mac)<0)
   {
   BufferGreen[i] = BufferRed[i];
   Buffer_1Green[i] = BufferBlue[i];
   }
//--------------------------------------------------------

   if(m<m1 && mac1>mac && (mac1-mac)>0)
   {
   BufferCrimson[i] = BufferRed[i];
   Buffer_1Crimson[i] = BufferBlue[i];  
   }
//-------------------------------------------------------

   if(m>ma && m>m1 && mac1>mac && (mac1-mac)>0)
   {
   BufferMediumBlue[i] = BufferRed[i];
   Buffer_1MediumBlue[i] = BufferBlue[i];
   }
//-------------------------------------------------------

   if(m<ma && m<m1 && mac1<mac && (mac1-mac)<0)
   {
   BufferMediumBlue[i] = BufferRed[i];
   Buffer_1MediumBlue[i] = BufferBlue[i];
   }
//=====================================================$
   }
        if(All==true){
          if(NewBar()==true){
     al = false;
     flag = true;
     if(!al){
       string text = "";
       for(i=0; i<limit; i++){
         if(m1<ma1 && m>ma && mac1<0 && mac>0)text = "Ñìåíà òðåíäà.Òðåíä ââåðõ!!!";
         if(m1>ma1 && m<ma && mac1>=0 && mac<=0)text = "Ñìåíà òðåíäà.Òðåíä âíèç!!!";
         if(m2>m1 && m1<m && mac1<=mac)text = "ÏÎÊÓÏÀÅÌ!!!";
         if(m2<m1 && m1>m && mac1>=mac)text = "ÏÐÎÄÀ¨Ì!!!";
         if(m>ma && m>m1 && mac2<=mac1 && mac1>mac)text = "Êîððåêöèÿ ââåðõ!!!";
         if(m<ma && m<m1 && mac2>=mac1 && mac1<mac)text = "Êîððåêöèÿ âíèç!!!";
         if(m>ma && m>m1 && mac2>=mac1 && mac1<mac)text = "Êîððåêöèÿ çàêîí÷èëàñü.ÏÎÊÓÏÀÅÌ!!!";
         if(m<ma && m<m1 && mac2<=mac1 && mac1>mac)text = "Êîððåêöèÿ çàêîí÷èëàñü.ÏÐÎÄÀ¨Ì!!!";
         if(m>ma && Ask<m && Ask>ma)text = "Öåíà â çîíå öåííîñòè.Ãîòîâèìñÿ ê ïîêóïêå!!!";
         if(m<ma && Bid>m && Bid<ma)text = "Öåíà â çîíå öåííîñòè.Ãîòîâèìñÿ ê ïðîäàæå!!!";
           if(text != "" && flag==true ){
           Alert(text + ": " + Symbol()+"; " + Period_toStr()+"; ");
           flag = false;            
           }
         }
       }
     } 
     al = true;
   }
   return(0);
  }
//+------------------------------------------------------------------+
      bool NewBar()
  {
       static datetime lastbar = 0;
       datetime curbar = iTime(NULL,0, 0);
       if(lastbar!=curbar)
       {
             lastbar=curbar;
             return (true);
       }
       return(false);
  }
//-------------------------------------------------------------------

//==========================================================================$
    string Period_toStr(){
   switch (Period()) {
      case PERIOD_M1:    return("M1" );
      case PERIOD_M5:    return("M5" );
      case PERIOD_M15:   return("M15");
      case PERIOD_M30:   return("M30");
      case PERIOD_H1:    return("H1" );
      case PERIOD_H4:    return("H4" );
      case PERIOD_D1:    return("D1" );
      case PERIOD_W1:    return("W1" );
      case PERIOD_MN1:   return("MN1");
   }
}

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