MaBased-ZigZag

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
MaBased-ZigZag
//+------------------------------------------------------------------+
//|                                               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 do[];
//+------------------------------------------------------------------+
//| 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,do);
   SetIndexEmptyValue(4,0.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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;
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   static int direction=0;
   static datetime lastChange=0;
   static int tmpPos=0;
   for(int i=Bars-counted_bars-1;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];
            do[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 ---