irinacfd : Sorry, I had edited the code and have added the code for the Buy signal.
Doesn't compile! This is my last post - I will not help you anymore: you may continue to think that you have invented the GRAIL and continue to hide the code.
Doesn't compile! This is my last post - I will not help you anymore: you may continue to think that you have invented the GRAIL and continue to hide the code.
I dont understand, the entire code is 1000 lines, shall I post 1000 lines of code here?
I'm rookie at MT5 and trying to test Swing Trade Expert. So When I try to run, operation from today is closed on auction (before market is really opened).
May you help me?
//+------------------------------------------------------------------+//| Robo Teste.mq5 |//| Copyright 2020, MetaQuotes Software Corp. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2020, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"//+------------------------------------------------------------------+//| INCLUDES |//+------------------------------------------------------------------+#include <Trade/Trade.mqh> // Biblioteca padrao CTrade//+------------------------------------------------------------------+//| INPUTS |//+------------------------------------------------------------------+inputint V = 1;//-- volumeinputint P = 14;
inputint RSISELL = 90;
inputint RSIBUY = 10;
inputint PECRSI = 3;
inputint HIA = 9; //HORA INICIO ABERTURA OPERACOESinputint MIA = 00;//MINUTO INICIO ABERTURA OPERACOESinputint HFA = 16;//HORA LIMITE ABERTURA OPERACOESinputint MFA = 30;//MINUTO LIMITE ABERTURA OPERACOESinputulong desvPts = 1;//Desvio em Pontosinputdouble G = 10.0;// GAINinputdouble L = 3.0;//LOSSMqlDateTime horaAtual;
MqlTick ultimoTick;
MqlRates rates[];
//+------------------------------------------------------------------+//| GLOBAIS |//+------------------------------------------------------------------+int rsihandle = INVALID_HANDLE;
int emahandle = INVALID_HANDLE;
//--- vetores de dadosdouble rsi[];
double ema[];
double ask, bid;
//--- declarar variavel trade
CTrade trade;
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//---ArraySetAsSeries(rsi,true);
ArraySetAsSeries(ema,true);
//--- atribuir valores de manipulador dos indicadores
rsihandle = iRSI(_Symbol,_Period,P,PRICE_MEDIAN);
emahandle = iMA(_Symbol,_Period,9,0,MODE_EMA,PRICE_MEDIAN);
if(HIA == HFA && MIA >= MFA)
{
Alert("INCONSISTENCIA HORARIOS DE NEGOCIACAO-VERIFICAR MINUTOS HORA NEGOCIACAO");
return(INIT_FAILED);
}
if( HFA < HIA )
{
Alert("INCONSISTENCIA HORARIOS DE NEGOCIACAO-HORA FIM MAIOR HORA INICIO");
return(INIT_FAILED);
}
//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
if(!SymbolInfoTick(Symbol(),ultimoTick))
{
Alert("Erro ao obter informações de Preços: ", GetLastError());
return;
}
if(CopyRates(_Symbol, _Period, 0, 3, rates)<0)
{
Alert("Erro ao obter as informações de MqlRates: ", GetLastError());
return;
}
elseif(HoraNegociacao())
{
Comment("DENTRO HORARIO NEGOCIACOES");
}
else
{
Comment("FORA HORARIO NEGOCIACOES");
}
// execute EXPERT//+------------------------------------------------------------------+//| COLLECTING DATA |//+------------------------------------------------------------------+int copied1 = CopyBuffer(rsihandle,0,0,3,rsi);
int copied2 = CopyBuffer(emahandle,0,0,3,ema);
//---//---bool buySignal = false;
bool sellSignal = false;
//--- if the data obtained were copied correctlyif(copied1==3 && copied2==3)
{
//--- buySignalif( rsi[0] < RSIBUY && ema[0] > ema[1] > ema [2])
{
buySignal = true;
}
//--- SELL SIGNALif( rsi[0] > RSISELL && ema[0] < ema[1] < ema [2])
{
sellSignal = true;
}
}
//+------------------------------------------------------------------+//| CHECK IF I AM POSITIONED |//+------------------------------------------------------------------+bool bought = false;
bool sold = false;
if(PositionSelect(_Symbol))
{
//--- if the position is boughtif(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY )
{
bought = true;
}
//--- if the position is SOLDif(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL )
{
sold = true;
}
}
//+------------------------------------------------------------------+//| LOGICA DE ROTEAMENTO |//+------------------------------------------------------------------+//--- no operations
ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
if( !sold && !bought )
{
//--- sinal de compraif( buySignal && HoraNegociacao() )
{
trade.Buy(V,_Symbol,0,ask-L, ask+G ,"Compra a mercado");
}
//--- sinal de vendaif( sellSignal && HoraNegociacao() )
{
trade.Sell(V,_Symbol,0 , bid+L,bid-G,"Venda a mercado");
}
}
if(HoraFechamento())
{
Comment("HORARIO FECHAMENTO MERCADO!");
FecharPosicao();
}
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+//---//---//---//---bool HoraNegociacao()
{
TimeToStruct(TimeCurrent(), horaAtual);
if(horaAtual.hour >= HIA && horaAtual.hour <= HFA)
{
if(horaAtual.hour == HIA)
{
if(horaAtual.min >= MIA)
{
returntrue;
}
else
{
returnfalse;
}
}
if(horaAtual.hour == HFA)
{
if(horaAtual.min <= MFA)
{
returntrue;
}
else
{
returnfalse;
}
}
returntrue;
}
returnfalse;
}
//---//---bool HoraFechamento()
{
TimeToStruct(TimeCurrent(), horaAtual);
if(horaAtual.hour >= 16)
{
if(horaAtual.hour == 16)
{
if(horaAtual.min >= 59)
{
returntrue;
}
else
{
returnfalse;
}
}
returntrue;
}
returnfalse;
}
//---//---//---//---void FecharPosicao()
{
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ResetLastError();
PositionSelectByTicket(PositionGetTicket(i));
if(PositionGetInteger(POSITION_MAGIC) == 123456 && PositionGetString(POSITION_SYMBOL) == _Symbol)
{
if(trade.PositionClose(PositionGetTicket(i)))
{
Print("Posições fechadas");
}
elsePrint("Erro ao fechar Posição ", GetLastError());
}
}
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
***
So what all is wrong with above code?
Thank you!
Your code does not compile - as you showed the snippet of code. I can't read other people's minds (although I try very hard).
Your code does not compile - as you showed the snippet of code. I can't read other people's minds (although I try very hard).
Sorry, I had edited the code and have added the code for the Buy signal.
I shall repeat, it is generating the signal, but not always at the bar on which the signal in the chart appears.
Sorry, I had edited the code and have added the code for the Buy signal.
Doesn't compile! This is my last post - I will not help you anymore: you may continue to think that you have invented the GRAIL and continue to hide the code.
Doesn't compile! This is my last post - I will not help you anymore: you may continue to think that you have invented the GRAIL and continue to hide the code.
Hey Guys
I'm rookie at MT5 and trying to test Swing Trade Expert. So When I try to run, operation from today is closed on auction (before market is really opened).
May you help me?
I dont understand, the entire code is 1000 lines, shall I post 1000 lines of code here?
Y.E.S.. :P
And make sure you use the Code (Alt + S) or upload the .mq5 file, unless its proprietary or "for your eyes only type of thing".you can use The Trade Request Structure (MqlTradeRequest) and TRADE_ACTION_SLTP
You can put TP near or under/obove price in buy/sell condition