398 lines
No EOL
16 KiB
MQL5
398 lines
No EOL
16 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Test_Script.mq5 |
|
|
//| Copyright 2024, Scalper HFT Systems Ltd. |
|
|
//| https://www.mql5.com/pt/users |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2024, Scalper HFT Systems Ltd."
|
|
#property link "https://www.mql5.com/pt/users"
|
|
#property version "1.00"
|
|
#property script_show_inputs
|
|
#property description "Script de Teste para Validar Configurações do HFT Scalper"
|
|
#property description "Execute este script antes de usar o EA para verificar compatibilidade"
|
|
|
|
#include "HFT_Scalper_Profiles.mqh"
|
|
#include "FBS_Broker_Config.mqh"
|
|
|
|
//--- Input parameters
|
|
input group "=== CONFIGURAÇÕES DE TESTE ==="
|
|
input bool TestBrokerCompatibility = true; // Testar compatibilidade com broker
|
|
input bool TestSymbolInfo = true; // Testar informações do símbolo
|
|
input bool TestConnectionQuality = true; // Testar qualidade da conexão
|
|
input bool TestIndicators = true; // Testar criação de indicadores
|
|
input bool TestTradingConditions = true; // Testar condições de trading
|
|
input bool TestPerformanceMetrics = true; // Testar métricas de performance
|
|
input bool ShowDetailedReport = true; // Mostrar relatório detalhado
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Script program start function |
|
|
//+------------------------------------------------------------------+
|
|
void OnStart()
|
|
{
|
|
Print("=== INICIANDO TESTE DO HFT SCALPER ===");
|
|
Print("Horário do teste: ", TimeToString(TimeCurrent()));
|
|
|
|
string final_report = "";
|
|
bool all_tests_passed = true;
|
|
|
|
// Teste 1: Compatibilidade com Broker
|
|
if(TestBrokerCompatibility)
|
|
{
|
|
Print("\n--- TESTE 1: COMPATIBILIDADE COM BROKER ---");
|
|
bool broker_test = TestBroker();
|
|
final_report += "Broker: " + (broker_test ? "✅ PASSOU" : "❌ FALHOU") + "\n";
|
|
if(!broker_test) all_tests_passed = false;
|
|
}
|
|
|
|
// Teste 2: Informações do Símbolo
|
|
if(TestSymbolInfo)
|
|
{
|
|
Print("\n--- TESTE 2: INFORMAÇÕES DO SÍMBOLO ---");
|
|
bool symbol_test = TestSymbol();
|
|
final_report += "Símbolo: " + (symbol_test ? "✅ PASSOU" : "❌ FALHOU") + "\n";
|
|
if(!symbol_test) all_tests_passed = false;
|
|
}
|
|
|
|
// Teste 3: Qualidade da Conexão
|
|
if(TestConnectionQuality)
|
|
{
|
|
Print("\n--- TESTE 3: QUALIDADE DA CONEXÃO ---");
|
|
bool connection_test = TestConnection();
|
|
final_report += "Conexão: " + (connection_test ? "✅ PASSOU" : "❌ FALHOU") + "\n";
|
|
if(!connection_test) all_tests_passed = false;
|
|
}
|
|
|
|
// Teste 4: Indicadores
|
|
if(TestIndicators)
|
|
{
|
|
Print("\n--- TESTE 4: CRIAÇÃO DE INDICADORES ---");
|
|
bool indicators_test = TestIndicatorsCreation();
|
|
final_report += "Indicadores: " + (indicators_test ? "✅ PASSOU" : "❌ FALHOU") + "\n";
|
|
if(!indicators_test) all_tests_passed = false;
|
|
}
|
|
|
|
// Teste 5: Condições de Trading
|
|
if(TestTradingConditions)
|
|
{
|
|
Print("\n--- TESTE 5: CONDIÇÕES DE TRADING ---");
|
|
bool trading_test = TestTradingEnvironment();
|
|
final_report += "Trading: " + (trading_test ? "✅ PASSOU" : "❌ FALHOU") + "\n";
|
|
if(!trading_test) all_tests_passed = false;
|
|
}
|
|
|
|
// Teste 6: Métricas de Performance
|
|
if(TestPerformanceMetrics)
|
|
{
|
|
Print("\n--- TESTE 6: MÉTRICAS DE PERFORMANCE ---");
|
|
bool performance_test = TestPerformance();
|
|
final_report += "Performance: " + (performance_test ? "✅ PASSOU" : "❌ FALHOU") + "\n";
|
|
if(!performance_test) all_tests_passed = false;
|
|
}
|
|
|
|
// Relatório Final
|
|
Print("\n=== RELATÓRIO FINAL ===");
|
|
Print(final_report);
|
|
|
|
if(all_tests_passed)
|
|
{
|
|
Print("🎉 TODOS OS TESTES PASSARAM! O EA está pronto para uso.");
|
|
Alert("✅ TESTE COMPLETO - Sistema aprovado para trading!");
|
|
}
|
|
else
|
|
{
|
|
Print("⚠️ ALGUNS TESTES FALHARAM! Verifique os problemas antes de usar o EA.");
|
|
Alert("❌ TESTE FALHOU - Corrija os problemas antes de continuar!");
|
|
}
|
|
|
|
// Relatório detalhado
|
|
if(ShowDetailedReport)
|
|
{
|
|
ShowDetailedSystemReport();
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Testar compatibilidade com broker |
|
|
//+------------------------------------------------------------------+
|
|
bool TestBroker()
|
|
{
|
|
string broker_name = AccountInfoString(ACCOUNT_COMPANY);
|
|
Print("Nome do Broker: ", broker_name);
|
|
|
|
// Verificar se é FBS
|
|
bool is_fbs = FBSValidation::ValidateBroker();
|
|
Print("É FBS: ", is_fbs ? "Sim" : "Não");
|
|
|
|
// Verificar tipo de conta
|
|
ENUM_ACCOUNT_TRADE_MODE trade_mode = (ENUM_ACCOUNT_TRADE_MODE)AccountInfoInteger(ACCOUNT_TRADE_MODE);
|
|
string mode_str = "";
|
|
switch(trade_mode)
|
|
{
|
|
case ACCOUNT_TRADE_MODE_DEMO: mode_str = "Demo"; break;
|
|
case ACCOUNT_TRADE_MODE_REAL: mode_str = "Real"; break;
|
|
case ACCOUNT_TRADE_MODE_CONTEST: mode_str = "Contest"; break;
|
|
default: mode_str = "Desconhecido"; break;
|
|
}
|
|
Print("Tipo de Conta: ", mode_str);
|
|
|
|
// Verificar se permite EAs
|
|
bool ea_allowed = TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) &&
|
|
MQLInfoInteger(MQL_TRADE_ALLOWED);
|
|
Print("EAs Permitidos: ", ea_allowed ? "Sim" : "Não");
|
|
|
|
// Verificar margem disponível
|
|
double free_margin = AccountInfoDouble(ACCOUNT_MARGIN_FREE);
|
|
Print("Margem Livre: $", free_margin);
|
|
|
|
return ea_allowed && free_margin > 100.0;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Testar informações do símbolo |
|
|
//+------------------------------------------------------------------+
|
|
bool TestSymbol()
|
|
{
|
|
string symbol = Symbol();
|
|
Print("Símbolo Atual: ", symbol);
|
|
|
|
// Verificar se é XAU/USD
|
|
bool valid_symbol = FBSValidation::ValidateSymbol();
|
|
Print("Símbolo Válido: ", valid_symbol ? "Sim" : "Não");
|
|
|
|
if(!valid_symbol)
|
|
{
|
|
Print("❌ ERRO: Este EA funciona apenas com XAU/USD!");
|
|
return false;
|
|
}
|
|
|
|
// Informações do símbolo
|
|
double point = SymbolInfoDouble(symbol, SYMBOL_POINT);
|
|
int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
|
|
double min_lot = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN);
|
|
double max_lot = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX);
|
|
double lot_step = SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP);
|
|
|
|
Print("Point: ", point);
|
|
Print("Digits: ", digits);
|
|
Print("Lote Mínimo: ", min_lot);
|
|
Print("Lote Máximo: ", max_lot);
|
|
Print("Step do Lote: ", lot_step);
|
|
|
|
// Verificar spread atual
|
|
double spread = SymbolInfoInteger(symbol, SYMBOL_SPREAD) * point;
|
|
Print("Spread Atual: ", spread, " (", SymbolInfoInteger(symbol, SYMBOL_SPREAD), " pontos)");
|
|
|
|
bool spread_ok = FBSValidation::ValidateSpread();
|
|
Print("Spread Aceitável: ", spread_ok ? "Sim" : "Não");
|
|
|
|
// Verificar horário de trading
|
|
datetime market_open = (datetime)SymbolInfoInteger(symbol, SYMBOL_TIME);
|
|
bool market_open_status = SymbolInfoInteger(symbol, SYMBOL_TRADE_MODE) == SYMBOL_TRADE_MODE_FULL;
|
|
Print("Mercado Aberto: ", market_open_status ? "Sim" : "Não");
|
|
Print("Última Cotação: ", TimeToString(market_open));
|
|
|
|
return valid_symbol && spread_ok && market_open_status;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Testar qualidade da conexão |
|
|
//+------------------------------------------------------------------+
|
|
bool TestConnection()
|
|
{
|
|
bool connected = TerminalInfoInteger(TERMINAL_CONNECTED);
|
|
double ping = TerminalInfoInteger(TERMINAL_PING_LAST);
|
|
|
|
Print("Conectado: ", connected ? "Sim" : "Não");
|
|
Print("Ping: ", ping, "ms");
|
|
|
|
string connection_status = FBSConnectionConfig::GetConnectionStatus();
|
|
Print("Status da Conexão: ", connection_status);
|
|
|
|
// Verificar estabilidade
|
|
bool stable_connection = FBSConnectionConfig::IsConnectionGood();
|
|
Print("Conexão Estável: ", stable_connection ? "Sim" : "Não");
|
|
|
|
// Testar velocidade de resposta
|
|
datetime start_time = GetMicrosecondCount();
|
|
double bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
|
|
double ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
|
|
datetime end_time = GetMicrosecondCount();
|
|
|
|
double response_time = (double)(end_time - start_time) / 1000.0; // em ms
|
|
Print("Tempo de Resposta: ", response_time, "ms");
|
|
Print("Bid: ", bid, " | Ask: ", ask);
|
|
|
|
return connected && ping < 200 && response_time < 10;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Testar criação de indicadores |
|
|
//+------------------------------------------------------------------+
|
|
bool TestIndicatorsCreation()
|
|
{
|
|
// Testar criação de EMAs
|
|
int ema_fast = iMA(Symbol(), PERIOD_M1, 5, 0, MODE_EMA, PRICE_CLOSE);
|
|
int ema_slow = iMA(Symbol(), PERIOD_M1, 10, 0, MODE_EMA, PRICE_CLOSE);
|
|
int rsi = iRSI(Symbol(), PERIOD_M1, 7, PRICE_CLOSE);
|
|
|
|
bool ema_fast_ok = (ema_fast != INVALID_HANDLE);
|
|
bool ema_slow_ok = (ema_slow != INVALID_HANDLE);
|
|
bool rsi_ok = (rsi != INVALID_HANDLE);
|
|
|
|
Print("EMA Rápida (5): ", ema_fast_ok ? "✅ OK" : "❌ ERRO");
|
|
Print("EMA Lenta (10): ", ema_slow_ok ? "✅ OK" : "❌ ERRO");
|
|
Print("RSI (7): ", rsi_ok ? "✅ OK" : "❌ ERRO");
|
|
|
|
if(ema_fast_ok && ema_slow_ok && rsi_ok)
|
|
{
|
|
// Testar leitura de dados
|
|
double ema_fast_data[];
|
|
double ema_slow_data[];
|
|
double rsi_data[];
|
|
|
|
ArraySetAsSeries(ema_fast_data, true);
|
|
ArraySetAsSeries(ema_slow_data, true);
|
|
ArraySetAsSeries(rsi_data, true);
|
|
|
|
int ema_fast_copied = CopyBuffer(ema_fast, 0, 0, 3, ema_fast_data);
|
|
int ema_slow_copied = CopyBuffer(ema_slow, 0, 0, 3, ema_slow_data);
|
|
int rsi_copied = CopyBuffer(rsi, 0, 0, 3, rsi_data);
|
|
|
|
bool data_ok = (ema_fast_copied > 0 && ema_slow_copied > 0 && rsi_copied > 0);
|
|
Print("Leitura de Dados: ", data_ok ? "✅ OK" : "❌ ERRO");
|
|
|
|
if(data_ok)
|
|
{
|
|
Print("EMA Rápida[0]: ", ema_fast_data[0]);
|
|
Print("EMA Lenta[0]: ", ema_slow_data[0]);
|
|
Print("RSI[0]: ", rsi_data[0]);
|
|
}
|
|
|
|
// Limpar handles
|
|
IndicatorRelease(ema_fast);
|
|
IndicatorRelease(ema_slow);
|
|
IndicatorRelease(rsi);
|
|
|
|
return data_ok;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Testar ambiente de trading |
|
|
//+------------------------------------------------------------------+
|
|
bool TestTradingEnvironment()
|
|
{
|
|
// Verificar timeframe
|
|
ENUM_TIMEFRAMES current_period = _Period;
|
|
bool correct_timeframe = (current_period == PERIOD_M1);
|
|
Print("Timeframe M1: ", correct_timeframe ? "✅ OK" : "❌ ERRO (atual: " + EnumToString(current_period) + ")");
|
|
|
|
// Verificar horário de trading
|
|
bool good_time = FBSTradingHours::IsGoodTradingTime();
|
|
bool bad_time = FBSTradingHours::IsBadTradingTime();
|
|
string session = FBSTradingHours::GetCurrentSession();
|
|
|
|
Print("Bom Horário: ", good_time ? "✅ Sim" : "❌ Não");
|
|
Print("Horário Ruim: ", bad_time ? "❌ Sim" : "✅ Não");
|
|
Print("Sessão Atual: ", session);
|
|
|
|
// Verificar configurações de trading
|
|
bool trading_allowed = TerminalInfoInteger(TERMINAL_TRADE_ALLOWED);
|
|
bool ea_trading = MQLInfoInteger(MQL_TRADE_ALLOWED);
|
|
|
|
Print("Trading Permitido: ", trading_allowed ? "✅ Sim" : "❌ Não");
|
|
Print("EA Trading: ", ea_trading ? "✅ Sim" : "❌ Não");
|
|
|
|
// Verificar margem
|
|
bool margin_ok = FBSMonitoring::CheckMarginLevel();
|
|
double margin_level = AccountInfoDouble(ACCOUNT_MARGIN_LEVEL);
|
|
Print("Nível de Margem: ", margin_level, "%");
|
|
Print("Margem OK: ", margin_ok ? "✅ Sim" : "❌ Não");
|
|
|
|
return correct_timeframe && trading_allowed && ea_trading && margin_ok;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Testar métricas de performance |
|
|
//+------------------------------------------------------------------+
|
|
bool TestPerformance()
|
|
{
|
|
// Informações da conta
|
|
double balance = AccountInfoDouble(ACCOUNT_BALANCE);
|
|
double equity = AccountInfoDouble(ACCOUNT_EQUITY);
|
|
double margin = AccountInfoDouble(ACCOUNT_MARGIN);
|
|
double free_margin = AccountInfoDouble(ACCOUNT_MARGIN_FREE);
|
|
|
|
Print("Saldo: $", balance);
|
|
Print("Equity: $", equity);
|
|
Print("Margem: $", margin);
|
|
Print("Margem Livre: $", free_margin);
|
|
|
|
// Verificar capital adequado
|
|
bool adequate_capital = FBSValidation::ValidateBalance(100.0);
|
|
Print("Capital Adequado: ", adequate_capital ? "✅ Sim" : "❌ Não");
|
|
|
|
// Calcular lote recomendado
|
|
double recommended_lot = MoneyManagement::CalculateLotSize(balance, 2.0);
|
|
Print("Lote Recomendado: ", recommended_lot);
|
|
|
|
// Verificar configurações de risco
|
|
bool risk_ok = (recommended_lot >= 0.01 && recommended_lot <= 1.0);
|
|
Print("Configuração de Risco: ", risk_ok ? "✅ OK" : "❌ REVISAR");
|
|
|
|
return adequate_capital && risk_ok;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Mostrar relatório detalhado do sistema |
|
|
//+------------------------------------------------------------------+
|
|
void ShowDetailedSystemReport()
|
|
{
|
|
Print("\n=== RELATÓRIO DETALHADO DO SISTEMA ===");
|
|
|
|
// Validação FBS
|
|
string fbs_report = FBSValidation::GetValidationReport();
|
|
Print(fbs_report);
|
|
|
|
// Informações do terminal
|
|
Print("\n--- INFORMAÇÕES DO TERMINAL ---");
|
|
Print("Nome: ", TerminalInfoString(TERMINAL_NAME));
|
|
Print("Empresa: ", TerminalInfoString(TERMINAL_COMPANY));
|
|
Print("Caminho: ", TerminalInfoString(TERMINAL_PATH));
|
|
Print("Build: ", TerminalInfoInteger(TERMINAL_BUILD));
|
|
Print("Conectado: ", TerminalInfoInteger(TERMINAL_CONNECTED) ? "Sim" : "Não");
|
|
Print("DLLs Permitidas: ", TerminalInfoInteger(TERMINAL_DLLS_ALLOWED) ? "Sim" : "Não");
|
|
Print("Trading Permitido: ", TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) ? "Sim" : "Não");
|
|
|
|
// Informações da conta
|
|
Print("\n--- INFORMAÇÕES DA CONTA ---");
|
|
Print("Servidor: ", AccountInfoString(ACCOUNT_SERVER));
|
|
Print("Nome: ", AccountInfoString(ACCOUNT_NAME));
|
|
Print("Número: ", AccountInfoInteger(ACCOUNT_LOGIN));
|
|
Print("Moeda: ", AccountInfoString(ACCOUNT_CURRENCY));
|
|
Print("Alavancagem: 1:", AccountInfoInteger(ACCOUNT_LEVERAGE));
|
|
|
|
// Configurações recomendadas
|
|
Print("\n--- CONFIGURAÇÕES RECOMENDADAS ---");
|
|
|
|
if(FBSValidation::ValidateBroker())
|
|
{
|
|
Print("Para FBS:");
|
|
Print("- Lote: ", FBSOptimizedConfig::LotSize());
|
|
Print("- Stop Loss: ", FBSOptimizedConfig::StopLoss(), " pips");
|
|
Print("- Take Profit: ", FBSOptimizedConfig::TakeProfit(), " pips");
|
|
Print("- Max Spread: ", FBSOptimizedConfig::MaxSpread(), " pips");
|
|
Print("- Slippage: ", FBSOptimizedConfig::Slippage(), " pontos");
|
|
}
|
|
else
|
|
{
|
|
Print("Para Broker Genérico:");
|
|
Print("- Lote: ", ModerateProfile::LotSize());
|
|
Print("- Stop Loss: ", ModerateProfile::StopLoss(), " pips");
|
|
Print("- Take Profit: ", ModerateProfile::TakeProfit(), " pips");
|
|
Print("- Max Spread: ", ModerateProfile::MaxSpread(), " pips");
|
|
}
|
|
|
|
Print("\n=== FIM DO RELATÓRIO ===");
|
|
} |