Author: Copyright 2015, Dodonov Vitaly (mql_5)
Indicators Used
Relative strength index
0 Views
0 Downloads
0 Favorites
ZigZag Rsi
//+------------------------------------------------------------------+
//|                                                   ZigZag rsi.mq4 |
//|                          Copyright 2015,  Dodonov Vitaly (mql_5) |
//|                                             "https://ellizii.ru" |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, Dodonov Vitaly (mql_5)"
#property link      "https://ellizii.ru"
#property version   "1.10"
#property description "ZigZag Rsi"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot ZZ_RSI
#property indicator_label1  "ZZ_RSI"
#property indicator_type1   DRAW_SECTION
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      period=14; // RSI Period
//--- indicator buffers
double         ZZ_RSIBuffer[];
double         r1Buffer[];
double         r2Buffer[];
double         mass[];
double         rsi[];
//--- indicator variables
int index[];
bool up,dw;
int lowest,highest,timeframe;
string symb;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   timeframe = Period();
   symb = Symbol();
//--- indicator buffers mapping
   SetIndexBuffer(0,ZZ_RSIBuffer);
   ArraySetAsSeries(r1Buffer,true);
   ArraySetAsSeries(r2Buffer,true);
   ArraySetAsSeries(mass,true);
   ArraySetAsSeries(rsi,true);
   up=false;dw=false;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {int i=0; if(prev_calculated==0)i=rates_total-2-period;else i=1;
  ArrayResize(r1Buffer,rates_total);
  ArrayResize(r2Buffer,rates_total);
  ArrayResize(mass,rates_total);
  ArrayResize(rsi,rates_total);
//---
     while(i>=0){
    rsi[i] = iRSI(symb,timeframe,period,PRICE_CLOSE,i);
    ZZ_RSIBuffer[i]=EMPTY_VALUE;
    
    
    if(up && rsi[i+1]<30 && rsi[i+2]>30){dw=true;up=false;ArrayResize(index,ArraySize(index)+1); index[ArraySize(index)-1]=i;}
    else if(dw && rsi[i+1]>70 && rsi[i+2]<70){up=true;dw=false;ArrayResize(index,ArraySize(index)+1); index[ArraySize(index)-1]=i;}
    else if(!up && !dw && rsi[i+1]<30 && rsi[i+2]>30){dw=true;ArrayResize(index,ArraySize(index)+1); index[ArraySize(index)-1]=i;}
    else if(!up && !dw && rsi[i+1]>70 && rsi[i+2]<70){up=true;ArrayResize(index,ArraySize(index)+1); index[ArraySize(index)-1]=i;}
    
    if(up && !dw){r1Buffer[i]=1;r2Buffer[i]=EMPTY_VALUE;}
    else if(dw && !up){r2Buffer[i]=1;r1Buffer[i]=EMPTY_VALUE;}
    
    if(up && ArraySize(index)>=2 && i>0){
    lowest = iLowest(symb,timeframe,MODE_LOW,index[ArraySize(index)-2]-index[ArraySize(index)-1]+1,index[ArraySize(index)-1]+1);
    ZZ_RSIBuffer[lowest]=low[lowest];}
    else if(dw && ArraySize(index)>=2 && i>0){
    highest = iHighest(symb,timeframe,MODE_HIGH,index[ArraySize(index)-2]-index[ArraySize(index)-1]+1,index[ArraySize(index)-1]+1);
    ZZ_RSIBuffer[highest]=high[highest];
    }
    
   i--;}
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

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