Author: ������� ��������
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
d_MA
//+------------------------------------------------------------------+
//|                                                         d_MA.mq4 |
//|                                                 Äìèòðèé Áóðãàçëè |
//|                                                   dmitriy62@i.ua |
//+------------------------------------------------------------------+
#property copyright "Äìèòðèé Áóðãàçëè"
#property link      "dmitriy62@i.ua"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Magenta
//--- input parameters
extern int       pMA=80;
extern int       metod=1;
extern int       cena=0;

   int          expBars=0;
   int          p_ma;
//--- buffers
double bufMA[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {p_ma=pMA;
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,bufMA);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }

//+---------------------------------------------------------------+
//|Ôóíêöèÿ âîçâðàùàåò true, åñëè ïîÿâèòüñÿ íîâûé áàð, èíà÷å false |
//+---------------------------------------------------------------+
 bool isNewBar()
 {
  bool res=false;
      if(expBars!=Bars)
         {expBars=Bars;
            res=true;
         }
  return(res);
 }

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   if (isNewBar()==false) return(0);   // åñëè íå ïîÿâèëñÿ íîâûé áàð - âûõîäèì
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
   int    counted_bars=IndicatorCounted(),
          i;
   int    limit=Bars-counted_bars-1;     // Èíäåêñ ïåðâîãî íåïîñ÷èòàííîãî
   double ma1;
   double ma2; 

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+
   for(i=limit; i>=0; i--)                       // Öèêë ïî íåïîñ÷èòàííûì áàðàì 
    {ma1=iMA(NULL,0,p_ma,0,metod,cena,i+1);
     ma2=iMA(NULL,0,p_ma,0,metod,cena,i+2);
     bufMA[i]=iMA(NULL,0,p_ma,0,metod,cena,i);
       
     if(Close[i+1]>Close[i+2])
           { if( Close[i+1]-ma1 > Close[i+2]-ma2 ) {p_ma=p_ma-1; if(p_ma<2)p_ma=2;}
             else    p_ma=p_ma;
           }
     else    { p_ma=p_ma; }
     if(Close[i+1]<Close[i+2])
           { if( Close[i+1]-ma1 < Close[i+2]-ma2 ) {p_ma=p_ma-1; if(p_ma<2)p_ma=2;}
             else    p_ma=p_ma;
           }
     else    { p_ma=p_ma; }
     if( Close[i+1]>ma1 && Close[i+2]<ma2 ) p_ma=pMA;
     if( Close[i+1]<ma1 && Close[i+2]>ma2 ) p_ma=pMA;
    }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+
   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 ---