//+------------------------------------------------------------------+ //| FBS_Broker_Config.mqh | //| 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" //+------------------------------------------------------------------+ //| Configurações Específicas para Corretora FBS | //+------------------------------------------------------------------+ //--- Informações da FBS struct FBSBrokerInfo { static string BrokerName() { return "FBS Inc"; } static string XAUUSDSymbol() { return "XAUUSD"; } // Símbolo padrão na FBS static string AlternativeSymbol() { return "GOLD"; } // Símbolo alternativo static double TypicalSpread() { return 1.5; } // Spread típico em pips static double MaxAcceptableSpread() { return 4.0; } // Spread máximo aceitável static int ServerTimezone() { return 2; } // GMT+2 (horário da FBS) static string ServerLocation() { return "Cyprus/London"; } static double MinLot() { return 0.01; } static double MaxLot() { return 100.0; } static double LotStep() { return 0.01; } static int Digits() { return 2; } // XAUUSD na FBS tem 2 decimais static double PointValue() { return 0.01; } }; //--- Configurações otimizadas para FBS struct FBSOptimizedConfig { // Parâmetros ajustados para latência e execução da FBS static double LotSize() { return 0.01; } static int StopLoss() { return 12; } // Ligeiramente maior devido ao spread static int TakeProfit() { return 18; } // Mantém ratio 1:1.5 static double MaxSpread() { return 4.0; } // Ajustado para FBS static int Slippage() { return 5; } // Slippage conservador static int Magic() { return 54321; } // Magic específico para FBS // Indicadores ajustados static int MA_Fast() { return 6; } // Ligeiramente mais lento static int MA_Slow() { return 12; } static int RSI_Period() { return 8; } static int RSI_Overbought() { return 72; } static int RSI_Oversold() { return 28; } // Gestão de risco FBS static int MaxOrders() { return 3; } static int MinBarsAfterTrade() { return 4; } static bool UseTrailingStop() { return true; } static int TrailingStop() { return 6; } static double MinPriceSpeed() { return 0.0002; } static string Description() { return "Configuração otimizada para FBS broker"; } }; //--- Horários de trading ajustados para FBS (GMT+2) struct FBSTradingHours { // Conversão para horário do servidor FBS (GMT+2) static bool IsGoodTradingTime() { MqlDateTime time_struct; TimeToStruct(TimeCurrent(), time_struct); int server_hour = time_struct.hour; // Converter para GMT+2 se necessário int fbs_hour = server_hour; // Assumindo que já está em GMT+2 // Horários ideais para FBS (horário local do servidor) // Manhã europeia: 10-14h (GMT+2) if(fbs_hour >= 10 && fbs_hour < 14) return true; // Tarde europeia/início americano: 15-19h (GMT+2) if(fbs_hour >= 15 && fbs_hour < 19) return true; // Sessão americana: 22-24h (GMT+2) if(fbs_hour >= 22 && fbs_hour < 24) return true; return false; } static bool IsBadTradingTime() { MqlDateTime time_struct; TimeToStruct(TimeCurrent(), time_struct); int fbs_hour = time_struct.hour; // Evitar horários de baixa liquidez // Madrugada: 1-7h if(fbs_hour >= 1 && fbs_hour < 7) return true; // Almoço europeu: 12-13h if(fbs_hour >= 12 && fbs_hour < 13) return true; // Final do dia: 23-1h if(fbs_hour >= 23 || fbs_hour < 1) return true; return false; } static string GetCurrentSession() { MqlDateTime time_struct; TimeToStruct(TimeCurrent(), time_struct); int fbs_hour = time_struct.hour; if(fbs_hour >= 1 && fbs_hour < 9) return "Asiática"; if(fbs_hour >= 9 && fbs_hour < 17) return "Europeia"; if(fbs_hour >= 17 && fbs_hour < 1) return "Americana"; return "Transição"; } }; //--- Configurações específicas por tipo de conta FBS struct FBSAccountTypes { // Conta Standard struct StandardAccount { static double MinLot() { return 0.01; } static double MaxSpread() { return 5.0; } static bool HasCommission() { return false; } static double RecommendedLot() { return 0.01; } static int MaxPositions() { return 200; } static string Description() { return "Conta Standard FBS - Spreads variáveis"; } }; // Conta ECN struct ECNAccount { static double MinLot() { return 0.01; } static double MaxSpread() { return 2.0; } // Spreads menores static bool HasCommission() { return true; } static double Commission() { return 6.0; } // USD por lote round-turn static double RecommendedLot() { return 0.01; } static int MaxPositions() { return 500; } static string Description() { return "Conta ECN FBS - Spreads baixos + comissão"; } }; // Conta Zero Spread struct ZeroSpreadAccount { static double MinLot() { return 0.01; } static double MaxSpread() { return 1.0; } // Spreads mínimos static bool HasCommission() { return true; } static double Commission() { return 20.0; } // USD por lote round-turn static double RecommendedLot() { return 0.01; } static int MaxPositions() { return 500; } static string Description() { return "Conta Zero Spread FBS - Spreads zero + comissão alta"; } }; }; //--- Configurações de servidor e conexão FBS struct FBSConnectionConfig { static string[] GetServerList() { string servers[] = { "FBS-Real", "FBS-Real2", "FBS-Real3", "FBS-Demo", "FBS-Demo2" }; return servers; } static int RecommendedTimeout() { return 10000; } // 10 segundos static int MaxRetries() { return 3; } static int ReconnectDelay() { return 5000; } // 5 segundos static bool IsConnectionGood() { // Verificar qualidade da conexão double ping = TerminalInfoInteger(TERMINAL_PING_LAST); bool connected = TerminalInfoInteger(TERMINAL_CONNECTED); return (connected && ping < 100); // Ping menor que 100ms } static string GetConnectionStatus() { if(!TerminalInfoInteger(TERMINAL_CONNECTED)) return "Desconectado"; double ping = TerminalInfoInteger(TERMINAL_PING_LAST); if(ping < 50) return "Excelente"; if(ping < 100) return "Boa"; if(ping < 200) return "Regular"; return "Ruim"; } }; //--- Validações específicas para FBS struct FBSValidation { static bool ValidateSymbol() { string symbol = Symbol(); return (symbol == "XAUUSD" || symbol == "GOLD" || symbol == "XAU/USD"); } static bool ValidateBroker() { string broker = AccountInfoString(ACCOUNT_COMPANY); return (StringFind(broker, "FBS") >= 0); } static bool ValidateAccountType() { ENUM_ACCOUNT_TRADE_MODE trade_mode = (ENUM_ACCOUNT_TRADE_MODE)AccountInfoInteger(ACCOUNT_TRADE_MODE); return (trade_mode == ACCOUNT_TRADE_MODE_REAL || trade_mode == ACCOUNT_TRADE_MODE_DEMO); } static bool ValidateSpread() { double spread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD) * SymbolInfoDouble(Symbol(), SYMBOL_POINT); return (spread <= FBSBrokerInfo::MaxAcceptableSpread() * FBSBrokerInfo::PointValue()); } static bool ValidateBalance(double min_balance = 100.0) { double balance = AccountInfoDouble(ACCOUNT_BALANCE); return (balance >= min_balance); } static string GetValidationReport() { string report = "=== RELATÓRIO DE VALIDAÇÃO FBS ===\n"; report += "Símbolo: " + (ValidateSymbol() ? "✅ OK" : "❌ ERRO") + "\n"; report += "Broker: " + (ValidateBroker() ? "✅ OK" : "❌ ERRO") + "\n"; report += "Tipo de Conta: " + (ValidateAccountType() ? "✅ OK" : "❌ ERRO") + "\n"; report += "Spread: " + (ValidateSpread() ? "✅ OK" : "❌ ALTO") + "\n"; report += "Saldo: " + (ValidateBalance() ? "✅ OK" : "❌ BAIXO") + "\n"; report += "Conexão: " + FBSConnectionConfig::GetConnectionStatus() + "\n"; return report; } }; //--- Configurações de monitoramento FBS struct FBSMonitoring { static void LogTradeExecution(string action, double price, double sl, double tp) { string log_msg = StringFormat( "[FBS] %s | Preço: %.2f | SL: %.2f | TP: %.2f | Spread: %.1f | Ping: %.0fms", action, price, sl, tp, SymbolInfoInteger(Symbol(), SYMBOL_SPREAD) * SymbolInfoDouble(Symbol(), SYMBOL_POINT), TerminalInfoInteger(TERMINAL_PING_LAST) ); Print(log_msg); } static void LogPerformanceMetrics() { string metrics = StringFormat( "[FBS METRICS] Saldo: %.2f | Equity: %.2f | Margin: %.2f | Free Margin: %.2f", AccountInfoDouble(ACCOUNT_BALANCE), AccountInfoDouble(ACCOUNT_EQUITY), AccountInfoDouble(ACCOUNT_MARGIN), AccountInfoDouble(ACCOUNT_MARGIN_FREE) ); Print(metrics); } static bool CheckMarginLevel() { double margin_level = AccountInfoDouble(ACCOUNT_MARGIN_LEVEL); return (margin_level > 200.0); // Nível de margem seguro } static void AlertLowMargin() { double margin_level = AccountInfoDouble(ACCOUNT_MARGIN_LEVEL); if(margin_level < 200.0 && margin_level > 0) { Alert("ATENÇÃO: Nível de margem baixo na FBS: ", margin_level, "%"); } } }; //--- Configurações de emergência para FBS struct FBSEmergencyConfig { static bool ShouldStopTrading() { // Parar trading em situações de risco if(!FBSConnectionConfig::IsConnectionGood()) return true; if(!FBSMonitoring::CheckMarginLevel()) return true; if(!FBSValidation::ValidateSpread()) return true; // Verificar se é sexta-feira após 20h (rollover weekend) MqlDateTime time_struct; TimeToStruct(TimeCurrent(), time_struct); if(time_struct.day_of_week == 5 && time_struct.hour >= 20) return true; return false; } static void ExecuteEmergencyStop() { // Fechar todas as posições abertas for(int i = PositionsTotal() - 1; i >= 0; i--) { if(PositionGetSymbol(i) == Symbol()) { ulong ticket = PositionGetInteger(POSITION_TICKET); MqlTradeRequest request = {}; MqlTradeResult result = {}; request.action = TRADE_ACTION_DEAL; request.position = ticket; request.symbol = Symbol(); request.volume = PositionGetDouble(POSITION_VOLUME); request.type = (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) ? ORDER_TYPE_SELL : ORDER_TYPE_BUY; request.price = (request.type == ORDER_TYPE_SELL) ? SymbolInfoDouble(Symbol(), SYMBOL_BID) : SymbolInfoDouble(Symbol(), SYMBOL_ASK); OrderSend(request, result); Print("Posição fechada em emergência: ", ticket); } } Alert("STOP DE EMERGÊNCIA ATIVADO - Todas as posições foram fechadas!"); } };