Pages - Menu

標籤

AWS (1) bash (1) Boost (2) C (2) CMake (2) Concurrency_Programming (3) CPP (37) Database (2) DNS (1) Docker (4) Docker-Compose (1) ELK (1) emacs (4) gcp (1) gdrive (1) git (1) gitbash (2) gitlab (1) kvm (4) Linux (5) MT4 (4) MT5 (4) Multicast (2) MySQL (2) Nijatrader8 (1) OpenCV (1) Python (4) QT5 (1) R (1) rdp (3) screenshot (1) ssh (3) Tabnine (1) TCP (1) TensorFlow (1) Tools (12) Ubuntu_1904 (11) Ubuntu_20_04 (5) UDP (1) VS2010 (1) VS2015 (1) VS2019 (1) WebServer (1) Win10 (1) winmerge (1) WSL (1) xrdp (1)

搜尋此網誌

2020年3月21日星期六

Tabnine in spacemacs

Learn From

Environment

  • ubuntu 19.04
  • Spacemacs 0.200.13@26.3
  • Emacs 26.3

Aim

Backup the way how to install tabnine in spacemacs. Only use the following content when the above link is not available.

Steps

We would like to use tabnine as a back-end service provider. auto-completion is the front-end. We will do the following setting auto-completion -> company -> company-tabnine.

Create tabnine layer

  1. In spacemacs, type SPC SPC
  2. configuration-layer/create-layer
  3. Asking for Configuration layer path, use default path ~/.emacs.d/private/
  4. Asking for Configuration layer name, type tabnine
  5. Asking for Create readme? (y or n), type n

Inside ~/.emacs.d/private/tabnine/package.el


(defconst tabnine-packages
  '(company-tabnine)
  )

;;; initial company-tabnine library
(defun tabnine/init-company-tabnine()
  (use-package company-tabnine
    :ensure t
    :defer t
    :init
    :config)
  )
;;; use company-tabnine as company backend
(defun tabnine/post-init-company-tabnine()
  (with-eval-after-load 'company
    (add-to-list 'company-backends #'company-tabnine)
    )
  )

Add tabnine layer inside ~/.spacemacs


;; List of configuration layers to load.
dotspacemacs-configuration-layers
   '(
     auto-completion
     better-defaults
     version-control
     emacs-lisp
     git
     ivy
     tabnine
     )

Final step

  1. Restart spacemacs
  2. You may need to install tabnine binary, SPC SPC, company-tabnine-install-binary
  3. Try it out or enable the layer by SPC SPC, company-mode
    1. notice: Company mode enabled in current buffer

2020年3月18日星期三

Integrate DLL and MT4/5 VS2019 example

Aim

This is an example followed VS 2010 example. Here we will use VS 2019 to repeat the same example.

Steps

  • Create new project

  • In framework.h add

#define _DLLAPI extern "C" __declspec(dllexport)

Integrate DLL and MT4/5 VS2010 example

Aim

We would like to create a Win32 DLL by Visual Studio 2010. A script running on MT4 will then use that DLL as an example.

Learning Source

Steps

  • Create Win32 DLL project



  • In stdafx.h, add
#define _DLLAPI extern "C" __declspec(dllexport)

  • In MQL5DLLSamples.cpp

// MQL5DLLSamples.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"


//+------------------------------------------------------------------+
//| Passing and receving of simple variables                         |
//+------------------------------------------------------------------+
_DLLAPI int __stdcall fnCalculateSpeed(int &res1,double &res2)
  {
   int    res_int=0;
   double res_double=0.0;
   int    start=GetTickCount();
//--- simple math calculations
   for(int i=0;i<=10000000;i++)
     {
      res_int+=i*i;
      res_int++;
      res_double+=(double)i*(double)i;
      res_double++;
     }
//--- set calculation results
   res1=res_int;
   res2=res_double;
//--- return calculation time
   return(GetTickCount()-start);
  }
//+------------------------------------------------------------------+
//| Filling the array with values                                    |
//+------------------------------------------------------------------+
_DLLAPI void __stdcall fnFillArray(int *arr,const int arr_size)
  {
//--- check input variables
   if(arr==NULL || arr_size<1) return;
//--- fill array with values
   for(int i=0;i<arr_size;i++) arr[i]=i;
  }
//+------------------------------------------------------------------+
//| The substring replacement of the text string                     |
//| the string is passed as direct reference to the string content   |
//+------------------------------------------------------------------+
_DLLAPI void fnReplaceString(wchar_t *text,wchar_t *from,wchar_t *to)
  {
   wchar_t *cp;
//--- parameters checking
   if(text==NULL || from==NULL || to==NULL) return;
   if(wcslen(from)!=wcslen(to))             return;
//--- search for substring
   if((cp=wcsstr(text,from))==NULL)         return;
//--- replace it 
   memcpy(cp,to,wcslen(to)*sizeof(wchar_t));
  }
//+------------------------------------------------------------------+
//| Call for the crush                                               |
//+------------------------------------------------------------------+
_DLLAPI void __stdcall fnCrashTest(int *arr)
  {
//--- wait for receipt of a zero reference to call the exception
   *arr=0;
  }
//+------------------------------------------------------------------+


  • Build the dll file and put that into MQL4/Libraries in the MT4 folder
  • Prepare the mql4 script in MQL4/Scripts, DLLTest.mq4

//+------------------------------------------------------------------+
//|                                                      DLLTest.mq4 |
//|                        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"
#property strict
//---
#import "MQL5DLLSamples.dll"
int  fnCalculateSpeed(int &res1,double &res2);
void fnFillArray(int &arr[],int arr_size);
void fnReplaceString(string text,string from,string to);
void fnCrashTest(int arr);
#import
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   //--- calling the function for calculations
   int    speed=0;
   int    res_int=0;
   double res_double=0.0;

   speed=fnCalculateSpeed(res_int,res_double);
   Print("Time ",speed," msec, int: ",res_int," double: ",res_double);
//--- call for the array filling
   int    arr[];
   string result="Array: "; 
   ArrayResize(arr,10);
   
   fnFillArray(arr,ArraySize(arr));
   for(int i=0;i<ArraySize(arr);i++) result=result+IntegerToString(arr[i])+" ";
   Print(result);
//--- modifying the string
   string text="A quick brown fox jumps over the lazy dog"; 
   
   fnReplaceString(text,"fox","cat");
   Print("Replace: ",text);
//--- and finally call a crash
//--- (the execution environment will catch the exception and prevent the client terminal crush)
   fnCrashTest(NULL);
   Print("You won't see this text!");
//---
  }
//+------------------------------------------------------------------+


  • Build that script and test on MT4
  • DONE

2020年3月17日星期二

Integrate MT4/5 with other process through ZMQ

Aim

We would like to treat MT4 as a server that can provide market data, backtest environment, trading execution. Other applications written by different programming language such as python, c++, R, c# can use ZMQ library as an interface to communicate with MT4.

Learning Source

Installation Steps --- Publish market data from MT4

  1. git clone
    1. darwinex github example
    2. mql-zmq github for mt4
  2. copy DWX_ZeroMQ_Server_v2.0.1_RC8.mq4
    • From dwx-zeromq-connector/v2.0.1/mql4/
    • To MT4/MQL4/Experts
  3. copy all folders and files
    • From mql-zmq/Include/
    • To MT4/MQL4/Include
  4. copy all dll files
    • From mql-zmq/Library/MT4/
    • To MT4/MQL4/Libraries
  5. Compile EA from MT4, drag and drop the EA and enable dll import
  6. Try to publish market data
    • You will see the following logs when success

Installation Steps --- Receive market data using python

  1. copy DWX_ZeroMQ_Connector_v2_0_1_RC8.py
    • From dwx-zeromq-connector/v2.0.1/python/api/
  2. Set up vitrualenv with python3
    1. Windows
      • Install python 3
      • open cmd
      • pip install virtualenv
      • virtualenv ./pythonEnv
      • ./pythonEnv/Script/activate
    2. Linux
      1. steps
  3. Install packages
    • pip install zmq
    • pip install pandas
  4. test.py, reference Example

import sys
sys.path.insert(1, '..')

import ZMQConnector.api.DWX_ZeroMQ_Connector_v2_0_1_RC8 as zmq

# ----------------------------------- Main
if __name__ == "__main__":
    _zmq = zmq.DWX_ZeroMQ_Connector()
    _zmq._DWX_MTX_SUBSCRIBE_MARKETDATA_('EURUSD')