MQL5: [2] Indicador de Médias Móveis
07/06/2017MQL5: [4] Dunnigan, setas e if
08/08/2017
1Código Criado
for(int i=periodos-1; i<rates_total; i++)
{
double media=0;
for(int j=0; j<periodos; j++)
{
media=media+close[i-j]/periodos;
}
SuperiorBuffer[i]=media*(1+desvio/100);
InferiorBuffer[i]=media*(1-desvio/100);
}
2Código Fonte Completo
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_label1 "Superior"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrBlue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 3
#property indicator_label2 "Inferior"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 3
double SuperiorBuffer[];
double InferiorBuffer[];
input int periodos=14;
input double desvio=0.1;
int OnInit()
{
SetIndexBuffer(0,SuperiorBuffer,INDICATOR_DATA);
SetIndexBuffer(1,InferiorBuffer,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++)
{
double media=0;
for(int j=0; j<periodos; j++)
{
media=media+close[i-j]/periodos;
}
SuperiorBuffer[i]=media*(1+desvio/100);
InferiorBuffer[i]=media*(1-desvio/100);
}
return(rates_total);
}