投稿者: Yamanouchi Katsura

  • How to use Metatrader4 on affordable VPS

    For example, VPS(KVM) by onamae.com

    bibliography
        lubuntu http://lubuntu.net/
        WINE https://www.winehq.org/
        MetaTrader4 http://www.metatrader4.com/
        ONAMAE.COM http://www.onamae.com/

    0  VPS contract and login
    I set up a MetaTrader4 platform on the virtual private server(VPS-KVM) provided by “ONAMAE.com”.
    This server has the following specifications:
    -CPU: shared virtual Core2Duo T7700 2.4GHz
    -MEMORY: 1GB
    -STORAGE : HDD 20GB + 80GB
    -RENDERER: Gallium 0.4 on llvmpipe (LLVM 3.8, 128 bits)

    You can visit the “onamae.com” website, and sign up for the smallest VPS(KVM) with 1GB of memory.  Don’t select a larger configuraton.  For the purpose of installing and running MetaTrader4 along with some related programs, you don’t need more than 2GB of memory.
    After you complete the contract, you will receive a “Login ID” and “Password” for your VPS. Go to the login page at “https://cp.myvps.jp/” to access the control panel.
    Click on the VPS name field (for example, “kvm00XXXXXX”).

    2016-05-13-3-1

    1  Installation of the Operating System and other Programs
    Next, you must install the operating system, a desktop manager, and WINE Windows(R) compatibility layer.
    I recommend using “lubuntu“,which is a lighter version of “Ubuntu”.
    The reasons are :
    – It is lightweight and uses less memory
    – It supports the Ubuntu kernel and WINE package.
    Now, let’s begin the installation process.

    1) First, visit the “lubuntu” web site and download the latest ISO image file. Do not download the Japanese-localized version, as it uses more memory-and in this case, you won’t be able to use a Japanese IME on your VPS.
    2) Then, log in to youre VPS control panel using your user ID and password.

    2016-05-13 (7)
    STEP1 Make SSH connect

    3) Upload the previously downloaded ISO file to the special “image” folder on the common server at ONAMAE.COM. You can use “WinSCP(SFTP software for Windows)“. If you are using another operating system, use an SFTP client that is appropriate for your OS.
    4) In WinSCP, select “New Site” > SFTP , then fill in the Hostname , User Name, and Password.

    2016-05-13-6
    WinSCP login

    And you have to hit the “Settings” button. You can find SSH > “Permission” at menu tree on the left, Select “Secret Key” from the file already downloaded. You will find a notification saying some cautions. You have to create and save a “private key” as .ppk format. After you saved that key, you should select again the saved key(-.ppk not -.key) and press the login button on the WinSCP.

    2016-05-13-5
    key to PPK

    5) After copying the iso image into the server, You have to go back to the server control panel. Click the server listing area “KVM/////”, press the “please select image” drop-box, scroll down , choose “[kvm///]lubuntu///]”, hit “insert” button, then click “restart” button.

    Control panel load the iso data and prepare the install menu. Follow the instructions of the installer. Nothing will be bothering you during the installing process.
    The installer shows a restart order on-screen. You have to remove force the iso image. After that, hit the “restart” button again.
    If you complete the process, the lubuntu desktop will appear on-screen.  Resolution can be changed from menu > Preferences > Monitor Settings.
    Are you ready?
    So, Let’s go the next step.

    2  OS initialization
    Next, You would install WINE.
    The site “https://wiki.winehq.org/Ubuntu” will help you well.
    1) Login Control panel, and start server.
    2) Start 32bit architecture
    sudo dpkg –add-architecture i386
    3) Add repository for wine
    sudo add-apt-repository ppa:wine/wine-builds
    4) Update for packages
    sudo apt-get update
    5) Install WINE developer version (latest 1.9)
    sudo apt-get install –install-recommends winehq-devel

    *Notice: Stable version 1.8 have some trouble with winhttp, so MetaTrader4 installer will lost network connectivity, and may cause of install failure(so-called “proxy problem”).
    WINE installer help you when you need to install other necessary program. Please obey their suggestions.

    6) Visit the MetaTrader4 download page (anywhere you like), download, and save the .exe file.
    7) Start Filer, and open the metatrader.exe by Wine program loader. Install process will begin.

    That’s all for installation. Try metatrader4 on your VPS.
    If you have an original Expert Adviser or Indicator etc. already, it would be better to install SSH and FTP server on your VPS. Let’s try the final step.

    3 Server settings for management
    If you need to handle your VPS with remote, these applications below must be helpful to save your time.
    1) OpenSSH
    Sudo apt-get install openssh-serve
    *It’s easy! However, it may cause a security problem, so you must install a firewall.
    I recommend “WinSCP” as a client for Windows.

    There is one difference between .iso loading process and after OS installed.
    If you installed OS from your uploaded .iso file, you don’t have to hit the “Settings” button. You could find SSH > “Permission” at the menu tree on the left. However, You can connect by password, so you don’t need to download the “Secret Key”.

    One caution is that password authentication includes security risks. So you must install Firewall on your server and close port, while you don’t handle remote file handling.

    2) Vsftp
    Sudo apt-get install vsftpd
    *It also has a security risk, so you must install a firewall.
    I recommend “TeraTerm” as a client for Windows.

    3) Firewall GUI (*VERY IMPORTANT!)
    sudo apt-get install gufw
    * When you don’t need a remote filehandle, It would be better to set the firewall “on”.

    That’s all from me.
    If you need more information, please search for internet resources.

  • 70tick20EMA indicator for MetaTrader4

    70tick20ema & MyCPanel

    The original program was developed by Mr.Rondo(http://fx-dollaryen.seesaa.net/article/414537690.html).

    Remodeling contents by me are below:
    Rounding price for the candle bar to be displayed in the 1pip unit
    Adding horizontal lines to be displayed change at the time of the appearance of the DD sign
    Adding horizontal lines to support range imaging
    We are adding a control panel to change or reset the number of DD and Range settings.

    Installation:
    1. Download 70tick20ema.mq4 and myCPanel.mqh.
    2. Put the *.mq4 file to ‘Indicator’ directory, and Put the *.mqh file to ‘Include’ directory.
    3. Compile mq4 file in MetaEditor.
    4. Let’s try on your chart.

    Usage:
    Please try in various usage.
    When the display becomes strange, turn off the chart, and try to re-display.

    Option notice:
    ‘Ignore spread true’ means to absorb the spreads variable. When it is false, the bar price is displayed as supplied price by your fx broker.

    Please download here(ZIP file) >> 70tick20ema.zip

    Thank you.


    New Script version is here > TickConverter v1.02

  • MQL4 & Visual C++2013 DLL with string

    I’ll show you here a useful ‘dll’ for MQL4 of MetaTrader4 for Windows.
    You may need ‘VisualStudio2013 & C++’. Of course, also MT4.
    At first, I introduce you to some helpful web sites below; Many thanks to these genius authors!!.

    Basic References
    https://msdn.microsoft.com/ja-jp/library/60k1461a.aspx MSDN References for VisualC++
    http://www7b.biglobe.ne.jp/~robe/cpphtml/index.html Mr. roberr
    http://www.asahi-net.or.jp/~yf8k-kbys/newcpp5.html C++ entrance

    Modern Coding C++
    https://cybozu.atlassian.net/wiki/pages/viewpage.action?pageId=8159240 Modern C++ Mr.Yamamoto(Cyboze co Ltd)
    https://isocpp.org/get-started ModernC++11,14
    http://www.geocities.co.jp/bleis_tift/cpp/badstd.html std namespace? what is that

    Stream
    http://99blues.dyndns.org/blog/2010/02/std_stringstream/ Stream general help
    http://homepage2.nifty.com/well/Stream.html Stream basic
    http://ppp-lab.sakura.ne.jp/ProgrammingPlacePlus/cpp/language/006.html filestream basic
    http://mementoo.info/archives/611 file coding

    Unicode specific
    http://vllv.us/Junk/_T/ Code general
    http://loops.at.webry.info/201011/article_3.html Unicode problem
    http://www.02.246.ne.jp/~torutk/cxx/vc/misc_tchar.html TCHAR coding
    https://social.msdn.microsoft.com/Forums/vstudio/ja-JP/a0bcb7d6-525b-4da8-8ea9-c02dd82e8cd4/basicifstream TCHAR Coding for filehandle
    http://www-06.ibm.com/jp/linux/tech/doc/007aca9b.html character code of filename references on windows file system version(Unicode,sjis Japanese)

    MT4
    http://www.green.dti.ne.jp/sdimension/mql/mql_2011_03.pdf#search=’mql+dll’ Mr.amenbo Helpful document with 4step development method
    https://www.tradersquare.jp/community/topic/47-mt4-%E5%90%91%E3%81%91-dll-%E3%81%AE%E9%96%A2%E6%95%B0%E3%82%A8%E3%82%AF%E3%82%B9%E3%83%9D%E3%83%BC%E3%83%88/ Document about MQL4 and DLL export table

    Test fo file handling and string transition

    I chose the 4 step method suggested by Mr.amenbo(see link), and add a bit shortcut.
    Step 1 is the same as the original idea, so let’s begin.
    I wrote ‘test.cpp’ as my solution name, but you can change as you like, within coding regulations.
    ‘%…%’ means replace proper string.
    Many impressive sites exist, but difficult for beginners. My comments in the .cpp code below might be helpful for your .dll coding for MQL4. Because I spend considerable hours to understand how to call dll from MQL4, if you like this message, please give me your expected expenses.
    You may try this code at a debug mode. Push ‘local debugger,’ and you can see a console window and prompt on the window.
    Here, step 1 must be complete, easy? Or difficult?
    If you have a question, please comment on this message. I don’t receive any e-mail from an unknown person.
    Finally some important notices, I cannot speak English, as you know?… and I’m a native Japanese living in Japan.

    Step 1-1 Create full code on C++

    [cpp]
    // test.cpp : Test for Console application for MT4
    #include "stdafx.h"	// you must add these header below in this headerfile
    // #include "targetver.h"
    // #include <tchar.h>
    // #include <locale>
    // #include <string>
    // #include <fstream>
    // #include <iostream>
    // #include <stdexcept>
    // #include <limits>
    #if defined(_UNICODE) || defined(UNICODE)
    #  define tcout std::wcout
    #  define tcin std::wcin
    #else
    #  define tcout std::cout
    #  define tcin std::cin
    #endif
    typedef std::basic_string<_TCHAR> tstring;
    typedef std::basic_ifstream<_TCHAR> tifstream; // file in stream
    typedef std::basic_stringstream<_TCHAR> tstringstream; // string in stream
    _TINT no;	//Just for debugging
    _TCHAR* hello(_TCHAR *file_name);	//prototype statement
    _TINT _tmain(_TINT argc, _TCHAR* argv[]){
        _tsetlocale(LC_ALL, _T("ja-JP"));	//locale is important, don't forget
        _TCHAR file_name[] = _T("% fullpath and filename here %");
        tcout << hello(file_name);
        tcin >> no;	// test use only, just for prevent close console window
        return 0;
    }
    //+---------- function-------------------------------------------+
    _TCHAR* hello(_TCHAR *file_name){
        // return and pass is both 'char pointer', it's important
        tstring s;	// string
        tstring ss;	// if you need formatted string, you can use 'tstringstream'
        FILE *fs;
        errno_t err;
        err= _tfopen_s(&fs, file_name, _T("rt, ccs=UNICODE"));
            // open err
            if (err != 0){
    	    return _T("fail not open that file");	//takecare, file exist?
    	}
    	else{
    	    // success open file
    	    tifstream ifs(fs);	// make a filestream
    	    while (ifs >> s){	// you don't need use 'getline' method
    	 	ss += s;	// just for string case. if you want to use stream...
     		// ss << s;	// like this.
      	    }
    	    tcout << ss;	//just for this test, strip this line when you copy code.
    	_TCHAR out[1000]; //no intention this number, not too short and not too much
    		err = _tcscpy_s(out, 1000, ss.c_str());		//also above
    		if (err == 0){
    			static _TCHAR *outp = out;	//keep address for MQL4
    			return outp;
    		}
    		else return _T("copy fail");
    	}
    }
    [/cpp]

    Step1-2 Create MQL side code

    This method is an alternate method for Mr.amenbo’s.
    The interface of mql and dll is quite easy. If you put ‘string’ to dll, the mql send that as a pointer to that string to dll. Dll receives as it and then return pointer, and the mql takes that as a string with an arrow. So you don’t need to create a ‘call program’ as step3 in Mr.amenbo’s method.
    And there is one tip, ‘Alert’ method in mql does not work well, that title is ok, but contents may fail to draw the proper character.
    If you can correct that problem, please tell me how to do that.
    Partially, I choose the ‘MessageBoxW’ with windows API, imported by WinUser32.mqh.

    [cpp]
    //+------------------------------------------------------------------+
    //|                                                         test.mq4 |
    //|                               Copyright 2015, UHL Software Corp. |
    //|                            https://www.yamanouchi-katsura.jp/fx/ |
    //+------------------------------------------------------------------+
    #property copyright "Copyright 2015, UHL Software Corp."
    #property link      "https://www.yamanouchi-katsura.jp/fx/"
    #property version   "1.00"
    #property strict
    #include <stdlib.mqh>
    #include <WinUser32.mqh>
    #import "test.dll"
    	string hello(string);	//put filename type 'string' and get data as 'string' in facto pointer
    #import
    #property script_show_inputs
    //+------------------------------------------------------------------+
    //| Script program start function                                    |
    //+------------------------------------------------------------------+
    input string InpFilter="*";
    void OnStart(){
        string file_name;	//NTFS=unicode、FAT=sjis
        int    i=1;
        long search_handle=FileFindFirst(InpFilter,file_name);
        if(search_handle!=INVALID_HANDLE){
     	do{
    		ResetLastError();
    		FileIsExist(file_name);
    		//PrintFormat("%d : %s name = %s",i,GetLastError()==5018 ? "Directory" : "File",file_name);	//just for debug
    		i++;
    	}while(FileFindNext(search_handle,file_name));
    	//--- executional code ---
    	string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);	//search install path
    	file_name=terminal_data_path+"\\MQL4\\Files\\"+file_name;	//test pattern
    	//--- close search handle
    	//PrintFormat("fullpath in MQL4: %s",file_name);	//just for debug
    	string ret=hello2(file_name);
    	int flg=MB_ICONINFORMATION+MB_TOPMOST;
    	MessageBoxW(0,ret,ret,flg);		//I cannot get over the 'alert' problem, so I use a windowsAPI on user32.dll, see header file
    	//Alert(ret);		//You may see a error with charcter code probrem
    	FileFindClose(search_handle);
        }
        else Print("Files not found");
    }
    [/cpp]

    Step2 Create dll code

    Important note is just below;
    1) #define MT4_EXPFUNC __declspec(dllexport)
    2) __stdcall
    That is it.

    1) Copy the header and target function code from the full system create above.
    //+———- function——————————————-+
    _TCHAR* hello(_TCHAR *file_name){……

    2) Change that title of the target function below.
    MT4_EXPFUNC _TCHAR* __stdcall hello(_TCHAR *file_name){……

    3 Set build mode to ‘Release’, and select menu project>property>, and set ‘Structure Property>c++>code create-runtime library’ to ‘multiple sleds(/MT)’.

    4 Build it.

    You don’t need to create a module definition (.def) file. (at least on VC++2013? I’m not sure in facto… Please tell me, genius wizard)

    Step3 Test!!

    Did you make it?
    If you missed it, let’s work harder. Please leave a message to this article.