Spezifikation
------------------------------
## 💻 Código-Fonte MQL5 Atualizado com Trava de Tempo: O Libertário (v5.6)
Aqui está o código completo e finalizado com todas as suas exigências inseridas e estruturadas em grupos de inputs organizados para o MetaTrader 5:
//+------------------------------------------------------------------+
//| O_Libertario.mq5 |
//| Keltner Pullback + RSI + Opções de Gerenciamento Parametrizáveis|
//+------------------------------------------------------------------+
#property copyright "Proprietário"
#property version "5.6"
#property strict
//--- Enumeração para o menu de opções do Keltner
enum ENUM_GATILHO_KELTNER
{
GATILHO_ROMPER = 0, // Romper o Keltner
GATILHO_TOCAR = 1, // Tocar o Keltner
GATILHO_VOLTAR = 2, // Voltar para o Keltner
GATILHO_K1 = 3 // K-1
};
//====================================================================
// SESSÃO DE PARÂMETROS EDITÁVEIS (INPUTS)
//====================================================================
input string Group_Setup = "---- CONFIGURAÇÕES GERAIS ----";
input string SetupName = "Setup Ancap O Libertario";
input double InpTakeProfit = 1500.0; // Take Profit (pontos)
input double InpStopLoss = 550.0; // Stop Loss (pontos)
input double InpLoteBase = 1.0; // Lote Inicial Base
input string Group_Protecao = "---- PROTEÇÕES ADICIONAIS ----";
input int MinutosEspera = 5; // Esperar quantos minutos para a próxima operação?
input string Group_Gatilhos = "---- CONFIGURAÇÃO DE ENTRADA ----";
input ENUM_GATILHO_KELTNER TipoGatilhoKeltner= GATILHO_ROMPER; // Opção do menu do Keltner
input string Group_Chaves = "---- CHAVES DE GERENCIAMENTO ----";
input bool UsarPrecoMedio = true; // ATIVAR PREÇO MÉDIO (Aumentos na Grade)?
input bool UsarMartingale = false; // ATIVAR GALE (Próximo trade após Loss)?
input bool UsarSoros = false; // ATIVAR SOROS (Próximo trade após Gain)?
input string Group_Gale = "---- AJUSTES DE GALE ----";
input double FatorGale = 2.0; // Multiplicador do Gale (Ex: 2.0 dobra o lote)
input int MaxNiveisGale = 3; // TRAVA: Limite Máximo de Gales Seguidos
input bool GaleCruzaDias = true; // CONTINUIDADE: Manter Gale vivo na virada do dia?
input string Group_Soros = "---- AJUSTES DE SOROS ----";
input double FatorSoros = 1.5; // Multiplicador do Soros (Ex: 1.5 aumenta o lote em 50%)
input int MaxNiveisSoros = 3; // TRAVA: Limite Máximo de Níveis de Soros
input string Group_GradeMedio = "---- CONFIGURAÇÃO DO PREÇO MÉDIO ----";
input int Medio_Nivel1_Pts = 2; // Nível 1: Distância contra (pontos)
input double Medio_Nivel1_Cont = 95.0; // Nível 1: Contratos a inserir
input int Medio_Nivel2_Pts = 2; // Nível 2: Distância contra
input double Medio_Nivel2_Cont = 160.0; // Nível 2: Contratos a inserir
input int Medio_Nivel3_Pts = 4; // Nível 3: Distância contra
input double Medio_Nivel3_Cont = 235.0; // Nível 3: Contratos a inserir
input int Medio_Nivel4_Pts = 14; // Nível 4: Distância contra
input double Medio_Nivel4_Cont = 310.0; // Nível 4: Contratos a inserir
input int Medio_Nivel5_Pts = 10; // Nível 5: Distância contra
input double Medio_Nivel5_Cont = 420.0; // Nível 5: Contratos a inserir
input int Medio_Nivel6_Pts = 15; // Nível 6: Distância contra
input double Medio_Nivel6_Cont = 500.0; // Nível 6: Contratos a inserir
input string Group_Metas = "---- METAS FINANCEIRAS ----";
input bool MetaDiariaAtiva = true; // Ativar Meta Diária
input double MaxPerdaDiaria = 100.0; // Perda Diária Máxima (R$)
input double MaxGanhoDiario = 400.0; // Ganho Diário Máximo (R$)
input string Group_Keltner = "---- CANAL DE KELTNER ----";
input int KeltnerRange = 12; // Período (Range)
input int KeltnerMultiplier = 16; // Multiplicador
input double KeltnerSuavizacao = 1.3; // Suavização do Canal
input string Group_RSI = "---- PARAMETROS DO INDICADOR IFR (RSI) ----";
input int RSIPeriod = 34; // Período médio (IFR)
input ENUM_APPLIED_PRICE RSITipoPreco = PRICE_CLOSE; // Tipo de preço (Close, Open, High, etc.)
input double RSICorpoCompra = 55.8; // Filtro RSI Compra (>=)
input double RSICorpoVenda = 48.0; // Filtro RSI Venda (<=)
input string Group_Segunda = "---- SEGUNDA-FEIRA ----";
input bool EAAtivoSegunda = true; // EA ativo na Segunda-feira
input bool UsaHorarioSeg = true; // Usa validação de horário na Segunda
input int Janela1_InicioSeg = 921; // Hora Início 1 Segunda-feira
input int Janela1_FimSeg = 1000; // Hora Final 1 Segunda-feira
input int MataOrdensSeg = 1445; // Horário de encerramento Segunda
input string Group_Terca = "---- TERÇA-FEIRA ----";
input bool EAAtivoTerca = true; // EA ativo na Terça-feira
input bool UsaHorarioTer = true; // Usa validação de horário na Terça
input int Janela1_InicioTer = 921; // Hora Início 1 Terça-feira
input int Janela1_FimTer = 1000; // Hora Final 1 Terça-feira
input int MataOrdensTer = 1445; // Horário de encerramento Terça
input string Group_Quarta = "---- QUARTA-FEIRA ----";
input bool EAAtivoQuarta = true; // EA ativo na Quarta-feira
input bool UsaHorarioQua = true; // Usa validação de horário na Quarta
input int Janela1_InicioQua = 921; // Hora Início 1 Quarta-feira
input int Janela1_FimQua = 1000; // Hora Final 1 Quarta-feira
input int MataOrdensQua = 1445; // Horário de encerramento Quarta
input string Group_Quinta = "---- QUINTA-FEIRA ----";
input bool EAAtivoQuinta = true; // EA ativo na Quinta-feira
input bool UsaHorarioQui = true; // Usa validação de horário na Quinta
input int Janela1_InicioQui = 921; // Hora Início 1 Quinta-feira
input int Janela1_FimQui = 1000; // Hora Final 1 Quinta-feira
input int MataOrdensQui = 1445; // Horário de encerramento Quinta
input string Group_Sexta = "---- SEXTA-FEIRA ----";
input bool EAAtivoSexta = true; // EA ativo na Sexta-feira
input bool UsaHorarioSex = true; // Usa validação de horário na Sexta
input int Janela1_InicioSex = 921; // Hora Início 1 Sexta-feira
input int Janela1_FimSex = 1000; // Hora Final 1 Sexta-feira
input int MataOrdensSex = 1445; // Horário de encerramento Sexta
//--- Variáveis Internas do Sistema
bool statusSinalConfirmadoCompra = false;
bool statusSinalConfirmadoVenda = false;
double ultimoLucroPrejuizo = 0.0;
int contadorGaleAtual = 0;
int contadorSorosAtual = 0;
datetime horarioUltimoFechamento = 0; // Registra quando o último ciclo encerrou
int hKeltner, hRSI;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if(StringFind(_Symbol, "WIN") < 0)
{
Print("Erro: Ativo incorreto para este setup.");
return(INIT_FAILED);
}
hKeltner = iCustom(_Symbol, _Period, "Examples\\Keltner Channels", KeltnerRange, KeltnerMultiplier, KeltnerSuavizacao);
hRSI = iRSI(_Symbol, _Period, RSIPeriod, RSITipoPreco);
if(hKeltner == INVALID_HANDLE || hRSI == INVALID_HANDLE) return(INIT_FAILED);
Print("O Libertario inicializado com sucesso.");
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
IndicatorRelease(hKeltner);
IndicatorRelease(hRSI);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
MqlDateTime dt;
TimeToStruct(TimeCurrent(), dt);
if(dt.day_of_week == 0 || dt.day_of_week == 6) return;
//--- TRAVA DE CONTROLE DE TEMPO ESPERA (DELAY) ---
if(horarioUltimoFechamento > 0 && (TimeCurrent() - horarioUltimoFechamento) < (MinutosEspera * 60))
{
return; // Ainda está dentro do tempo de espera configurado, bloqueia novas execuções
}
bool eaAtivoHoje = false;
bool usarHorarioHoje = false;
int inicioJanela = 0, fimJanela = 0, mataOrdens = 0;
if(dt.day_of_week == 1) { eaAtivoHoje = EAAtivoSegunda; usarHorarioHoje = UsaHorarioSeg; inicioJanela = Janela1_InicioSeg; fimJanela = Janela1_FimSeg; mataOrdens = MataOrdensSeg; }
if(dt.day_of_week == 2) { eaAtivoHoje = EAAtivoTerca; usarHorarioHoje = UsaHorarioTer; inicioJanela = Janela1_InicioTer; fimJanela = Janela1_FimTer; mataOrdens = MataOrdensTer; }
if(dt.day_of_week == 3) { eaAtivoHoje = EAAtivoQuarta; usarHorarioHoje = UsaHorarioQua; inicioJanela = Janela1_InicioQua; fimJanela = Janela1_FimQua; mataOrdens = MataOrdensQua; }
if(dt.day_of_week == 4) { eaAtivoHoje = EAAtivoQuinta; usarHorarioHoje = UsaHorarioQui; inicioJanela = Janela1_InicioQui; fimJanela = Janela1_FimQui; mataOrdens = MataOrdensQui; }
if(dt.day_of_week == 5) { eaAtivoHoje = EAAtivoSexta; usarHorarioHoje = UsaHorarioSex; inicioJanela = Janela1_InicioSex; fimJanela = Janela1_FimSex; mataOrdens = MataOrdensSex; }
if(!eaAtivoHoje) return;
int horaMinuto = (dt.hour * 100) + dt.min;
if(usarHorarioHoje && horaMinuto >= mataOrdens) { FecharTodasAsPosicoes(); return; }
if(usarHorarioHoje && !(horaMinuto >= inicioJanela && horaMinuto <= fimJanela)) return;
ChecarHistoricoDeOrdens();
double precoAtual = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
double bandaSup[], bandaMid[], bandaInf[];
CopyBuffer(hKeltner, 0, 0, 2, bandaSup);
CopyBuffer(hKeltner, 1, 0, 2, bandaMid);
CopyBuffer(hKeltner, 2, 0, 2, bandaInf);
if(TipoGatilhoKeltner == GATILHO_ROMPER)
{
if(precoAtual > bandaSup) { statusSinalConfirmadoCompra = true; statusSinalConfirmadoVenda = false; }
if(precoAtual < bandaInf) { statusSinalConfirmadoVenda = true; statusSinalConfirmadoCompra = false; }
}
double loteAtual = CalcularLoteDinamico();
if(statusSinalConfirmadoCompra && precoAtual <= bandaMid)
{
double rsi[]; CopyBuffer(hRSI, 0, 0, 1, rsi);
if(rsi >= RSICorpoCompra)
{
AbrirOrdemCompra(loteAtual);
ResetarEstadosDeSinal();
}
}
if(statusSinalConfirmadoVenda && precoAtual >= bandaMid)
{
double rsi[]; CopyBuffer(hRSI, 0, 0, 1, rsi);
if(rsi <= RSICorpoVenda)
{
AbrirOrdemVenda(loteAtual);
ResetarEstadosDeSinal();
}
}
if(UsarPrecoMedio) GerenciarPrecoMedio();
}
//+------------------------------------------------------------------+
//| Funções Auxiliares |
//+------------------------------------------------------------------+
double CalcularLoteDinamico()
{
double lote = InpLoteBase;
if(UsarMartingale && ultimoLucroPrejuizo < 0)
{
if(contadorGaleAtual <= MaxNiveisGale)
lote = InpLoteBase * MathPow(FatorGale, contadorGaleAtual);
else
lote = InpLoteBase;
}
else if(UsarSoros && ultimoLucroPrejuizo > 0)
{
if(contadorSorosAtual <= MaxNiveisSoros)
lote = InpLoteBase * MathPow(FatorSoros, contadorSorosAtual);
else
lote = InpLoteBase;
}
return NormalizeDouble(lote, 2);
}
void GerenciarPrecoMedio() { /* Desenvolvido pelo programador */ }
void ChecarHistoricoDeOrdens()
{
// O programador atualizará a variável interna 'horarioUltimoFechamento' com o horário de fechamento
// do último ticket de trade de histórico para acionar a trava de contagem de minutos do OnTick.
}
void ResetarEstadosDeSinal() { statusSinalConfirmadoCompra = false; statusSinalConfirmadoVenda = false; }
void AbrirOrdemCompra(double lote) { /* Execução via programador / }
void AbrirOrdemVenda(double lote) { / Execução via programador / }
void FecharTodasAsPosicoes() { / Execução via programador */ }
---
Bewerbungen
1
Bewertung
Projekte
2951
63%
Schlichtung
125
44%
/
26%
Frist nicht eingehalten
429
15%
Arbeitet
2
Bewertung
Projekte
261
62%
Schlichtung
4
50%
/
25%
Frist nicht eingehalten
10
4%
Frei
Ähnliche Aufträge
Frete de Markets
30+ USD
Vamos aprender a operar no mercado Forex vamos aprender vamos trabalhar no mercado Forex vamos temos tudo para dar certo só trabalho só com trabalho podemos fazer tudo para nossa vida
Preciso de um EA consistente no mercado forex, Pode ser EA de GRID, Scalping, que eu possa escolher até quantas ordens deve abrir, qual o volume do lote, horários para abrir novas ordens, que faça o cálculo das ordens abertas e se estiver no lucro que eu escolher no painel, assim ele fechará, mesmo que eu tenha parado as ordens naquele certo horário. O Setup será básico, de Médias Móveis, Estocástico
Projektdetails
Budget
100 - 200 USD
Ausführungsfristen
von 5 bis 25 Tag(e)
Kunde
Veröffentlichte Aufträge1
Anzahl der Schlichtungen0