Bibliotecas: MT4Orders - página 36

 
Ilya Malev:
Excelente! Pelo que entendi, isso resolve o problema da seleção SELECT_BY_TICKET no histórico (sem garantia de execução parcial)?
#include <MT4Orders.mqh>

#define Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)

void OnStart()
{
  const TICKET_TYPE Ticket = OrderSend(_Symbol, OP_BUY, 1, Ask, 100, 0, 0); // Abriu uma posição.
  
  if (OrderSelect(Ticket, SELECT_BY_TICKET))
    OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 100);         // Fechou a posição.
    
  if (OrderSelect(Ticket, SELECT_BY_TICKET)) // A opção para selecionar em qualquer bilhete MT5 será acionada.
    OrderPrint();
}

Este é um exemplo do uso mais primitivo.

Obrigado, @Andrey Khatimlianskii e @Igor Makanu, por "terminarem". As tarefas que foram expressas não vieram à mente.


Em particular, agora é possível monitorar o destino de um pedido com base em seu tíquete quando ele é aberto.

É difícil montar um exemplo e explicar os detalhes do que foi feito. Experimente diferentes situações (e execução parcial) de SELECT_BY_TICKET em OrderTicket, OrderTicketOpen, OrderTicketID e quaisquer tickets do MT5.

 
fxsaber:

Esse é um exemplo do uso mais primitivo.

Algo que não entendo: em seu exemplo, não há nenhuma nova chamada de função. Na biblioteca mais recente, o histórico funcionará como no MT4 por padrão? Ou ainda é necessário fazer algo com o tíquete recebido?

 
fxsaber:

Sou grato a você, @Andrey Khatimlianskii e @Igor Makanu por "terminar". As tarefas que foram expressas não vieram à mente.

Obrigado por seu trabalho árduo e apoio

 
Ilya Malev:

Algo que não entendo: em seu exemplo, não há nenhuma nova chamada de função. Na biblioteca mais recente, o histórico funcionará como no MT4 por padrão? Ou você ainda precisa fazer alguma coisa com o tíquete recebido?

Você não precisa fazer nada com o tíquete recebido. O escopo das tarefas que podem ser resolvidas facilmente agora foi ampliado. Por exemplo.


Esse script

#property script_show_inputs

#include <MT4Orders.mqh>

input TICKET_TYPE inTicket = 0;

// Saída conveniente
template <typename T>
T MyPrint( const T Value, const string Str ) { Print(Str + " = " + (string)Value); return(Value); }
#define _P(A) MyPrint(A, __FUNCSIG__ ", Line = " + (string)__LINE__ + ": " + #A)

// Emite todos os dados do tíquete
void Test( const TICKET_TYPE Ticket )
{
  _P(Ticket);
  
  if (_P(OrderSelect(Ticket, SELECT_BY_TICKET)))
  {
    OrderPrint();
    
    _P(OrderTicket());
    _P(OrderTicketOpen());
    _P(OrderTicketID());
  }
  
  Print("");
}

void OnStart()
{    
  Test(inTicket);
  
  if (OrderSelect(OrdersHistoryTotal() - 1, SELECT_BY_POS, MODE_HISTORY))
    Test(OrderTicket());
}


produzirá algo parecido com isto

void Test(const long), Line = 15: Ticket = 0
void Test(const long), Line = 17: OrderSelect(Ticket,1) = false

void Test(const long), Line = 15: Ticket = 1753321
void Test(const long), Line = 17: OrderSelect(Ticket,1) = true
#1753321 2019.03.13 16:15:07 buy 1.00 EURUSD 1.13119 0.00000 0.00000 2019.03.13 16:15:08 1.13118 -4.52 0.00 -1.00 0
void Test(const long), Line = 21: OrderTicket() = 1753321
void Test(const long), Line = 22: OrderTicketOpen() = 1753320
void Test(const long), Line = 23: OrderTicketID() = 2532884

A seleção em qualquer um dos tíquetes selecionados produzirá o mesmo resultado.

 
fxsaber:

A seleção por qualquer um dos tickets selecionados produzirá o mesmo resultado.

Portanto, é completamente normal quando a seleção por Ticket é bem-sucedida e OrderTicket() != Ticket.

 

Fórum sobre negociação, sistemas de negociação automatizados e teste de estratégias de negociação

Especialistas: TradePanel

fxsaber, 2019.04.10 22:28

Converter para MT5:
#include <KimIVToMT5.mqh> // https://www.mql5.com/ru/forum/93352/page32#comment_10603352

#define  ERR_NO_CONNECTION 6
#define  ERR_TRADE_NOT_ALLOWED 4109
#define  ERR_TRADE_EXPERT_DISABLED_BY_SERVER 4112

int ObjectsTotal() { return(ObjectsTotal(0)); }
string ObjectName( const int Pos ) { return(ObjectName(0, Pos)); } 
bool IsConnected() { return((bool)TerminalInfoInteger(TERMINAL_CONNECTED)); }

#define NULL _Symbol // redefinição de macro

#include "TradePanel.mq4" // https://www.mql5.com/en/code/19752
 
Outro exemplo de conversão

Fórum sobre negociação, sistemas de negociação automatizados e teste de estratégias de negociação

Indicadores: Gráfico de ações

fxsaber, 2019.04.25 11:25 AM.

Parece que funcionou

#define  MT4_TICKET_TYPE // Obrigar o OrderSend e o OrderTicket a retornar um valor do mesmo tipo que no MT4 - int.
#include <KimIVToMT5.mqh> // https://c.mql5.com/3/263/KimIVToMT5.mqh

// https://www.mql5.com/en/blogs/post/681230
#include "ind4to5.mqh" // https://c.mql5.com/3/277/ind4to5.mqh

#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots 2
#property indicator_color1 SteelBlue
#property indicator_color2 OrangeRed
#property indicator_color3 SlateGray
#property indicator_color4 ForestGreen
#property indicator_color5 Silver
#property indicator_color6 Gray
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
#property indicator_width6 1

#define  TotalOrders TotalOrdersTmp
#define  Ticket TicketTmp
#define  StartTime StartTimeTmp
#define  Type TypeTmp
#define  Margin MarginTmp
#define  Magic MagicTmp

bool ObjectSetText( const string name, const string text,
                    const int font_size = 0, const string font_name = NULL )
{
  return(ObjectSetString(0, name, OBJPROP_TEXT, text) &&
         (!font_size || ObjectSetInteger(0, name, OBJPROP_FONTSIZE, font_size)) &&
         ((font_name == NULL) || ObjectSetString(0, name, OBJPROP_FONT, font_name)));
}

string StringConcatenate( const string Str1, const string Str2, const string Str3 )
{
  return(Str1 + Str2 + Str3);
}

string StringConcatenate( const string Str1, const string Str2, const string Str3, const string Str4)
{
  return(Str1 + Str2 + Str3 + Str4);
}

string StringConcatenate( const string Str1, const string Str2, const string Str3, const string Str4, const string Str5 )
{
  return(Str1 + Str2 + Str3 + Str4 + Str5);
}

string StringConcatenate( const string Str1, const string Str2, const int Str3, const string Str4, const int Str5 )
{
  return(Str1 + Str2 + (string)Str3 + Str4 + (string)Str5);
}

string StringConcatenate( const string Str1, const string Str2, const string Str3, const string Str4, const string Str5, const string Str6 )
{
  return(Str1 + Str2 + Str3 + Str4 + Str5 + Str6);
}

string StringConcatenate( const string Str1, const int Str2, const string Str3, const double Str4, const string Str5, const string Str6 )
{
  return(Str1 + (string)Str2 + Str3 + (string)Str4 + Str5 + Str6);
}

string StringConcatenate( const string Str1, const string Str2, const string Str3, const string Str4, const string Str5, const string Str6, const string Str7 )
{
  return(Str1 + Str2 + Str3 + Str4 + Str5 + Str6 + Str7);
}

string StringConcatenate( const int Str1, const string Str2, const ENUM_TIMEFRAMES Str3, const string Str4)
{
  return((string)Str1 + Str2 + EnumToString(Str3) + Str4);
}

// Comente a linha com o erro de compilação: 'Import_History' - a constante não pode ser modificada Equity-Monitor.mq4 734 7
#include "Equity-Monitor.mq4" // https://www.mql5.com/pt/code/13242

 

Fórum sobre negociação, sistemas de negociação automatizados e teste de estratégias de negociação

Conversor de código de MT4 para MT5

fxsaber, 2019.04.29 10:47 AM

#property indicator_chart_window 
#property indicator_buffers 6
#property indicator_plots 6
#property indicator_color1 White 
#property indicator_color2 White 
#property indicator_color3 DodgerBlue
#property indicator_color4 DodgerBlue
#property indicator_color5 Lime
#property indicator_color6 Red
 
#property indicator_width1 5
#property indicator_width2 5
#property indicator_width3 3
#property indicator_width4 3
#property indicator_width5 1
#property indicator_width6 1

#include <KimIVToMT5.mqh> // https://c.mql5.com/3/263/KimIVToMT5.mqh

// https://www.mql5.com/en/blogs/post/681230
#define  MT4_OLD_EVENT_HANDLERS
#include "ind4to5.mqh" // https://c.mql5.com/3/277/ind4to5.mqh

#define  digits digits2
#undef MODE_LOW
#undef MODE_HIGH

#include "Chaos_Semafor_-_3_Mod.mq4" // https://c.mql5.com/3/277/Chaos_Semafor_-_3_Mod__1.mq4
 
Se você precisar manter o uso do MT4Orders em seu produto sem falar, poderá cortar as partes relevantes do código-fonte da biblioteca ou colocar um stub universal nele
// Por meio de macros, eliminamos todas as dicas sobre a presença do MT4Orders.
#define Alert PrintTmp
#define Print PrintTmp
  void PrintTmp( string ) {}
  
  #include <MT4Orders.mqh> // https://www.mql5.com/pt/code/16006
#undef  Print
#undef  Alert
 

Fórum sobre negociação, sistemas de negociação automatizados e teste de estratégias de negociação

Especialistas: Daily Chart Trader

fxsaber, 2019.04.30 12:08 AM

Versão MT5
#define  MT4_TICKET_TYPE // Obrigar o OrderSend e o OrderTicket a retornar um valor do mesmo tipo que no MT4 - int.
#include <KimIVToMT5.mqh> // https://c.mql5.com/3/263/KimIVToMT5.mqh

#include "ind4to5.mqh" // https://c.mql5.com/3/277/ind4to5.mqh

bool ObjectSetText( const string name, const string text,
                    const int font_size = 0, const string font_name = NULL, const color Color = clrNONE )
{
  return(ObjectSetString(0, name, OBJPROP_TEXT, text) &&
         ((font_name == NULL) || ObjectSetInteger(0, name, OBJPROP_FONTSIZE, font_size)) &&
         ((font_name == NULL) || ObjectSetString(0, name, OBJPROP_FONT, font_name)) &&
         ((Color == clrNONE) || ObjectSetInteger(0, name, OBJPROP_COLOR, Color)));
}

#define NULL ""

#include "AEROSPINE.mq4" // https://www.mql5.com/en/code/24903