MT5 and trans2quik.dll - page 14

 
prostotrader:

Then wait for me to get into options...

Right now I'm only trading them with my hands (waiting for the news).

Ok, thanks.

 

Tweaked SetTickers() to make it work faster

//+------------------------------------------------------------------+
//| Set Tickers  function                                            |
//+------------------------------------------------------------------+
bool SetTickers()
{
  int s_total = SymbolsTotal(false);
  if(s_total > 0)
  {
    ArrayResize(qfs_data, s_total);
    int s_cnt = 0;
    ulong fut_exp;
    string fut_name, t_name, spot_name;
    ulong cur_time = ulong(TimeTradeServer());
    for(int i = 0; i < s_total;i++)
    {
      fut_name = SymbolName(i, false);
      fut_exp = GetExpiration(fut_name);
      if(fut_exp > ulong(cur_time))
      {
        for(int j = 0; j < ArraySize(enum_tikers);j++)
        {
          t_name = EnumToString(enum_tikers[j]);
          if(t_name != "")
          {
            if(StringFind(fut_name, t_name) > -1)
            {
              spot_name = GetSpot(t_name);
              if(spot_name != "")
              {
                s_cnt++;
                qfs_data[s_cnt - 1].tiker = fut_name;
                qfs_data[s_cnt - 1].base_tiker = spot_name;
                if(SymbolSelect(fut_name, true) != true) return(false);
                if(SymbolSelect(spot_name, true) != true) return(false);
                break;
              }  
            }
          }
        }
      }
    }
    if(s_cnt > 0)
    {
      ArrayResize(qfs_data, s_cnt);
      return(true);
    }  
  }
  return(false);
}
 

While there is no opportunity to do other things, I have decided to

To continue my work on MT5 --> Quik

I found a solution how to write a robot on MT5 and give trading orders to Quik.

The robot in MT5 will work with futures or shares.

And also joint work futures - stocks.

To work we need a FORTS real account (MT5) and the EBS with Quick at any broker.

Approximate "fish" of the Expert Advisor

//+------------------------------------------------------------------+
//|                                                     MT5_quik.mq5 |
//|                                      Copyright 2020 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020 prostotrader"
#property link      "https://www.mql5.com"
#property version   "1.00"
//---
#define  RET_ERROR  -1
//---
struct INIT_QUIK
{
  uchar tr2q_path[100];
  uchar fut_class_code[20];
  uchar fut_symb_code[20];
  uchar fut_account[20];
  uchar spot_class_code[20];
  uchar spot_symb_code[20];
  uchar spot_account[20];
};
struct BOOK_DATA
{
  double price;
  long   volume;
};
struct MARKET_DATA
{
  BOOK_DATA fut_sell;
  BOOK_DATA fut_buy;
  BOOK_DATA spot_sell;
  BOOK_DATA spot_buy;
};
//---
input string QDll    = "D:\\Program Files\\QUIK-Junior"; //Путь к rtans2quik.dll
input string FClCode = "SPBFUT";                         //Код класса фьючерса
input string FSCode  = "SRU0";                           //Код символа фьючерса
input string FAcc    = "SPBFUT00064";                    //Номер счета фьючерса;
input string SClCode = "TQBR";                           //Код класса СПОТа
input string SSCode  = "SBER";                           //Код символа СПОТа
input string SAcc    = "NL0011100043";                   //Номер счета СПОТа;
//---
#import "MT5_to_Quik.dll"
  int InitQuik(INIT_QUIK &a_str);                                                              
  int SetFutOrder(const double price, const long volume, const int ord_type, ulong &ticket);    
  int SetSpotOrder(const double price, const long volume, const int ord_type, ulong &ticket);
  int RemoveFutOrder(const ulong ticket);
  int RemoveSpotOrder(const ulong ticket);
  int ModifyFutOrder(const double price, const long volume, ulong &ticket);
  int ModifySpotOrder(const double price, const long volume, ulong &ticket);
#import
//---
INIT_QUIK init_quik;
MARKET_DATA m_data;
bool fut_book, spot_book;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
  int result = StringToCharArray(QDll, init_quik.tr2q_path);
  if(result > 0)
  {
    result = StringToCharArray(FClCode, init_quik.fut_class_code);
    if(result > 0)
    {
      result = StringToCharArray(FSCode, init_quik.fut_symb_code);
      if(result > 0)
      {
        result = StringToCharArray(FAcc, init_quik.fut_account);
        if(result > 0)
        {
          result = StringToCharArray(SClCode, init_quik.spot_class_code);
          if(result > 0)
          {
            result = StringToCharArray(SSCode, init_quik.spot_symb_code);
            if(result > 0)
            {
              result = StringToCharArray(SAcc, init_quik.spot_account);
            }
          }
        }
      }
    }
  }
  result = InitQuik(init_quik);
  if(result == RET_ERROR) return(INIT_FAILED);
//---
  fut_book = MarketBookAdd(Symbol());
  if(SymbolSelect(SSCode, true) == true)
  {
    spot_book = MarketBookAdd(SSCode);
  }
  else
  {
    Print("SPOT not selected!");
    return(INIT_FAILED);
  }  
  return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
  if(fut_book == true) MarketBookRelease(Symbol());
  if(spot_book == true) MarketBookRelease(SSCode); 
}
//+------------------------------------------------------------------+
//| Expert Get Book function                                         |
//+------------------------------------------------------------------+
bool GetBook(const string a_symbol)
{
  MqlBookInfo book_data[];
  bool is_found = false;
  if(MarketBookGet(a_symbol, book_data) == true)//getBook )
  {
    int size = ArraySize(book_data);
    if(size > 2)                                //Sell price exists
    {
      for(int i = 0; i < size; i++)
      {
        if(book_data[i].type == BOOK_TYPE_BUY) 
        {
          if(a_symbol == Symbol())
          {
            m_data.fut_buy.price = book_data[i].price;
            m_data.fut_sell.price = book_data[i-1].price;
            m_data.fut_buy.volume = book_data[i].volume;
            m_data.fut_sell.volume = book_data[i-1].volume;
          }
          else
          if(a_symbol == SSCode)
          {
            m_data.spot_buy.price = book_data[i].price;
            m_data.spot_sell.price = book_data[i-1].price;
            m_data.spot_buy.volume = book_data[i].volume;
            m_data.spot_sell.volume = book_data[i-1].volume;
          }
          return(true);
        }
      }  
    }  
  } 
  return(false);
}
//+------------------------------------------------------------------+
//| Expert Book Event function                                       |
//+------------------------------------------------------------------+
void OnBookEvent(const string &symbol)
{
  if((symbol == Symbol()) || (symbol == SSCode)) 
  {
    if(GetBook(Symbol()) == true)
    {
      if(GetBook(SSCode) == true)
      {
        //TODO YOU TS
      }
    }
  }  
}
//+------------------------------------------------------------------+
 
prostotrader:

While there is no opportunity to do other things, I have decided to

To continue my work on MT5 --> Quik

I found a solution how to write a robot on MT5 and give trading orders to Quik.

The robot in MT5 will work with futures or shares.

And also joint work futures - stocks.

To work we need a FORTS real account (MT5) and the EBS with Quick at any broker.

Approximate "fish" of the Expert Advisor

Good work!

What can a fish do? :)

Is it possible to get market information through the library?

More comments, please, in the code!
 
Aleksey Vyazmikin:

Good business!

What can fish do? :)

Is it possible to get market information through the library?

More comments, please, in the code!

There is nothing to explain yet, I have a problem with pending orders because there are no callbacks in MT5.

I want to have pending orders in my arsenal.

Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Приказы на проведение торговых операций оформляются ордерами. Каждый ордер имеет множество свойств для чтения, информацию по ним можно получать с помощью функций Идентификатор позиции, который ставится на ордере при его исполнении. Каждый исполненный ордер порождает сделку, которая открывает новую или изменяет уже существующую позицию...
 
prostotrader:

There is nothing to explain yet, there is a problem with pending orders, there are no callbacks in MT5.

and we want to have pending orders.

The callbacks can be organized through OnChartEvent, you can send a keypress from delphi to the MT chart.

 
Sergey Chalyshev:

Callbacks can be organised via OnChartEvent, you can also send a keystroke on the MT chart from delphi.

Hi Seryozh.

Thank you, I will try it.

And you have an example?

 
prostotrader:

Hello, Seryozh.

Thanks, I'll give it a try.

Do you have an example?

I don't have any ready-made solution, I just tried it, I can't find an example right now, maybe later.

Look here for now.

Обмен данными между советниками
Обмен данными между советниками
  • 2019.03.31
  • www.mql5.com
Есть ли возможность обмена данными между двумя советниками, которые работают одновременно с двумя разными инструментами...
 

Forgot to take the depot from Quick, so.... Gave up on that one.

 
prostotrader:

Forgot to take the depot from Quick, so.... Gave up on that one.

Well from QUIK it is possible to send the required information via file, as an option.