ma_2MAcross_yt_sig_alert

Author: Yuriy Tokman
ma_2MAcross_yt_sig_alert
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
ma_2MAcross_yt_sig_alert
//+------------------------------------------------------------------+
//|                                                         2xMA.mq4 |
//|                                                     Yuriy Tokman |
//|                                            yuriytokman@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman"
#property link      "yuriytokman@gmail.com"

#property indicator_chart_window

#property indicator_buffers 4
#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_color3 Yellow
#property indicator_color4 Red

extern string __1__        = "Fast MA";
extern int PeriodMA_1      = 5;
extern int ma_method_1     = 1;//0-3
extern int applied_price_1 = 6;//0-6

extern string __2__        = "Slow MA";
extern int PeriodMA_2      = 12;
extern int ma_method_2     = 1;//0-3
extern int applied_price_2 = 6;//0-6

extern string __3__ = "Another";
extern int alertBar           = 0;
extern int arrow_code_up   = 218;
extern int arrow_code_down = 217;
extern int width           = 3;


double ExtMapBuffer0[];
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];

datetime LastTime=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer0);
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer1);
   
   SetIndexStyle(2,DRAW_ARROW,EMPTY,width);
   SetIndexArrow(2,arrow_code_up);
   SetIndexBuffer(2,ExtMapBuffer2);
   SetIndexEmptyValue(2,0.0);
   
   SetIndexStyle(3,DRAW_ARROW,EMPTY,width);
   SetIndexArrow(3,arrow_code_down);
   SetIndexBuffer(3,ExtMapBuffer3);
   SetIndexEmptyValue(3,0.0);
   
   IndicatorShortName("2xMA ("+PeriodMA_1+")");
   
   SetIndexLabel(0," ISQ#481971287  ");
   SetIndexLabel(1," yuriytokman@gmail.com  ");
   SetIndexLabel(2," ISQ#481971287  ");
   SetIndexLabel(3," yuriytokman@gmail.com  ");   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   int limit;
   int counted_bars=IndicatorCounted();
   
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;

   for(int i=limit; i>=0; i--)
   {
     double MA_1_0    = iMA(NULL,0,PeriodMA_1,0,ma_method_1,applied_price_1,i+alertBar);
     double MA_1_1    = iMA(NULL,0,PeriodMA_1,0,ma_method_1,applied_price_1,i+alertBar+1);
     double MA_2_0    = iMA(NULL,0,PeriodMA_2,0,ma_method_2,applied_price_2,i+alertBar);
     double MA_2_1    = iMA(NULL,0,PeriodMA_2,0,ma_method_2,applied_price_2,i+alertBar+1);
     ExtMapBuffer0[i] = MA_1_0;
     ExtMapBuffer1[i] = MA_2_0;
     
     if (MA_1_1>=MA_2_1 && MA_1_0<MA_2_0 && Time[i]!= LastTime)
      {
       ExtMapBuffer2[i]=High[i]+5*Point;
       LastTime = Time[i];
       Alert("MAcrossDown"," TF",GetNameTF());
      }
     
     if (MA_1_1<=MA_2_1 && MA_1_0>MA_2_0 && Time[i]!= LastTime)
      {
       ExtMapBuffer3[i]=Low[i]-5*Point;
       LastTime = Time[i];
       Alert("MAcrossUp "," TF",GetNameTF());
      }        
   }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//+----------------------------------------------------------------------------+
//|  Àâòîð    : Êèì Èãîðü Â. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Âåðñèÿ   : 01.09.2005                                                     |
//|  Îïèñàíèå : Âîçâðàùàåò íàèìåíîâàíèå òàéìôðåéìà                             |
//+----------------------------------------------------------------------------+
//|  Ïàðàìåòðû:                                                                |
//|    TimeFrame - òàéìôðåéì (êîëè÷åñòâî ñåêóíä)      (0 - òåêóùèé ÒÔ)         |
//+----------------------------------------------------------------------------+
string GetNameTF(int TimeFrame=0) {
  if (TimeFrame==0) TimeFrame=Period();
  switch (TimeFrame) {
    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("MN");
    default:         return("UnknownPeriod");
  }
}

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