Abrir condição no fechamento de uma vela

 

Pessoal,

 Na parte do meu código, quero fechar todas as ordens assim que a vela fechar. Alguma dica? 

 
Pensei em fazer por cálculo de hora, por exemplo, negociando em H4, abriu as 10:10, mando fechar as 14:10. Porém é meio gambiarra, gostaria de fechar a ordem assim que fechar a vela atual e abrir uma nova.
 
Bruno Salles Pereira:

Pessoal,

 Na parte do meu código, quero fechar todas as ordens assim que a vela fechar. Alguma dica? 

Olá Bruno,

aqui no fórum tem um artigo sobre isso.

   static datetime Old_Time;
   datetime New_Time[1];
   bool IsNewBar=false;

// copying the last bar time to the element New_Time[0]
   int copiedTIME=CopyTime(_Symbol,_Period,0,1,New_Time);
   if(copiedTIME>0) // ok, the data has been copied successfully
     {
      if(Old_Time!=New_Time[0]) // if old time isn't equal to new bar time
        {
                IsNewBar=true;   // if it isn't a first call, the new bar has appeared
                if(MQL5InfoInteger(MQL5_DEBUGGING)) Print("We have new bar here ",New_Time[0]," old time was ",Old_Time);
                Old_Time=New_Time[0];            // saving bar time
        }
     }
   else
     {
        Print("Error in copying historical times data, error =",GetLastError());
        ResetLastError();
        return;
     }

//---
   if(PositionSelect(Symbol()))
     {
      if(IsNewBar)
        {
            Print("New Bar"); // closePosition();
        }
     }

 

https://www.mql5.com/en/articles/100 

 

Abraço. 

Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners
Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners
  • 2010.06.09
  • Samuel Olowoyo
  • www.mql5.com
The Expert Advisors programming in MQL5 is simple, and you can learn it easy. In this step by step guide, you will see the basic steps required in writing a simple Expert Advisor based on a developed trading strategy. The structure of an Expert Advisor, the use of built-in technical indicators and trading functions, the details of the Debug mode and use of the Strategy Tester are presented.
 
Amigo, vou verificar. Muito obrigado
 

https://www.mql5.com/pt/articles/159

Handler de evento "nova barra"
Handler de evento "nova barra"
  • 2014.02.06
  • Konstantin Gruzdev
  • www.mql5.com
A linguagem de programação é capaz de resolver problemas em um nível completamente novo. Mesmo as tarefas que já tenham soluções, graças à programação orientada a objeto elas podem atingir um nível ainda maior. Neste artigo, consideramos um exemplo especialmente simples de verificação de uma nova barra em um gráfico, que foi transformado em uma ferramenta bastante poderosa e versátil. Qual ferramenta? Descubra neste artigo.
 
otaviokc:

https://www.mql5.com/pt/articles/159

Otávio, mais uma vez, obrigado!
 
boa note pessoal alguen tem um EA renko por mudança de cor da vela
 
xandyy:
boa note pessoal alguen tem um EA renko por mudança de cor da vela

Procure no CodeBase. Se nao encontrar, desenvolva ou contrate desenvolvedor na area de Freelance.

Razão: