LAMP server on VPS test install manual (5)

Caution: This instruction does not consider strict security. You must know much more to keep proper security for publication to world-wide. So I recommend this server constructed here should be used for your personal practice how to make web server. If you want to know more, the related links below will be your help.

5. Security install

http://www.clamav.net/lang/en/ ClamAntiVirus
https://github.com/vrtadmin/clamav-faq/raw/master/manual/clamdoc.pdf Manual(pdf)
https://www.adminsys.ch/2015/08/21/installing-clamav-epel-centosred-hat-7-nightmare/ Last resort
https://cisofy.com/ Lynis security solution investigator

#ClamAntiVirus

yum -y install clamav clamav-scanner-systemd clamav-update
	#Note: installed by dependency > -data,-lib,-filesystem -scanner -server -server-systemd

	#selinux setting
setsebool -P antivirus_can_scan_system on
setsebool -P clamd_use_jit on

ln -s /etc/clamd.d/scan.conf /etc/clamd.conf

cp /etc/clamd.d/scan.conf /etc/clamd.d/scan.conf.bak
vi /etc/clamd.d/scan.conf
	#Example
	#^ comment out
	LogFile /var/log/clamd.scan
	ExcludePath ^/sys/
	#^remove

cp /etc/freshclam.conf /etc/freshclam.conf.bak
vi /etc/freshclam.conf
	#Example

vi /etc/cron.d/clamav-update
	#Example of job definition: every ------>
	# .---------------- minute (0 - 59)
	# |  .------------- hour (0 - 23)
	# |  |  .---------- day of month (1 - 31)
	# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
	# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
	# |  |  |  |  |
	# *  *  *  *  * user-name  command to be executed
	  0  */3  *  *  * root /usr/share/clamav/freshclam-sleep	#you can change time and date

cp /etc/sysconfig/freshclam /etc/sysconfig/freshclam.bak
vi /etc/sysconfig/freshclam
	# comment (#remove me line)

chmod g+w -R /var/run/clamd.scan
freshclam	#create data base

systemctl  enable clamd@scan
	# automated; ln -s /usr/lib/systemd/system/clamd@scan.service /etc/systemd/system/multi-user.target.wants/clamd@scan.service

systemctl  start clamd@scan
systemctl  status clamd@scan

#Test from command line>
clamdscan -c /etc/clamd.d/scan.conf --fdpass /var/log/*
	#scan daemon already work on your system check /var/log/message

#Firewall

firewall-cmd --get-zones
	block dmz drop external home internal public trusted work
firewall-cmd --get-services
	RH-Satellite-6 amanda-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns freeipa-ldap freeipa-ldaps freeipa-replication ftp high-availability
	http https imaps ipp ipp-client ipsec iscsi-target kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mountd ms-wbt mysql nfs ntp openvpn pmcd
	pmproxy pmwebapi pmwebapis pop3s postgresql proxy-dhcp radius rpc-bind rsyncd samba samba-client smtp ssh telnet tftp tftp-client
	transmission-client vdsm vnc-server wbem-https
firewall-cmd --get-icmptypes
firewall-cmd --list-all-zones
firewall-cmd --list-services --zone=public

#Lynis

cd /etc/yum.repos.d
vi cisofy-lynis.repo
	[lynis]
	name=CISOfy Software - Lynis package
	baseurl=https://packages.cisofy.com/community/lynis/rpm/
	enabled=1
	gpgkey=https://packages.cisofy.com/keys/cisofy-software-rpms-public.key
	gpgcheck=1
yum makecache fast
yum -y install lynis

lynis audit system
	#Run as root
	#maybe later ok

du -ach /home
	# total size of that directory

modinfo
	#module information viewer

LAMP server on VPS test install manual (4)

Caution:This instruction does not consider strict security. You must know much more to keep proper security for publication to world wide. So I recommend this server constructed here should be used for your personal practice how to make LAMP(linux-apache-mysql-perl,php,python) web server. If you want to get farther knowledge, visit the related links suggested below. Those would be good help for you.

4. Setting System Control Tool

http://www.openlmi.org/ OpenLMI

#Add repository

yum -y install epel-release

yum -y install openlmi-scripts*

firewall-cmd --add-port 5989/tcp --permanent
firewall-cmd --reload

systemctl enable tog-pegasus.service
	#symbolic link has been updated.
systemctl start tog-pegasus.service
systemctl -l status tog-pegasus.service
	#You might be warned because you don't have ssl settings yet.
	#systemctl works at low level, so need more security.
	#c.f.

firewall-cmd --get-zones
firewall-cmd --get-services

lmi
	lmi> hwinfo;	#Get hardwear information
	lmi> system;	#Get system information

#Tips for TeraTerm users

You can be more comfortable for teraterm command line and ttmacros. e.g.

One click auto connect( Be careful, the easier the leakier, secret key and pass… )
shell “C:\Program Files (x86)\teraterm\ttermpro.exe” <your url or ip of ssh server >:\<port number> /ssh /2 /auth=publickey /user=<your user> /keyfile=”Path/to/private_key/file” /passwd=”\<your password>”.

Auto login and su root
shell “C:\Program Files (x86)\teraterm\ttpmacro.exe” /V login.ttl

login.ttl

hostname = '<your host url or ip>'
sshport ='<ssh port>'
Username = '<user>'
Userpass ='<user password>'
Rootpass ='<root password>'

msg = hostname
strconcat msg ':'
strconcat msg sshport
strconcat msg ' /ssh /2 /auth=publickey /user='
strconcat msg Username
strconcat msg ' /keyfile="C:\Program Files (x86)\teraterm\id_rsa" /passwd='
strconcat msg Userpass

connect msg

; set username
UserPrompt = '$'
RootPrompt = '#'
PasswordPrompt = ':'
timeout = 30

; login
wait   UserPrompt
sendln 'su root'

wait   PasswordPrompt
sendln Rootpass

wait RootPrompt
sendln 'cd'

; OK, auto login complete. current dir = /root

exit

LAMP server on VPS test install manual (3)

Caution: This instructions do not consider strict security. You must know much more to keep proper security for publication to world wide. So I recommend this server constructed here should be used for your personal practice how to make LAMP(linux-apache-mysql-perl,php,python) web server. If you want to get farther knowledges, visit related links suggested below. Those would be good help for you.
Note: Placeholders are signed as < ..data.. >. you must fill your data. […] sign as key input.

3. AntiVirus and Security check install

http://www.clamav.net/lang/en/ ClamAntiVirus
https://github.com/vrtadmin/clamav-faq/raw/master/manual/clamdoc.pdf Manual(pdf)
https://www.adminsys.ch/2015/08/21/installing-clamav-epel-centosred-hat-7-nightmare/ Last resort
https://cisofy.com/ Lynis security solution investigator

### Add repository ###

yum -y install epel-release

### ClamAntiVirus ###

yum -y install clamav clamav-scanner-systemd clamav-update
	#other packages than above automated to be installed by dependency.

vi /etc/clamd.d/scan.conf
	#Example
	#^ comment out
	ExcludePath ^/proc/
	ExcludePath ^/sys/
	LocalSocket /var/run/clamd.scan/clamd.sock
	#^remove

vi /etc/freshclam.conf
	#Example
	# Send the RELOAD command to clamd.
	# Default: no
	NotifyClamd /etc/clamd.d/scan.conf

vi /etc/cron.d/clamav-update
	#Example of job definition: every ------>
	# .---------------- minute (0 - 59)
	# |  .------------- hour (0 - 23)
	# |  |  .---------- day of month (1 - 31)
	# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
	# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
	# |  |  |  |  |
	# *  *  *  *  * user-name  command to be executed
	  0  */3  *  *  * root /usr/share/clamav/freshclam-sleep	#you can change time and date

vi /etc/sysconfig/freshclam
	# comment (#remove me line)

chmod g+x -R /var/run/clamd.scan
chmod g+rw /var/run/clamd.scan/clamd.sock

	#selinux setting
setsebool -P antivirus_can_scan_system on
setsebool -P antivirus_use_jit on

systemctl enable clamd@scan
	# automated; ln -s /usr/lib/systemd/system/clamd@scan.service /etc/systemd/system/multi-user.target.wants/clamd@scan.service

systemctl restart clamd@scan

systemctl -l status clamd@scan

### load and refresh database ###

freshclam	#create data base

### Test scan from command line> ###
clamdscan -c /etc/clamd.d/scan.conf --fdpass /var/log/*
	#scan daemon already work on your system check /var/log/message

### Lynis ###

vi /etc/yum.repos.d/cisofy-lynis.repo
#--- cisofy-lynis.repo ------------------
[lynis]
name=CISOfy Software - Lynis package
baseurl = https://packages.cisofy.com/community/lynis/rpm/
enabled=1
gpgkey = https://packages.cisofy.com/keys/cisofy-software-rpms-public.key
gpgcheck=1
#----------------------------------------end

yum makecache fast

yum -y install lynis

lynis audit system
	#Run as root
	#maybe later ok

result Files:
– Test and debug information : /var/log/lynis.log
– Report data : /var/log/lynis-report.dat

#Some fixation
#change umask(optional)
It will be good for security, but may cause some trouble when installing some kind of apprication.

cp /etc/profile /etc/profile.d/custom.sh
vi /etc/profile.d/custom.sh
	if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
	    umask 007
	else
	    umask 027
	fi

#chage
if more security chage -E, -I -W …
at leaset…

vi /etc/login.defs
	PASS_MAX_DAYS   <your choice propery>
	PASS_MIN_DAYS   <your choice without 0>
	PASS_MIN_LEN    <your choice over 8 recommended>

#blacklisted unuse modules

vi /etc/modprobe.d/blacklist-devices.conf
blacklist firewire-core
blacklist soundcore
blacklist dvb_usb
blacklist dvb_usb_v2
blacklist usb-storage

modprobe --showconfig | grep blacklist

#ban banner info

vi /etc/postfix/main.cf
	smtpd_banner = $myhostname ESMTP

vi /etc/php.ini
	expose_php = Off
	allow_url_fopen = Off

#others

vi /etc/profile
	002->007
	022->027

leadtime 30min

LAMP server on VPS test install manual (2)

Caution: This instructions do not consider strict security. You must know much more to keep proper security for publication to world wide. So I recommend this server constructed here should be used for your personal practice how to make LAMP(linux-apache-mysql-perl,php,python) web server. If you want to get farther knowledges, visit related links suggested below. Those would be good help for you.
Note: Placeholders are signed as < ..data.. >. you must fill your data. […] sign as key input.

2. SSH secure console set

http://www.vim.org/ Vim
http://hp.vector.co.jp/authors/VA016670/unix/vi_reference.html vi commands(jp)
http://www.oualline.com/vim-book.html Vim Tutorial and Reference _PDF_
http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml IANA Service Name and Transport Protocol Port Number
https://selinuxproject.org/page/Main_Page SELinux project
http://freecomputerbooks.com/books/The_SELinux_Notebook-4th_Edition.pdf SElinux textbook

On VNC panel>

https://cp.myvps.jp/Home.aspx Onamae Home
root login

#update system

yum update
	#===wait for a while===

Note: VNC browser view is uncomfortable because of not working cut and paste with Windows clipboard, that You would be better to create SSH connect as soon as possible.

On Client>

Connect by password auth(temporally).
TeraTermPro ; at Windows e.g.
shell “C:\Program Files (x86)\teraterm\ttermpro.exe”
Host: <your vps host ip or name>
Port:22
User: <wheel user id> temporally connection with root and pass
Password authentication.
You can login with your user not root.

login: <root id>
Password:<root password>
wheel user was set before, when the OS was installed.

### VIM setting ###
cd ~

vi .vimrc
#—.vimrc——-
set nocompatible
set fileformats=unix,dos
set history=50
set number
set list
set showmatch
syntax on
highlight Comment ctermfg=LightCyan
set wrap
#—————-end

### CF Check volumes and partations ###

yum -y install system-storage-manager

ssm list

### change wheel user policy ###

cd /etc/pam.d
cp su su.bak
vi su
  auth       required     pam_wheel.so use_uid
  #↑ comment out
  #vi command : move cursor to target and press [x] [ESC] then type [:wq]

### make sshd_config secure to change well known port ###
Check the IANA website and see the “Service Name and Transport Protocol Port Number Registry”.
You may choose new port number for your ssh connect from 32768 to 61000(linux ready private number). Other number may be OK, but that must be checked conflict against known port number.

### change port ###

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak	#save original file

vi /etc/ssh/sshd_config
	Port <new ssh port>
	#vi command:enter [i] and move cursor to target and hit key your number
	#[ESC] then type [:wq] if you make miss, you can recover hit [ESC][u]
	#learn how to use vim at vim tutor.

### selinux confirm enforcing and set new port ###

sestatus
vi /etc/selinux/config
	SELINUX=enforcing;	#Do Not choose permissive or disabled

yum install policycoreutils-python
semanage port -a -t ssh_port_t -p tcp <new ssh port>
	#The new ssh port number must not be maced other preset port

### firewalld ###

cp /usr/lib/firewalld/services/ssh.xml /etc/firewalld/services/ssh.xml
vi /etc/firewalld/services/ssh.xml
	port=<new ssh port>

firewall-cmd --reload
systemctl restart sshd
systemctl -l status sshd	#check the port number had been changed

### key generate ###

vi /etc/ssh/sshd_config
	#HostKey /etc/ssh/ssh_host_key
	#HostKey /etc/ssh/ssh_host_ecdsa...
	#HostKey /etc/ssh/ssh_host_ed255...
		#It would be better, 
                   that you comment-out all the way of authentications except RSA key.
	LogLevel verbose
	#PermitRootLogin no    #end of this chapter, you must remove #
	MaxAuthTries 2
	MaxSessions 4
	RSAAuthentication yes
	PubkeyAuthentication yes
	PasswordAuthentification no
	#GSSAPIA.......
	#GSSAPIC.......
	#X11Forwarding
	Banner none

cd	#root home
mkdir .ssh
cd .ssh
ssh-keygen
	$Enter...save the key(...id_rsa): [enter]
	$Enter passphrase... <key password>
	#id_rsa(private key), id_rsa.pub(public key)  is generated in directory of /root/.ssh

mkdir /home/<your user id>/.ssh

cd id_rsa.pub /home/<your user id>/.ssh/authorized_keys
	# Change the public key name along with the sshd_config, and copy for login-user.
        # By SSHSCR Receive [/root/.ssh/id_rsa]  to [proper directory local PC] e.g "C:\Program Files (x86)\teraterm"

rm -fR /root/.ssh    #you don't need root .ssh, invalid root login at this sshd.

firewall-cmd --reload

systemctl restart sshd

systemctl -l status sshd
        #check the port number had been changed
	#remain keep this connect and

### New connection ###
On Client>
TeraTermPro: login:++id_rsa(key)
#if success this key connection, you can close 1st and 2nd TeraTermPro safely.

### Setting root mail transparent ###

vi /etc/aliases
	# Person who should get root's mail
	#root:          marc
	   #| comment off and change 'marc' to your e-mail address
	root:             i@<ip>.jp

newaliases

echo test | mail root
    #If you find mail from "root@<ip>", that would be success settings.

### Setting auto update ###

yum -y install yum-cron yum-utils

vi /etc/yum/yum-cron.conf
	apply_updates = yes
	#Do not do this before yum update, it may fail of dependency.

vi /etc/cron.daily/0yum-daily.cron

vi /etc/yum/yum-cron-hourly.conf
vi /etc/cron.hourly/0yum-hourly.cron

systemctl start yum-cron
systemctl enable yum-cron
systemctl restart yum-cron
systemctl -l  status yum-cron

### update system ###

yum -y update

### Note Result ###

cat /etc/passwd > p.txt
yum list installed > y.txt
journalctl > f.txt
	save to client
reboot

lead-time 30min

LAMP server on VPS test install manual (1)

Caution: This instructions do not consider strict security. You must know much more to keep proper security for publication to world wide. So I recommend this server constructed here should be used for your personal practice how to make LAMP(linux-apache-mysql-perl,php,python) web server. If you want to get farther knowledges, visit related links suggested below. Those would be good help for you.
Note: Placeholders are signed as < ..data.. >. you must fill your data. […] sign as key input.

0. Introduction

Onamae.com VPS(KVM) plan
Virtual 2 core cpu and 1GB memory 20GBHDD+80GBHDD(scarable)

Install planning

  1. OS install
  2. SSH secure console set
  3. Antivirus and security check
  4. Secure Web (Openssl,MariaDB,Apache,Perl)
  5. PHP
  6. Domain and SSL authorized certification
  7. phpMyadmin
  8. CakePHP
  9. WordPress
  10. AIDE
  11. Running System

1. OS install

Download latest OS image from official site. https://www.centos.org/
The full contents version has oversize for DVD.
Upload the image to vps provider’s storage, follow the instruction.

Note:Mouse does not work on Google Chrome. You need FireFox web browser. e.g, path at Windows
shell “C:\Program Files (x86)\Mozilla Firefox\firefox.exe” https://cp.myvps.jp/Home.aspx

Control Panel >
Server List >kvm************ [click]
Power Off (Confirm stop power)
OS re-install tab
OS:[custom OS] > pull down the list and the last one is the latest you uploaded.
Semi-virtual driver (virtio) [on]
VNC console key map [ja]
video [vmvga]
Disks [Custom][100GB] <expand, partationing is auto set
> [confirm] >[execute] >[return to server list] >[power on]
>Power on ready? [yes]
Server list >kvm************ [click]
See console view
click and start [click]
Next view get from the icon right above
[Enter] to start install

The installer view >
keyboard [Japanese] #pick by ‘j’
Selected install device Basic expanded to 80GB+20GB
It’s ok with default set.
If you know about linux filesystem, I reccomend to create customized partation like this;
pool name = <you like …>
filesystem = xfs
partations = / , /var , /tmp, /home (each size would be your choice within your VPS limitation)
/boot and /swap should be remained default.

KDUMP off
Selected software as webserver(MariaDB,perl,php,python) + developer
Enabling the network connection

>[Start Installer]
root pass <root password>
create user <your id > to be administrator pass <your-ids password>
===wait for a while(about 30 min)===
Reboot [click]
reject customOS disk [click]
Forced reject the install disk from check box at the top of view.
When the progress bar is displayed and, is showed the login : prompt, you made success install.
enter your user and pass, try login.

login: <your user>
Password:<your pass>
$ su root
Password:<root pass>
# prompt changed

lead time 60-90min(depends on network speed)

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 made an MetaTrader4 platform on the virtual private server(VPS-KVM) provided by “ONAMAE.com”.
This server has such specs below;
-CPU : shared virtual Core2DuoT7700 2.4Ghz
-MEMORY : 1GB
-STORAGE : HDD 20GB + 80GB
-RENDERER : Gallium 0.4 on llvmpipe (LLVM 3.8, 128 bits)

You can jump to “onamae.com” web site, and make a contract of smallest size VPS(KVM) that has memory size 1GB.  Don’t select any bigger one.  You don’t need higher spec over 2GB memory for this aim, in this case to install and run the MetaTrader4 and some related programs.
Then you can get “Login ID” and “Password” of your VPS, go to the login page “https://cp.myvps.jp/”, and start your control panel.
Click the VPS name field (for example “kvm00XXXXXX”).

2016-05-13-3-1

 

1  Installation of Operating System and some others
Next, you have to install Operating System, desktop manager, and WINE Windows(R) compatibility layer program.
I would recommend “lubuntu” the lighter version of “Ubuntu”.
The reasons are ;
– Light weight action and less memory use
– Support the Ubuntu kernel and WINE package.
Well, Let’s start installation processes.

1) First, you have to visit “lubuntu” web site, and download the latest “-.iso” image file. Do not download Japanese localized version, since save memory. In this case, you cannot use Japanese IME at your VPS.
2) Then, enter userID and password to open the control panel of your VPS,

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

3) The “-.iso” file previously downloaded must be inserted to the special “image” folder of common server at ONAMAE.COM. You can use “WinSCP(SFTP software for Windows)“. If you are using the other Operating System, you can use your SFTP client suited your OS).
4) At your WinSCP, Select “New Site” > SFTP , and fill Host name > User name > 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 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 login button on the WinSCP.

2016-05-13-5
key to ppk

5) After copying iso image into server, You have to go back to 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 install menu. Follow the instructions of installer. Nothing will be bothering you while the installing process.
The installer show a restart order on-screen. You have to remove force the iso image. After that, hit the “restart” button again.
If you complete process, the lubuntu desktop will appear on-screen.  Resolution can be changed from menu > Preferences > Monitor Settings.
Are you ready?
So, Let’s go 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 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 original Expert Adviser or Indicator etc already, it would be better to install SSH and FTP server on your VPS. Let’s try 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 security problem, so you must install   firewall.
I recommend “WinSCP” as client for Windows.

There is one difference between .iso loading process and after OS installed.
If you installed OS from your own uploaded .iso file, you don’t have to hit the “Settings” button. You could find SSH > “Permission” at menu tree on the left. However, You can connect by password, so you don’t need 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 have also security risk, so you must install firewall.
I recommend “TeraTerm” as client for Windows.

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

That’s all from me.
If you need more information, please search from 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
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 absorb the spreads variable. when it is false, bar price is displayed as supplied price by your fx broker.

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

Thank you.

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 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://cx5software.com/article_vcpp_unicode/ 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 file handle
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.
The step 1 is same as original idea, so let’s begin.
I wrote ‘test.cpp’ as my solution name, but you can change as you like, within coding regulations.
‘%…%’ mean replace proper string.
Many impressive site are exist, but difficult for beginners. My comments in the .cpp code below might be helpful for your .dll coding for MQL4. Because I spend huge 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 question, please comment to this message. I don’t receive any e-mail from 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++

// test.cpp : Test for Console application for MT4
#include &quot;stdafx.h&quot; // you need add other header below in this headerfile
// #include &quot;targetver.h&quot;
// #include &lt;tchar.h&gt;
// #include &lt;locale&gt;
// #include &lt;string&gt;
// #include &lt;fstream&gt;
// #include &lt;iostream&gt;
// #include &lt;stdexcept&gt;
// #include &lt;limits&gt;
#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&lt;_TCHAR&gt; tstring;
typedef std::basic_ifstream&lt;_TCHAR&gt; tifstream; // file in stream
typedef std::basic_stringstream&lt;_TCHAR&gt; 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(&quot;ja-JP&quot;)); //locale is important, don't forget

    _TCHAR file_name[] = _T(&quot;% fullpath and filename here %&quot;);
    tcout &lt;&lt; hello(file_name);
    tcin &gt;&gt; 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(&amp;fs, file_name, _T(&quot;rt, ccs=UNICODE&quot;));

// open err
if (err != 0){
    return _T(&quot;fail not open that file&quot;); //takecare, file exist?
}
else{
    // success open file
    tifstream ifs(fs); // make a filestream
    while (ifs &gt;&gt; s){ // you don't need use 'getline' method
        ss += s; // just for string case. if you want to use stream...
        // ss &lt;&lt; s; // like this.
}
tcout &lt;&lt; ss; //just for this test, strip this line when you copy to dll 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(&quot;copy fail&quot;);
}
}

Step1-2 Create MQL side code

This is an alternate method on 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 receive as it, and then return pointer, and the mql take that as string with pointer. So you don’t need create ‘call program’ as step3 in the Mr.amenbo’s method.
And there is one tip, ‘Alert’ method in mql do not work well, that title is ok, but contents may fail to draw 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.

//+------------------------------------------------------------------+
//| test.mq4 |
//| Copyright 2015, UHL Software Corp. |
//| https://www.yamanouchi-katsura.jp/fx/ |
//+------------------------------------------------------------------+
#property copyright &quot;Copyright 2015, UHL Software Corp.&quot;
#property link &quot;https://www.yamanouchi-katsura.jp/fx/&quot;
#property version &quot;1.00&quot;
#property strict
#include &lt;stdlib.mqh&gt;
#include &lt;winuser32.mqh&gt;
#import &quot;test.dll&quot;
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=&quot;*&quot;;
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(&quot;%d : %s name = %s&quot;,i,GetLastError()==5018 ? &quot;Directory&quot; : &quot;File&quot;,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+&quot;\\MQL4\\Files\\&quot;+file_name; //test pattern
    //--- close search handle
    //PrintFormat(&quot;fullpath in MQL4: %s&quot;,file_name); //just for debug
    string ret=hello2(file_name);
    int flg=MB_ICONINFORMATION+MB_TOPMOST;
    MessageBoxW(0,ret,ret,flg); //I cannot solve the 'alert' problem, so I use a windowsAPI on user32.dll, see header file
    //Alert(ret); //You may see an error with character code problem
    FileFindClose(search_handle);
    }
    else Print(&quot;Files not found&quot;);
}

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 full code create above.
//+———- function——————————————-+
_TCHAR* hello(_TCHAR *file_name){……

2) Change that title of target function to 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 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.