Fazendo um indicador técnico para metatrader 5 usando a teoria informacional multiversal para prever movimentações no mercado financeiro. Status do Projeto:: confidencial.............09 de agosto de 2026
.............................. Atualização 16 de agosto de 2026
Sendo assim meu algoritmo preditivo começa a ganhar vida :D
Módulo auditor
//+------------------------------------------------------------------+
//| MES_C137_Auditor.mqh |
//| MES-LAB / CÓDEX 137 |
//| Auditoria experimental preditiva |
//+------------------------------------------------------------------+
#ifndef MES_C137_AUDITOR_MQH
#define MES_C137_AUDITOR_MQH
//==================================================================
// CONFIGURAÇÃO
//==================================================================
#define MES_AUDIT_H1 1
#define MES_AUDIT_H3 3
#define MES_AUDIT_H5 5
#define MES_AUDIT_H10 10
//==================================================================
// Nome do arquivo
//==================================================================
string MES_AuditFileName()
{
return "MES_C137_AUDIT_" +
_Symbol +
"_" +
EnumToString((ENUM_TIMEFRAMES)_Period) +
".csv";
}
//==================================================================
// Cabeçalho
//==================================================================
void MES_AuditWriteHeader(int handle)
{
FileWrite(
handle,
"event",
"key",
"signal_time",
"measurement_time",
"symbol",
"timeframe",
"horizon_bars",
"s001",
"s002",
"s003",
"s004",
"ici",
"confidence",
"conflict",
"state",
"signal_close",
"future_close",
"return_pct",
"future_direction",
"max_high",
"min_low",
"mfe_pct",
"mae_pct",
"server_time",
"local_time",
"gmt_time",
"server_local_offset_hours"
);
}
//==================================================================
// Teste se chave já existe
//==================================================================
bool MES_AuditKeyExists(
const string target_key
)
{
ResetLastError();
int handle = FileOpen(
MES_AuditFileName(),
FILE_READ |
FILE_CSV |
FILE_ANSI |
FILE_COMMON,
';'
);
if(handle == INVALID_HANDLE)
return false;
//===============================================================
// Pula cabeçalho
//===============================================================
for(int i = 0; i < 28; i++)
{
if(FileIsEnding(handle))
{
FileClose(handle);
return false;
}
FileReadString(handle);
}
//===============================================================
// Pesquisa
//
// Ordem:
//
// event
// key
// ...
//===============================================================
while(!FileIsEnding(handle))
{
string event_name =
FileReadString(handle);
if(event_name == "")
break;
string key =
FileReadString(handle);
// Restante da linha
for(int i = 0; i < 26; i++)
{
if(FileIsEnding(handle))
break;
FileReadString(handle);
}
if(key == target_key)
{
FileClose(handle);
return true;
}
}
FileClose(handle);
return false;
}
//==================================================================
// Abre arquivo
//==================================================================
int MES_AuditOpen()
{
ResetLastError();
int handle = FileOpen(
MES_AuditFileName(),
FILE_READ |
FILE_WRITE |
FILE_CSV |
FILE_ANSI |
FILE_COMMON,
';'
);
if(handle == INVALID_HANDLE)
{
Print(
"[MES_AUDITOR] ERRO ao abrir arquivo. Erro=",
GetLastError()
);
return INVALID_HANDLE;
}
if(FileSize(handle) == 0)
{
MES_AuditWriteHeader(handle);
FileFlush(handle);
}
FileSeek(handle, 0, SEEK_END);
return handle;
}
//==================================================================
// Auditoria de tempo
//==================================================================
void MES_AuditGetTimes(
datetime &server_time,
datetime &local_time,
datetime &gmt_time,
double &offset_hours
)
{
server_time = TimeTradeServer();
if(server_time <= 0)
server_time = TimeCurrent();
local_time = TimeLocal();
gmt_time = TimeGMT();
offset_hours =
(double)(local_time - gmt_time) /
3600.0;
}
//==================================================================
// Registro de sinal
//
// IMPORTANTE:
//
// Esta função registra SOMENTE a informação disponível no
// momento do sinal.
//==================================================================
bool MES_AuditSignal(
const datetime signal_time,
const string symbol,
const ENUM_TIMEFRAMES timeframe,
const MES_State &state,
const double signal_close
)
{
string key =
"SIGNAL|" +
IntegerToString((long)signal_time);
if(MES_AuditKeyExists(key))
return true;
int handle = MES_AuditOpen();
if(handle == INVALID_HANDLE)
return false;
datetime server_time;
datetime local_time;
datetime gmt_time;
double offset_hours;
MES_AuditGetTimes(
server_time,
local_time,
gmt_time,
offset_hours
);
FileWrite(
handle,
"SIGNAL",
key,
TimeToString(
signal_time,
TIME_DATE | TIME_SECONDS
),
TimeToString(
server_time,
TIME_DATE | TIME_SECONDS
),
symbol,
EnumToString(timeframe),
0,
DoubleToString(state.s001, 8),
DoubleToString(state.s002, 8),
DoubleToString(state.s003, 8),
DoubleToString(state.s004, 8),
DoubleToString(state.ici, 8),
DoubleToString(state.confidence, 8),
state.conflict ? "1" : "0",
state.market_state,
DoubleToString(signal_close, 8),
"",
"",
"",
"",
"",
"",
"",
"",
TimeToString(
server_time,
TIME_DATE | TIME_SECONDS
),
TimeToString(
local_time,
TIME_DATE | TIME_SECONDS
),
TimeToString(
gmt_time,
TIME_DATE | TIME_SECONDS
),
DoubleToString(
offset_hours,
2
)
);
FileFlush(handle);
FileClose(handle);
return true;
}
//==================================================================
// Registra resultado futuro
//
// signal_index:
//
// h=1 -> index 2
// h=3 -> index 4
// h=5 -> index 6
// h=10 -> index 11
//
// A comparação é feita contra a última barra fechada: index 1.
//
// Portanto NÃO usamos a barra atual 0.
//==================================================================
bool MES_AuditOutcome(
const int horizon_bars,
const datetime signal_time,
const string symbol,
const ENUM_TIMEFRAMES timeframe,
const double signal_s001,
const double signal_s002,
const double signal_s003,
const double signal_s004,
const double signal_ici,
const double signal_confidence,
const bool signal_conflict,
const string signal_state,
const double &high[],
const double &low[],
const double &close[],
const datetime measurement_time
)
{
if(horizon_bars < 1)
return false;
//===============================================================
// Para H candles precisamos do índice H+1
//
// Ex:
//
// H1 -> índice 2
// H3 -> índice 4
// H5 -> índice 6
// H10 -> índice 11
//===============================================================
int signal_index =
horizon_bars + 1;
if(signal_index >= ArraySize(close))
return false;
//===============================================================
// Preço do momento do sinal
//===============================================================
double signal_close =
close[signal_index];
//===============================================================
// Última barra FECHADA
//
// index 1
//===============================================================
double future_close =
close[1];
if(signal_close == 0.0)
return false;
//===============================================================
// Retorno simples
//===============================================================
double return_pct =
(
future_close -
signal_close
) /
signal_close;
//===============================================================
// Direção futura
//===============================================================
string future_direction = "FLAT";
if(future_close > signal_close)
future_direction = "UP";
else
if(future_close < signal_close)
future_direction = "DOWN";
//===============================================================
// Máxima e mínima durante o horizonte
//===============================================================
double max_high =
high[1];
double min_low =
low[1];
for(
int i = 1;
i < signal_index;
i++
)
{
if(high[i] > max_high)
max_high = high[i];
if(low[i] < min_low)
min_low = low[i];
}
//===============================================================
// MFE
//
// Maximum Favorable Excursion
//
// Aqui é calculado em relação ao preço do sinal.
//===============================================================
double mfe_pct =
(
max_high -
signal_close
) /
signal_close;
//===============================================================
// MAE
//
// Maximum Adverse Excursion
//
//===============================================================
double mae_pct =
(
min_low -
signal_close
) /
signal_close;
//===============================================================
// Chave única
//===============================================================
string key =
"OUTCOME|" +
IntegerToString((long)signal_time) +
"|H" +
IntegerToString(horizon_bars);
if(MES_AuditKeyExists(key))
return true;
//===============================================================
// Abre arquivo
//===============================================================
int handle =
MES_AuditOpen();
if(handle == INVALID_HANDLE)
return false;
datetime server_time;
datetime local_time;
datetime gmt_time;
double offset_hours;
MES_AuditGetTimes(
server_time,
local_time,
gmt_time,
offset_hours
);
//===============================================================
// Escreve resultado
//===============================================================
FileWrite(
handle,
"OUTCOME",
key,
TimeToString(
signal_time,
TIME_DATE | TIME_SECONDS
),
TimeToString(
measurement_time,
TIME_DATE | TIME_SECONDS
),
symbol,
EnumToString(timeframe),
horizon_bars,
DoubleToString(signal_s001, 8),
DoubleToString(signal_s002, 8),
DoubleToString(signal_s003, 8),
DoubleToString(signal_s004, 8),
DoubleToString(signal_ici, 8),
DoubleToString(signal_confidence, 8),
signal_conflict ? "1" : "0",
signal_state,
DoubleToString(
signal_close,
8
),
DoubleToString(
future_close,
8
),
DoubleToString(
return_pct * 100.0,
8
),
future_direction,
DoubleToString(
max_high,
8
),
DoubleToString(
min_low,
8
),
DoubleToString(
mfe_pct * 100.0,
8
),
DoubleToString(
mae_pct * 100.0,
8
),
TimeToString(
server_time,
TIME_DATE | TIME_SECONDS
),
TimeToString(
local_time,
TIME_DATE | TIME_SECONDS
),
TimeToString(
gmt_time,
TIME_DATE | TIME_SECONDS
),
DoubleToString(
offset_hours,
2
)
);
FileFlush(handle);
FileClose(handle);
return true;
}
//==================================================================
// Executa auditoria completa
//
// Esta é a função que vamos chamar no C137.
//
// closed_bar = 1
//==================================================================
void MES_AuditProcess(
const datetime &time[],
const double &high[],
const double &low[],
const double &close[],
const MES_State &closed_state,
const string symbol,
const ENUM_TIMEFRAMES timeframe
)
{
ArraySetAsSeries(
time,
true
);
ArraySetAsSeries(
high,
true
);
ArraySetAsSeries(
low,
true
);
ArraySetAsSeries(
close,
true
);
int total =
ArraySize(close);
if(total < 12)
return;
//===============================================================
// Barra 1 = último candle fechado
//===============================================================
const int closed_bar = 1;
//===============================================================
// REGISTRA O SINAL
//===============================================================
MES_AuditSignal(
time[closed_bar],
symbol,
timeframe,
closed_state,
close[closed_bar]
);
//===============================================================
// RESULTADOS MADUROS
//
// H1
//===============================================================
if(total > 2)
{
MES_AuditOutcome(
MES_AUDIT_H1,
time[2],
symbol,
timeframe,
closed_state.s001,
closed_state.s002,
closed_state.s003,
closed_state.s004,
closed_state.ici,
closed_state.confidence,
closed_state.conflict,
closed_state.market_state,
high,
low,
close,
time[closed_bar]
);
}
//===============================================================
// H3
//===============================================================
if(total > 4)
{
MES_AuditOutcome(
MES_AUDIT_H3,
time[4],
symbol,
timeframe,
closed_state.s001,
closed_state.s002,
closed_state.s003,
closed_state.s004,
closed_state.ici,
closed_state.confidence,
closed_state.conflict,
closed_state.market_state,
high,
low,
close,
time[closed_bar]
);
}
//===============================================================
// H5
//===============================================================
if(total > 6)
{
MES_AuditOutcome(
MES_AUDIT_H5,
time[6],
symbol,
timeframe,
closed_state.s001,
closed_state.s002,
closed_state.s003,
closed_state.s004,
closed_state.ici,
closed_state.confidence,
closed_state.conflict,
closed_state.market_state,
high,
low,
close,
time[closed_bar]
);
}
//===============================================================
// H10
//===============================================================
if(total > 11)
{
MES_AuditOutcome(
MES_AUDIT_H10,
time[11],
symbol,
timeframe,
closed_state.s001,
closed_state.s002,
closed_state.s003,
closed_state.s004,
closed_state.ici,
closed_state.confidence,
closed_state.conflict,
closed_state.market_state,
high,
low,
close,
time[closed_bar]
);
}
}
#endif // MES_C137_AUDITOR_MQH
Comentários
Postar um comentário