Primeira versão oficial do indicador Frequência Z-Score Institucional. Recursos: - Cálculo estatístico via Z-Score - Detecção de sobrecompra e sobrevenda - Estrutura institucional para reversão à média - Compatível com Forex, índices, ações e criptos - Visual moderno otimizado para MetaTrader 5
174 lines
No EOL
6.2 KiB
MQL5
174 lines
No EOL
6.2 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Frequência Z-Score Institucional - MT5 |
|
|
//| Diego Vinicius Righetti Sá |
|
|
//| https://frequenciadomercado.com.br |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Diego Vinicius Righetti Sá | Frequência do Mercado"
|
|
#property link "https://frequenciadomercado.com.br"
|
|
#property version "2.00"
|
|
#property strict
|
|
|
|
#property description "Frequência do Mercado - Institutional Z-Score"
|
|
|
|
//-------------------------------------------------------------------
|
|
// CONFIGURAÇÃO DO INDICADOR
|
|
//-------------------------------------------------------------------
|
|
#property indicator_separate_window
|
|
#property indicator_buffers 4
|
|
#property indicator_plots 4
|
|
|
|
//-------------------------------------------------------------------
|
|
// PLOT 1 - ZSCORE
|
|
//-------------------------------------------------------------------
|
|
#property indicator_label1 "FDM Z-Score"
|
|
#property indicator_type1 DRAW_LINE
|
|
#property indicator_color1 C'0,180,255'
|
|
#property indicator_width1 3
|
|
|
|
//-------------------------------------------------------------------
|
|
// PLOT 2 - OVERBOUGHT
|
|
//-------------------------------------------------------------------
|
|
#property indicator_label2 "Upper"
|
|
#property indicator_type2 DRAW_LINE
|
|
#property indicator_color2 C'255,80,80'
|
|
#property indicator_style2 STYLE_DASH
|
|
#property indicator_width2 1
|
|
|
|
//-------------------------------------------------------------------
|
|
// PLOT 3 - ZERO
|
|
//-------------------------------------------------------------------
|
|
#property indicator_label3 "Zero"
|
|
#property indicator_type3 DRAW_LINE
|
|
#property indicator_color3 clrDimGray
|
|
#property indicator_style3 STYLE_DOT
|
|
#property indicator_width3 1
|
|
|
|
//-------------------------------------------------------------------
|
|
// PLOT 4 - OVERSOLD
|
|
//-------------------------------------------------------------------
|
|
#property indicator_label4 "Lower"
|
|
#property indicator_type4 DRAW_LINE
|
|
#property indicator_color4 C'0,255,140'
|
|
#property indicator_style4 STYLE_DASH
|
|
#property indicator_width4 1
|
|
|
|
//-------------------------------------------------------------------
|
|
// INPUTS
|
|
//-------------------------------------------------------------------
|
|
input int Periodo = 100;
|
|
input double UpperLevel = 2.5;
|
|
input double LowerLevel = -2.5;
|
|
|
|
//-------------------------------------------------------------------
|
|
// BUFFERS
|
|
//-------------------------------------------------------------------
|
|
double ZBuffer[];
|
|
double UpperBuffer[];
|
|
double ZeroBuffer[];
|
|
double LowerBuffer[];
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| INIT |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
//----------------------------------------------------------------
|
|
// BUFFERS
|
|
//----------------------------------------------------------------
|
|
SetIndexBuffer(0, ZBuffer, INDICATOR_DATA);
|
|
SetIndexBuffer(1, UpperBuffer, INDICATOR_DATA);
|
|
SetIndexBuffer(2, ZeroBuffer, INDICATOR_DATA);
|
|
SetIndexBuffer(3, LowerBuffer, INDICATOR_DATA);
|
|
|
|
//----------------------------------------------------------------
|
|
// NOME
|
|
//----------------------------------------------------------------
|
|
IndicatorSetString(
|
|
INDICATOR_SHORTNAME,
|
|
"Frequência Z-Score Institucional"
|
|
);
|
|
|
|
Print("=======================================");
|
|
Print("Frequência Z-Score Institucional");
|
|
Print("Frequência do Mercado");
|
|
Print("=======================================");
|
|
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| CALCULAR |
|
|
//+------------------------------------------------------------------+
|
|
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[]
|
|
)
|
|
{
|
|
//----------------------------------------------------------------
|
|
// VALIDAÇÃO
|
|
//----------------------------------------------------------------
|
|
if(rates_total < Periodo)
|
|
return(0);
|
|
|
|
//----------------------------------------------------------------
|
|
// OTIMIZAÇÃO
|
|
//----------------------------------------------------------------
|
|
int start;
|
|
|
|
if(prev_calculated == 0)
|
|
start = Periodo;
|
|
else
|
|
start = prev_calculated - 1;
|
|
|
|
//----------------------------------------------------------------
|
|
// LOOP
|
|
//----------------------------------------------------------------
|
|
for(int i = start; i < rates_total; i++)
|
|
{
|
|
double soma = 0.0;
|
|
|
|
//-------------------------------------------------------------
|
|
// MÉDIA
|
|
//-------------------------------------------------------------
|
|
for(int j = 0; j < Periodo; j++)
|
|
soma += close[i - j];
|
|
|
|
double media = soma / Periodo;
|
|
|
|
//-------------------------------------------------------------
|
|
// DESVIO PADRÃO
|
|
//-------------------------------------------------------------
|
|
double soma2 = 0.0;
|
|
|
|
for(int j = 0; j < Periodo; j++)
|
|
soma2 += MathPow(close[i - j] - media, 2);
|
|
|
|
double desvio = MathSqrt(soma2 / Periodo);
|
|
|
|
//-------------------------------------------------------------
|
|
// ZSCORE
|
|
//-------------------------------------------------------------
|
|
if(desvio != 0)
|
|
ZBuffer[i] = (close[i] - media) / desvio;
|
|
else
|
|
ZBuffer[i] = 0;
|
|
|
|
//-------------------------------------------------------------
|
|
// LINHAS
|
|
//-------------------------------------------------------------
|
|
UpperBuffer[i] = UpperLevel;
|
|
ZeroBuffer[i] = 0;
|
|
LowerBuffer[i] = LowerLevel;
|
|
}
|
|
|
|
return(rates_total);
|
|
}
|
|
//+------------------------------------------------------------------+ |