MaBased-ZigZag_v1

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
MaBased-ZigZag_v1
//+------------------------------------------------------------------+
//|                                               MaBased-ZigZag.mq4 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Green
#property indicator_color2 Black
#property indicator_color3 Red
#property indicator_color4 Blue
#property indicator_color5 Red
//---- buffers
double zz[];
double ma[];
double ma_fast[];
double up[];
double dn[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorDigits(Digits);
   SetIndexStyle(0,DRAW_SECTION,STYLE_SOLID,4);
   SetIndexBuffer(0,zz);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ma);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ma_fast);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,108);
   SetIndexBuffer(3,up);
   SetIndexEmptyValue(3,0.0);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,108);
   SetIndexBuffer(4,dn);
   SetIndexEmptyValue(4,0.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
extern int MaSlow_Period=14;
extern int MaSlow_Type=MODE_SMMA;
extern int MaSlow_Price=PRICE_CLOSE;
extern int MaSlow_Shift=0;
extern int MaFast_Period=3;
extern int MaFast_Type=MODE_SMMA;
extern int MaFast_Price=PRICE_CLOSE;
extern int MaFast_Shift=0;
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit--;
//----
   static int direction=0;
   static datetime lastChange=0;
   static int tmpPos=0;
   for(int i=limit;i>=0;i--)
     {
      ma[i]=iMA(Symbol(),Period(),MaSlow_Period,0,MaSlow_Type,MaSlow_Price,i+1+MaSlow_Shift);
      ma_fast[i]=iMA(Symbol(),Period(),MaFast_Period,0,MaFast_Type,MaFast_Price,i+1+MaFast_Shift);
      if(ma[i]<ma_fast[i])
        {
         if(direction!=1)
           {
            direction=1;
            tmpPos=iLowest(Symbol(),Period(),MODE_LOW,iBarShift(Symbol(),Period(),lastChange,true)-i,i);
            zz[tmpPos]=Low[tmpPos];
            up[i]=Low[tmpPos];
            lastChange=Time[tmpPos];
           }
        }
      if(ma[i]>ma_fast[i])
        {
         if(direction!=-1)
           {
            direction=-1;
            tmpPos=iHighest(Symbol(),Period(),MODE_HIGH,iBarShift(Symbol(),Period(),lastChange,true)-i,i);
            zz[tmpPos]=High[tmpPos];
            dn[i]=High[tmpPos];
            lastChange=Time[tmpPos];
           }
        }
     }
//----
   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 ---