Termos de Referência
Este EA eu uso na neológica preciso converter para mt5
// CINETICA_EA_1_1
// EA criado na plataforma ProfitPro
///////////////////////////////////////////////////////////////////////////
// //
//criado por AMX/MCG //
//A intenção do indicador é identificar a direção e fraquezas do //
// através do volume financeiro. //
// //
// IDENTIFICAÇÃO DAS CORES //
// VERDE ESCURO = FORÇA DE COMPRA //
// VERMELHO ESCURO = FORÇA DE VENDA //
// VERMELHO CLARO = TENDENCIA COMPRA //
// VERMELHOCLARO = TENDENCIAVENDA //
// //
///////////////////////////////////////////////////////////////////////////
const
perc = 0.65;
//PARECE NÃO FAZER DIFERENÇA NA MULTIPLICAÇÃO
Parametro
//canal
Desvio(0.5);
Periodo(100);
Dados(OPEN);
ma_tipo(3);
plotcanal (false);
//-----------------------------------------------------
Horainicio(905); //hora que inicia
HoraTerminoDeEnvioDeOndem(1740); // hora que para de enviar ordem
horaFecharTudo(1740); //hora que cancela todas as ordens
//-----------------------------------------------------
Lateralizacao_INDICE(50); // distancia da media1 para media2
Lateralizacao_DOLAR(6); // distancia da media1 para media2
//-----------------------------------------------------
MediaRapida(7); //7
MediaLonga(21); //21
PLOTAR_MEDIAS(FALSE); //PLOT2,PLOT3
//-----------------------------------------------------
DolarVolumeBaixo (30000000);
IndiceVolumeBaixo(200000000); //menor volume na barra para aceitar a entrada
//-----------------------------------------------------
OperarGap(true);
GapIndice(800); //filtro de gap
GapDolar(10);
GapHoraInicio(1030);
//-----------------------------------------------------
swingtrade(false);
plotarsetinhas(true); //plotar as setas no grafico
ColorirBarras(true);
ComoOscilador(false);
//PLOTAR_comooscilador(true);//PLOT sempre ligado
//-----------------------------------------------------
Gain(1500); // alvo da operação
stopLoss(400); //stop da operação
//-----------------------------------------------------
//REALIZACAO_PARCIAL(FALSE); // vou estudar isso ainda
// Distancia_Parcial(200);
// QT_Parcial(1);
//-----------------------------------------------------
//STOP MOVÉL POR PONTO
LigarStopMovel (true);
Acionamento(110);//O QUANTO PRECISA ANDAR PARA iniciar o stop movél
StopMovelAnda(400);//o tamanho do passo do stop movél
DistanciaOffset(1); //uma distancia pequena para ajudar no micro lucro
PLOTAR_STOP_MOVEL(true); //PLOT5,PLOT6
//-----------------------------------------------------
//STOP MOVÉL POR HILO
LigarStopHilo(FALSE); //stop movél pelo indicador hilo
Periodohilo(10);
PontosParaAtivarHilo(100);
PlotarHILO(false); //PLOT4
//-----------------------------------------------------
//Breakeven1
LigarBreakeven1(FALSE); //uma proteção depois que anda x pontos
breakeven(100);
breakevengain(200);
//-----------------------------------------------------
//Breakeven2
LigarBreakeven2(false); //uma proteção depois que anda x pontos
breakeven2(1400);
breakevengain2(200);
var
SinalC,SinalV,bPosicionado,enveC,enveV : boolean;
// canal
mm,Superior,Inferior,Resultado : Real;
//----------------------------------------
PrecoStop,DefesaBreakeven,PrecoAlvo,PrecoStopOffset : float;
bConfigurouRiscoInicial : boolean;
bTrailingStopAtivado : boolean;
//---------------------------------------------------
StopMovelAndando: boolean; // Nova variável para controlar se o stop móvel está andando
vGap : real;
t1,t2,t3,t4,t5,t6,T7 : real;
_volumeBaixo,_filtroLateralizacao : Real;
i : Inteiro;
{contagem}
AlvoSTM,StopSTM : Real; // AlvoSTM não esta usando
{Average Speed = Velocidade Média}
{distância : pontos}
amp,ampDia,d,r,m : Real;
v : Real;
{velocidade : pontos/minuto}
sumv,regiao50 : Real;
{soma}
//operacoes: integer;
Media1,Media2 : Float;
lastsinal : string;
//Martelo
SinalINV,SinalINV1,SinalINv2,SinalINC,SinalINC1 : boolean;
fechamento_anterior : real;
abertura_atual : real;
vHoraInicio : integer;
hilostop : float;
//hilo x periodos para saida
begin // vou iniciar toda a leitura
if Date <> Date[1] then
lastsinal := "";
//canal
begin
if (ma_tipo=0) then mm:=media(periodo,dados);
if (ma_tipo=1) then mm:=mediaexp(periodo,dados);
if (ma_tipo=2) then mm:=WellesSum(periodo,dados, 0)/periodo;
if (ma_tipo=3) then mm:=WAverage(dados,periodo);
if (ma_tipo=4) then mm:=mediaexp(periodo,mediaexp(periodo,dados));
if (ma_tipo=5) then mm:=mediaexp(periodo,WAverage(dados,periodo));
begin
Superior := mm + (mm * (Desvio / 100));
Inferior := mm - (mm * (Desvio / 100));
if plotcanal then
begin
plot8 (superior);
plot9 (mm);
plot10 (inferior);
end;
Resultado := ((Dados - Inferior) / (Superior - Inferior)) * 100;
// envev:=( Resultado > 100);//fora das bandas
// envec:=( Resultado < 0); //fora das bandas
envev:=( Resultado > 50);
envec:=( Resultado < 50);
end;
end;
//fim do canal
bPosicionado := hasPosition;
if (time < time[1]) and OperarGap then
begin
vHoraInicio := horainicio;
fechamento_anterior := closeD(1);
abertura_atual := openD(0);
if (MinPriceIncrement = 0.5) then
vGap := GapDolar;
if (MinPriceIncrement = 5) then
vGap := GapIndice;
if abs(fechamento_anterior - abertura_atual) > vGap then
vHoraInicio := GapHoraInicio;
end;
//se der condição de horario começamos a leitura.
if vHoraInicio <= 0 then
vHoraInicio := horainicio;
//identificamos o volume da barra
amp := volume;
r := Abs(amp);
//-----------------------------------------------------
// Calcula a diferença entre o preço de fechamento e abertura do dia
ampDia := Close - OpenD(0);
//-----------------------------------------------------
//////PLOTAGEM como oscilador
if (comooscilador) then
begin
setplottype(1,1);
//1=histograma barra
setplottype(2,0);
//0=linha
setplotwidth(2,1);
plot(volume);
end;
//identificamos as medias que vamos usar.
Media1 := mediaExp(MediaRapida,close);
Media2 := media(MediaLonga,close);
IF PLOTAR_MEDIAS THEN
BEGIN
plot2(Media1);
plot3(Media2);
END;
//-----------------------------------------------------
//USAR O HILO COMO UM STOP MOVEL
begin
hilostop := (HiloActivator(Periodohilo));
if PlotarHILO then
begin
plot4(hilostop);
end;
end;
//Verificamos o grafico e o horario.
if (graphicinterval > 1) or (swingtrade) or ((time > vHoraInicio) e (time < HoraTerminoDeEnvioDeOndem)) then
begin
//verificar se teve gap
if (MinPriceIncrement = 0.5) then //identificamos o grafico no dolar
begin
vGap := GapDolar;
_volumeBaixo := DolarVolumeBaixo;
_filtroLateralizacao := Lateralizacao_DOLAR;
if (GraphicInterval = 1) then
_volumeBaixo := _volumeBaixo * GraphicOffset
//intraday
else if (GraphicInterval = 2) and (graphicoffset = 1) then
_volumeBaixo := _volumeBaixo * 113 * perc
//113 barras de 5M diário
else if (GraphicInterval = 3) and (graphicoffset = 1) then
_volumeBaixo := _volumeBaixo * 9 * perc;
//semanal
end
else if (MinPriceIncrement = 5) then //identificamos o grafico no indice
begin
vGap := GapIndice;
_volumeBaixo := IndiceVolumeBaixo;
_filtroLateralizacao := Lateralizacao_INDICE;
if (GraphicInterval = 1) then
_volumeBaixo := _volumeBaixo * GraphicOffset
//intraday
Else if (GraphicInterval = 2) and (graphicoffset = 1) then
_volumeBaixo := _volumeBaixo * 113 * perc
//113 barras de 5M diário
else if (GraphicInterval = 3) and (graphicoffset = 1) then
_volumeBaixo := _volumeBaixo * 9 * perc;
//semanal
end;
//SE CASO DER O SINAL E VOLTAR EM 50% DA BARRA de entrada
regiao50 := (high + low) / 2;
//usar com o comando da ordem de entrada
//======================================SINAIS DE ENTRADA ========================================
//COMPRA
sinalC := ((volume >= _volumeBaixo) and (Media2 > (Media2[1])) and (Media1 > (Media1[1])) and (media1 > media2 + _filtroLateralizacao)and (enveC));
//VENDA
sinalV := ((volume >= _volumeBaixo) and (Media2 < (Media2[1])) and (Media1 < (Media1[1])) and (media1 < media2 - _filtroLateralizacao)and(enveV));
//// ======================================IDENTIFICAÇÃO GRAFICA DE PADRÕES DE FORÇA================
t1 := Abertura - fechamento;
t2 := Máxima - Mínima;
t3 := Máxima - fechamento;
t4 := fechamento - abertura;
t5 := Máxima - abertura;
t6 := abertura - minima;
t7 := Fechamento - minima;
// ======================================MARTELO BRANCO=============================================
if (t4 <> 0) e (t5 <> 0) then
//checar divizão por zero >= 0
SinalINC1 := ((SinalC) e (t4 >= 0) e ((t2 / t4) >= 2.5) e ((t2 / t5) >= 2.5));
// ======================================MARTELO BRANCO INVERTIDO===================================
if (t4 <> 0) e (t7 <> 0) then
SinalINv := ((SinalC) e (t4 >= 0) e ((t2 / t4) >= 2.5) e ((t2 / t7) >= 2.5));
// ======================================MARTELO PRETO==============================================
if (t1 <> 0) e (t3 <> 0) then
//checa divizão por zero
SinalINC := ((sinalV) e (t1 >= 0) e ((t2 / t1) >= 2.5) e ((t2 / t3) >= 2.5));
// ======================================MARTELO PRETO INVERTIDO====================================
if (t1 <> 0) e (t6 <> 0) then
SinalINv1 := ((sinalV) e (t1 >= 0) e ((t2 / t1) >= 2.5) e ((t2 / t6) >= 2.5));
//// ======================================IDENTIFICAÇÃO GRAFICA DE PADRÕES DE FORÇA================
end;
////aqui ===========================APOIS IDENTIFICAR OS PADRÕES COLOCAMOS AS CONDIÇÕES PARA A PLOTAGEM
if ((lastsinal = "") and (lastsinal[1] = "C") or (lastsinal[1] = "V")) then
lastsinal := lastsinal[1];
//=============SE plotar um sinal o outro tem que ser diferente isso garante pra não entrar todo hora
if SinalINC1 and (lastsinal <> "Vc") e plotarsetinhas then
begin
lastsinal := "Vc";
if (comooscilador) then
plottext("Vc",clAzul,2,10)
else
plottext("Vc",clAzul,2,10);
if (colorirbarras) then
paintbar(clAzul);
setplotcolor(1,clAzul);
end
//// ===========================SE SINAL (SinalINC) PLOT O MESMO SINAL "VC"
else if SinalINC and (lastsinal <> "VC") e plotarsetinhas then
begin
lastsinal := "VC";
if (comooscilador) then
plottext("VC",clAzul,2,10)
else
plottext("VC",clAzul,2,10);
if (colorirbarras) then
paintbar(clAzul);
setplotcolor(1,clAzul);
end
//// ===========================SE SINAL (SinalC) AGORA PLOT "C"
ELSE if sinalC and (lastsinal <> "C") e plotarsetinhas then
begin
lastsinal := "C";
if (comooscilador) then
plottext("C",clpreto,2,10)
else
plottext("C",clPreto,0,10);
//// ===========================APROVEITANDO O SINAL "C" VAMOS FAZER UMA COMPRA
//VERIFICAMOS SE JA EXISTE UMA POSIÇÃO DE COMPRA
if (BuyPosition = 0) and (sellposition = 0) then
begin
begin
BuyLimit(regiao50);
end;
if (BuyPosition = 0) and (sellposition = 0) then
begin
BuyLimit(high + 5);
end;
end;
if (colorirbarras) then
paintbar(clVerde);
setplotcolor(1,clVerde);
end
//---------------------VOLUME DE VENDA------------------------------------
else if SinalINV1 and (lastsinal <> "VV") e plotarsetinhas then
begin
lastsinal := "VV";
if (comooscilador) then
plottext("VV",clAzul,2,10)
else
plottext("VV",clAzul,2,10);
if (colorirbarras) then
paintbar(rgb(125,10,106));
setplotcolor(1,rgb(125,10,106));
end
else if SinalINV and (lastsinal <> "VV") e plotarsetinhas then
begin
lastsinal := "VV";
if (comooscilador) then
plottext("VV",clAzul,2,10)
else
plottext("VV",clAzul,2,10);
if (colorirbarras) then
paintbar(rgb(125,10,106));
setplotcolor(1,rgb(125,10,106));
end
ELSE if sinalv and (lastsinal <> "V") and plotarsetinhas then
//ELSE if sinalv and plotarsetinhas then
begin
lastsinal := "V";
if (comooscilador) then
plottext("V",clPreto,2,10)
// plotar a letra de venda da cor branca
else
plottext("V",clPreto,2,10);
//=======================ENVIAR UMA ORDEM DE VENDA=======================
if (sellposition = 0) and (BuyPosition = 0) then
begin
begin
SellShortLimit(regiao50);
end;
if (sellposition = 0) and (BuyPosition = 0) then
begin
SellShortLimit(low - 5);
end;
end;
if (colorirbarras) then
paintbar(clVermelho);
setplotcolor(1,clVermelho);
end;
//AGORA VAMOS IDENTIFICAR O VOLUME ABAIXO DO ESCOLHIDO
if ((volume <= _volumeBaixo) or (volume < WAverage(volume,15) / 1.5)) then
begin
plottext("",cllime,0,10);
if (colorirbarras) then
paintbar(rgb(240,237,67));
setplotcolor(1,clAmarelo);
end
else if (amp < amp[1]) e (close >= close[1]) then
begin
if (colorirbarras) then
paintbar(rgb(132,245,132));
//(212,245,181));
setplotcolor(1,rgb(132,245,132));
end
else if (amp < amp[1]) e (close <= close[1]) then
begin
if (colorirbarras) then
paintbar(rgb(245,116,108));
setplotcolor(1,rgb(245,116,108));
end;
//DAQUI PARA BAIXO VAMOS VERIFICAR OS RISCO DA OPERAÇÃO COMO ENTRADAS E SAIDAS.
////////////////////////////////////////////////////////////////////////////////////////////////////
// Verifica se há uma posição de compra aberta
if isBought then
begin
// Verifica se o risco inicial já foi configurado
if not bConfigurouRiscoInicial then
begin
// Calcula o preço do stop loss para a posição comprada
PrecoStop := BuyPrice - stopLoss;
// Calcula o preço-alvo para a posição comprada
PrecoAlvo := BuyPrice + Gain;
// Calcula o preço do stop offset (com uma pequena distância adicional)
PrecoStopOffset := PrecoStop - DistanciaOffset;
// Marca que o risco inicial foi configurado
bConfigurouRiscoInicial := true;
end;
// Verifica se o trailing stop está habilitado
if LigarStopMovel then
begin
// Ativa o trailing stop se o preço atingir a distância de acionamento a partir do preço de compra
if ((Close >= (BuyPrice + Acionamento)) or (Acionamento = 0)) and ( not bTrailingStopAtivado) then
bTrailingStopAtivado := true;
// Atualiza o preço do stop móvel se o preço se mover a favor da posição
if ((Close - StopMovelAnda) >= PrecoStop) and (bTrailingStopAtivado) then
begin
PrecoStop := Close - StopMovelAnda;
// Atualiza o preço do stop offset após o ajuste do stop móvel
PrecoStopOffset := PrecoStop - DistanciaOffset;
// Indica visualmente a ativação do trailing stop (pintando a barra)
begin
paintbar(clPreto);
end;
end;
end;
// Fecha a posição de compra com base no stop móvel e no preço-alvo
SellToCoverStop(PrecoStop,PrecoStopOffset);
SellToCoverLimit(PrecoAlvo);
end;
//*********************************************************************
// REALIZAÇÃO PARCIAL // vou estudar isso ainda
// IF (isBought) AND (BuyPosition > 1) AND REALIZACAO_PARCIAL THEN
// BEGIN
// SellToCoverLimit(BuyPrice + Distancia_Parcial,QT_Parcial);
//pensar no futuro colocar para verificar se a posição
// end;
//*********************************************************************
//fecha GAIN na virada do HILO
if (isBought) and ((close > (BuyPrice + PontosParaAtivarHilo)) and (close < hilostop) and LigarStopHilo) then
BEGIN
closeposition;
end;
//*********************************************************************
// PROTEGER NO BreakEven 1 para operações de compra
if (isBought) and (close[0] >= (Buyprice + breakeven)) and LigarBreakeven1 then
begin
DefesaBreakeven := (Buyprice + breakevengain);
//SellShortStop(DefesaBreakeven);
SellToCoverStop(DefesaBreakeven,DefesaBreakeven);
end;
//*********************************************************************
// PROTEGER NO BreakEven 2
if (isBought) and (close[0] >= (Buyprice + breakeven2)) and LigarBreakeven2 then
begin
DefesaBreakeven := (Buyprice + breakevengain2);
// SellShortStop(DefesaBreakeven);
SellToCoverStop(DefesaBreakeven,DefesaBreakeven);
end;
//*********************************************************************
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
// se estiver vendido veja:===========================================================================
// Verifica se há uma posição vendida aberta
if isSold then
begin
// Verifica se o risco inicial já foi configurado
if not bConfigurouRiscoInicial then
begin
// Calcula o preço do stop loss para a posição vendida
PrecoStop := SellPrice + stopLoss;
// Preço do stop loss é adicionado ao preço de venda
// Calcula o preço-alvo para a posição vendida
PrecoAlvo := SellPrice - Gain;
// Preço-alvo é subtraído do preço de venda
// Calcula o preço do stop offset (com uma pequena distância adicional)
PrecoStopOffset := PrecoStop + DistanciaOffset;
// Stop offset é calculado adicionando a distância
// Marca que o risco inicial foi configurado
bConfigurouRiscoInicial := true;
end;
// Verifica se o trailing stop está habilitado
if LigarStopMovel then
begin
// Ativa o trailing stop se o preço atingir a distância de acionamento a partir do preço de venda
if ((Close <= (SellPrice - Acionamento)) or (Acionamento = 0)) and ( not bTrailingStopAtivado) then
bTrailingStopAtivado := true;
// Atualiza o preço do stop móvel se o preço se mover a favor da posição
if ((Close + StopMovelAnda) <= PrecoStop) and (bTrailingStopAtivado) then
begin
PrecoStop := Close + StopMovelAnda;
// Atualiza o preço do stop offset após o ajuste do stop móvel
PrecoStopOffset := PrecoStop + DistanciaOffset;
// Indica visualmente a ativação do trailing stop (pintando a barra)
begin
paintbar(clPreto);
end;
end;
end;
// Fecha a posição vendida com base no stop móvel e no preço-alvo
BuyToCoverStop(PrecoStop,PrecoStopOffset);
// Fecha a venda com o stop loss
BuyToCoverLimit(PrecoAlvo);
// Fecha a venda com o preço-alvo
end;
//*********************************************************************
{ //REALIZAÇÃO PARCIAL // vou estudar isso ainda
IF (isSold) AND REALIZACAO_PARCIAL THEN
BEGIN
BuyToCoverLimit(sellprice - Distancia_Parcial, QT_Parcial);
END; }
//***************************************************************
//fecha GAIN na virada do HILO
begin
if (isSold) AND ((close < (sellprice - PontosParaAtivarHilo)) and (close > hilostop) and LigarStopHilo) then
closeposition;
end;
//***************************************************************
// PROTEGER NO BreakEven 1 para operações de compra
if (isSold) and ((close[0] <= (sellPrice - breakeven)) and (LigarBreakeven1)) then
begin
DefesaBreakeven := (sellPrice - breakevengain);
BuyToCoverStop(DefesaBreakeven);
end;
//*********************************************************************
// PROTEGER NO BreakEven 2
if (isSold) and ((close[0] <= (sellPrice - breakeven2)) and (LigarBreakeven2)) then
begin
DefesaBreakeven := (sellPrice - breakevengain2);
BuyToCoverStop(DefesaBreakeven,DefesaBreakeven);
end;
//*********************************************************************
////final da verificação da venda
//*********************************************************************
//fim da verificação para sair da operação de venda:==================================================
// comando nativo do profit ( hasPosition)retorna verdadeiro se a posição não for zero
if Not hasPosition and bConfigurouRiscoInicial then
begin
bConfigurouRiscoInicial := false;
bTrailingStopAtivado := false;
end;
// Plot de Stop e Alvo para inspeção visual do código
bPosicionado := hasPosition;
if bPosicionado and PLOTAR_STOP_MOVEL then
begin
plot5(PrecoStop);
plot6(PrecoStopOffset);
plot7(PrecoAlvo);
end;
if (time >= horaFecharTudo) then
begin
if ((isSold) or (isBought)) then
closeposition;
if ((time < vHoraInicio)) then
lastsinal := "";
end;
end;