Indicators Used
Moving average indicator
Miscellaneous
It issuies visual alerts to the screenImplements a curve of type %1
0 Views
0 Downloads
0 Favorites
MA_MTF_1
//+------------------------------------------------------------------+
//|                                                       MA_MTF.mq4 |
//+------------------------------------------------------------------+
#property strict

//--- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 5
#property  indicator_color1  clrBlack
#property  indicator_color2  clrGreen
#property  indicator_color3  clrRed
#property  indicator_color4  clrLime
#property  indicator_color5  clrOrangeRed
//--- buffers
double     ExtAOBuffer[];
double     ExtUpBuffer[];
double     ExtDnBuffer[];
double     ExtUpBuffer2[];
double     ExtDnBuffer2[];
//---

enum ENUM_TF { current=0,M1=1,M5=5,M15=15,M30=30,H1=60,H4=240,D1=1440,W1=10080,MN1=43200 };

input             string _1_="___ Íàñòðîéêè Fast MA ___";
input                int Period_=8,
Shift_=0;
input     ENUM_MA_METHOD Method_MA_=MODE_EMA;
input ENUM_APPLIED_PRICE Apply_to_=PRICE_CLOSE;
input             string _2_="___ Íàñòðîéêè Slow MA ___";
input                int Period__=21,
Shift__=0;
input     ENUM_MA_METHOD Method_MA__=MODE_EMA;
input ENUM_APPLIED_PRICE Apply_to__=PRICE_CLOSE;
input             string _3_="___ Symbol ___";
input             string SYMBOL="";
input             string _4_="___ Time frame ___";
input            ENUM_TF TF=current;

string Symb;
bool Activate;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   Activate=false;

   if(SYMBOL=="")
      Symb=Symbol();
   else 
     {
      if((int)MarketInfo(SYMBOL,MODE_DIGITS)>0)
         Symb=SYMBOL;
      else 
        {
         Alert("'",SYMBOL,"'"," - ýòîò ñèìâîë óêàçàí íåêîððåêòíî èëè íå äîáàâëåí â 'Îáçîð ðûíêà'!");
         return(INIT_PARAMETERS_INCORRECT); 
        }
     }

   if(TF!=current && TF<Period()) 
     {
      IndicatorShortName("MA MTF: ÒÅÊÓÙÈÉ ÒÀÉÌ-ÔÐÅÉÌ ÁÎËÜØÅ ÓÊÀÇÀÍÍÎÃÎ!");
      return(INIT_SUCCEEDED);
     }

//--- drawing settings
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexStyle(4,DRAW_HISTOGRAM);
   IndicatorDigits(Digits+1);
   SetIndexDrawBegin(0,Period__);
   SetIndexDrawBegin(1,Period__);
   SetIndexDrawBegin(2,Period__);
   SetIndexDrawBegin(3,Period__);
   SetIndexDrawBegin(4,Period__);
//--- 5 indicator buffers mapping
   SetIndexBuffer(0,ExtAOBuffer);
   SetIndexBuffer(1,ExtUpBuffer);
   SetIndexBuffer(2,ExtDnBuffer);
   SetIndexBuffer(3,ExtUpBuffer2);
   SetIndexBuffer(4,ExtDnBuffer2);
//--- name for DataWindow and indicator subwindow label
   IndicatorShortName("MA MTF ("+Symb+", "+Get_TF()+")");
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   SetIndexLabel(3,NULL);
   SetIndexLabel(4,NULL);

   Activate=true;
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Awesome Oscillator                                               |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   if(!Activate) return(rates_total);

   int    i,shift,limit=rates_total-prev_calculated;
   double prev=0.0,current;
//--- check for rates total
   if(rates_total<=Period__)
      return(0);
//--- last counted bar will be recounted
   if(prev_calculated>0)
     {
      limit++;
      prev=ExtAOBuffer[limit];
      shift=iBarShift(Symb,0,iTime(Symb,TF,0));
      if(limit-1<shift) 
        {
         limit=shift+1;
         prev=ExtAOBuffer[limit];
        }
     }
//--- macd
   for(i=0; i<limit; i++)
      ExtAOBuffer[i]=iMA(Symb,TF,Period_,Shift_,Method_MA_,Apply_to_,iBarShift(Symb,TF,iTime(Symb,0,i)))-
                     iMA(Symb,TF,Period__,Shift__,Method_MA__,Apply_to__,iBarShift(Symb,TF,iTime(Symb,0,i)));
//--- dispatch values between 2 buffers
   int dir=0;
   for(i=limit-1; i>=0; i--)
     {
      current=ExtAOBuffer[i];

      if(current>prev && current>0.0)
         dir=1; else
      if(current<prev && current>0.0)
         dir=-1; else
      if(current>prev && current<0.0)
         dir=2; else
      if(current<prev && current<0.0)
         dir=-2; else dir=0;

      if(dir==-1)
        {
         ExtDnBuffer[i]=current;
         ExtUpBuffer[i]=0.0;
         ExtDnBuffer2[i]=0.0;
         ExtUpBuffer2[i]=0.0;
        }
      else
      if(dir==1)
        {
         ExtUpBuffer[i]=current;
         ExtDnBuffer[i]=0.0;
         ExtUpBuffer2[i]=0.0;
         ExtDnBuffer2[i]=0.0;
        }
      else
      if(dir==-2)
        {
         ExtDnBuffer[i]=0.0;
         ExtUpBuffer[i]=0.0;
         ExtDnBuffer2[i]=current;
         ExtUpBuffer2[i]=0.0;
        }
      else
      if(dir==2)
        {
         ExtUpBuffer[i]=0.0;
         ExtDnBuffer[i]=0.0;
         ExtUpBuffer2[i]=current;
         ExtDnBuffer2[i]=0.0;
        }
      else
        {
         if(i!=limit-1)
           {
            ExtUpBuffer[i]=ExtUpBuffer[i+1];
            ExtDnBuffer[i]=ExtDnBuffer[i+1];
            ExtUpBuffer2[i]=ExtUpBuffer2[i+1];
            ExtDnBuffer2[i]=ExtDnBuffer2[i+1];
           }
        }

      prev=current;
     }
//--- done
   return(rates_total);
  }
//=================================================================================================================================================//
string Get_TF() 
  {
   int tf=(int)TF;  if(tf==0) tf=Period();

   switch(tf) 
     {
      case     1: return("M1");
      case     5: return("M5");
      case    15: return("M15");
      case    30: return("M30");
      case    60: return("H1");
      case   240: return("H4");
      case  1440: return("D1");
      case 10080: return("W1");
      case 43200: return("MN1");
     } // switch
   return("");
  }
//=================================================================================================================================================//

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