MQL5: [4] Dunnigan, setas e if
08/08/2017MQL5: [6] Acessando dados de outros Indicadores
09/11/2017
1Arrow
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_label1 "Dunnigan"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrGold
#property indicator_width1 1
double DunniganBuffer[];
int OnInit()
{
SetIndexBuffer(0,DunniganBuffer,INDICATOR_DATA);
PlotIndexSetInteger(0,PLOT_ARROW,74);
return(INIT_SUCCEEDED);
}
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[])
{
for(int i=1; i<rates_total;i++)
{
if(low[i]<low[i-1] && high[i]<high[i-1])
{
DunniganBuffer[i]=high[i];
}
else if(low[i]>low[i-1] && high[i]>high[i-1])
{
DunniganBuffer[i]=low[i];
}
else
{
DunniganBuffer[i]=0;
}
}
return(rates_total);
}
2Color Arrow
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_label1 "Dunnigan"
#property indicator_type1 DRAW_COLOR_ARROW
#property indicator_color1 clrDodgerBlue,clrTomato
#property indicator_width1 3
double DunniganBuffer[];
double DunniganColors[];
int OnInit()
{
SetIndexBuffer(0,DunniganBuffer,INDICATOR_DATA);
SetIndexBuffer(1,DunniganColors,INDICATOR_COLOR_INDEX);
return(INIT_SUCCEEDED);
}
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[])
{
for(int i=1; i<rates_total;i++)
{
if(low[i]<low[i-1] && high[i]<high[i-1])
{
DunniganBuffer[i]=high[i];
DunniganColors[i]=1;
}
else if(low[i]>low[i-1] && high[i]>high[i-1])
{
DunniganBuffer[i]=low[i];
DunniganColors[i]=0;
}
else
{
DunniganBuffer[i]=0;
}
}
return(rates_total);
}
3Color Histogram
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_label1 "Corpo"
#property indicator_type1 DRAW_COLOR_HISTOGRAM
#property indicator_color1 Lime,DarkGreen,Red,Maroon
#property indicator_style1 STYLE_SOLID
#property indicator_width1 5
double CorpoBuffer[];
double CorpoColors[];
int OnInit()
{
SetIndexBuffer(0,CorpoBuffer,INDICATOR_DATA);
SetIndexBuffer(1,CorpoColors,INDICATOR_COLOR_INDEX);
return(INIT_SUCCEEDED);
}
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[])
{
for(int i=1; i<rates_total; i++)
{
CorpoBuffer[i]=close[i]-open[i];
if(CorpoBuffer[i]>0)
{
CorpoColors[i]=CorpoBuffer[i]>CorpoBuffer[i-1]? 0 : 1;
}
else
{
CorpoColors[i]=CorpoBuffer[i]<CorpoBuffer[i-1]? 2 : 3;
}
}
return(rates_total);
}
4Color Line
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_label1 "Media"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrDodgerBlue,clrTomato
#property indicator_style1 STYLE_SOLID
#property indicator_width1 3
double MediaBuffer[];
double MediaColors[];
input int Periodos=10;
int OnInit()
{
SetIndexBuffer(0,MediaBuffer,INDICATOR_DATA);
SetIndexBuffer(1,MediaColors,INDICATOR_COLOR_INDEX);
return(INIT_SUCCEEDED);
}
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[])
{
for(int i=Periodos-1; i<rates_total; i++)
{
MediaBuffer[i]=0;
for(int j=0; j<Periodos; j++)
{
MediaBuffer[i]=MediaBuffer[i]+close[i-j]/Periodos;
}
MediaColors[i] = MediaBuffer[i] > MediaBuffer[i-1] ? 0 : 1;
}
return(rates_total);
}
5Color Section
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_label1 "ZigZag"
#property indicator_type1 DRAW_COLOR_SECTION
#property indicator_color1 clrDodgerBlue,clrTomato
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
double ZigZagBuffer[];
double ZigZagColors[];
int OnInit()
{
SetIndexBuffer(0,ZigZagBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ZigZagColors,INDICATOR_COLOR_INDEX);
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
return(INIT_SUCCEEDED);
}
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[])
{
for(int i=2; i<rates_total-2;i++)
{
if(high[i]>high[i-2] && high[i]>high[i-1] && high[i]>=high[i+1] && high[i]>=high[i+2])
{
ZigZagBuffer[i]=high[i];
ZigZagColors[i]=0;
}
else if(low[i]<low[i-2] && low[i]<low[i-1] && low[i]<=low[i+1] && low[i]<=low[i+2])
{
ZigZagBuffer[i]=low[i];
ZigZagColors[i]=1;
}
else
{
ZigZagBuffer[i]=0;
}
}
return(rates_total);
}
6Histogram
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_label1 "Corpo"
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 clrTomato
#property indicator_style1 STYLE_SOLID
#property indicator_width1 6
double CorpoBuffer[];
int OnInit()
{
SetIndexBuffer(0,CorpoBuffer,INDICATOR_DATA);
return(INIT_SUCCEEDED);
}
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[])
{
for(int i=0; i<rates_total; i++)
{
CorpoBuffer[i]=close[i]-open[i];
}
return(rates_total);
}
7Line
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_label1 "Media"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrGold
#property indicator_style1 STYLE_DOT
#property indicator_width1 3
double MediaBuffer[];
input int Periodos=10;
int OnInit()
{
SetIndexBuffer(0,MediaBuffer,INDICATOR_DATA);
return(INIT_SUCCEEDED);
}
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[])
{
for(int i=Periodos-1; i<rates_total; i++)
{
MediaBuffer[i]=0;
for(int j=0; j<Periodos; j++)
{
MediaBuffer[i]=MediaBuffer[i]+close[i-j]/Periodos;
}
}
return(rates_total);
}
8None
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 0
#property indicator_label1 "Sequencia"
#property indicator_type1 DRAW_NONE
double SequenciaBuffer[];
int OnInit()
{
SetIndexBuffer(0,SequenciaBuffer,INDICATOR_DATA);
return(INIT_SUCCEEDED);
}
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[])
{
for(int i=1; i<rates_total; i++)
{
if(close[i]>open[i]) // Positivo
{
if(close[i-1]>open[i-1]) // Anterior Positivo
{
SequenciaBuffer[i]=SequenciaBuffer[i-1]+1;
}
else // Anterior Negativo
{
SequenciaBuffer[i]=1;
}
}
else if(close[i]<open[i]) // Negativo
{
if(close[i-1]<open[i-1]) // // Anterior Negativo
{
SequenciaBuffer[i]=SequenciaBuffer[i-1]-1;
}
else // Anterior Positivo
{
SequenciaBuffer[i]=-1;
}
}
else // Doji (nem positivo, nem negativo)
{
SequenciaBuffer[i]=0;
}
}
return(rates_total);
}
9Section
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_label1 "ZigZag"
#property indicator_type1 DRAW_SECTION
#property indicator_color1 clrGold
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
double ZigZagBuffer[];
int OnInit()
{
SetIndexBuffer(0,ZigZagBuffer,INDICATOR_DATA);
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
return(INIT_SUCCEEDED);
}
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[])
{
for(int i=2; i<rates_total-2;i++)
{
if(high[i]>high[i-2] && high[i]>high[i-1] && high[i]>=high[i+1] && high[i]>=high[i+2])
{
ZigZagBuffer[i]=high[i];
}
else if(low[i]<low[i-2] && low[i]<low[i-1] && low[i]<=low[i+1] && low[i]<=low[i+2])
{
ZigZagBuffer[i]=low[i];
}
else
{
ZigZagBuffer[i]=0;
}
}
return(rates_total);
}