callmekohei's blog

callmekoheiのひとりごと

MQL on Vim ( VimでMQLをかいてみる )

f:id:callmekohei00:20180208173913g:plain

Summary

MQLという言語をVimで書いて実行する環境を作ってみました〜

MQLとはMetaTraderというソフトの言語です

Thanks

@haxe

@matthn

@raa0121

Environment

nvim$ sw_vers 
ProductName:    Mac OS X
ProductVersion: 10.13.3
BuildVersion:   17D47

nvim$ wine --version
wine-3.0

nvim$ mono --version
Mono JIT compiler version 5.4.1.6 (tarball Mon Dec 11 14:59:42 GMT 2017)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           normal
    SIGSEGV:       altstack
    Notification:  kqueue
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug 
    LLVM:          supported, not enabled.
    GC:            sgen (concurrent by default)


nvim$ wine cmd
Microsoft Windows 10.0.15063 (3.0)

Z:\Users\callmekohei\.config\nvim>

MetaEditorに F5 を送る

こんな感じ

F#で書いてます

// file name is abc.fsx

open System.Runtime.InteropServices
open System.Windows.Forms

[<DllImport "user32.dll">]
extern nativeint FindWindow(string className, string windowName)

[<DllImport "user32.dll">]
extern bool SetForegroundWindow(nativeint hwnd)

FindWindow("MetaQuotes::MetaEditor::5.00", null) |> SetForegroundWindow |> ignore
SendKeys.Send "{F5}"

Quickrunの設定

こんな感じ

 let g:quickrun_config.mql4 = {
        \  'exec': [ '%c %o %s:p:t' ]
        \ ,'command':'bash'
        \ ,'cmdopt' :'$HOME/tmp/quickrunMQL/quickrunMQL.bash'
    \}

foo.bash

^Mは ctrl V , ctrl M で入力する

# ===========================================================================
#  FILE    : mql
#  AUTHOR  : callmekohei <callmekohei at gmail.com>
#  License : MIT license
# ===========================================================================

file=$1
MetaTraderHOME=("$WINEPREFIX/drive_c/Program Files/OANDA - MetaTrader")
MetaEditor=("${MetaTraderHOME[@]}"/metaeditor.exe)
SendsKeyCMD=$(cd $(dirname $0) && pwd)/quickrunMQL

wine "${MetaEditor[@]}" /s /log:foo.log /compile:$file 2>/dev/null
iconv -f utf-16 -t utf-8 foo.log | sed -e "s/^M//g" > bar.log

echo "───── MetaEditor Compiler ─────"
cat bar.log

if cat bar.log | fgrep 'Result 0 error(s), 0 warning(s)' 1>/dev/null ; then

    echo "───── MetaTrader Terminal ─────"
    echo $SendsKeyCMD | wine cmd 1>/dev/null
    echo $SendsKeyCMD | wine cmd 1>/dev/null
    echo $SendsKeyCMD | wine cmd 1>/dev/null
    cat "${MetaTraderHOME[@]}"/MQL4/Logs/$(date +"%Y%m%d").log | tail -4 | sed -e "s/\\^M//g"

fi

rm foo.log
rm bar.log

課題

とりあえず動く、という程度なのでもっと洗練させたい