2018年5月13日日曜日

[MT4] ExpertsEnable は機能していない?

@ MetaTrader 4 Version 4.00 build 1090

[MetaTrader 4](https://www.metatrader4.com) には config ファイルを指定して起動する機能がありますこの機能を使うと、自動で Strategy Tester を走らせたりできる。

> 参考
>
> [Configuration at Startup - Tools - MetaTrader 4 Help](https://www.metatrader4.com/en/trading-platform/help/service/start_conf_file)

2018年5月12日土曜日

[MT4] 気配値表示ウィンドウにスプレッドを表示する方法

気配値表示ウィンドウ内で右クリック

スプレッドを選択
`!` がスプレッドになります
その他、「高値」・「安値」・「時間最後の tick 時間」の表示も出来ます。 このスプレッドの単位は point なので注意しましょう。 > 参考 > > [[MT4] pips とpoint の使い分け](https://strategyofc.blogspot.com/2018/05/mt4-pips-point.html)
2018年5月11日金曜日

[MT4] pips とpoint の使い分け

Metatrader の point(s) と pip(s) の使い分け方について私見ですが書いてみようと思います。

まずは簡単に違いから。

> 詳しい違いについては以下を参考にしてください
>
> [MT4のpoint(ポイント)とpips(ピップス)の違い | MT4ラボ|メタトレーダーの使い方/EA・インジケーター検証](http://mt4.click/chart_sosa/point_pips_chigai/)

2018年5月10日木曜日

[MQL4] SELECT_BY_POS のソート順は保証されていない

[OrdersHistoryTotal()](https://docs.mql4.com/trading/ordershistorytotal) のドキュメントに以下のような記述があります。

> Consecutive selection of orders using the SELECT_BY_POS parameter returns information in the sequence in which it was received from the trading server. Sorting of the resulting list of orders cannot be guaranteed.

最後にさらりと、「ソート順は保証されていません」と書いてあるではないですか。

つまり、直近の履歴だけを見たい場合でも、最低1回はループを回さないといけないわけですね。

そりゃ、「口座履歴」タブで取得期間を絞っておく必要があるわけだ。

> 参考
>
> [[MQL4] OrderHistoryTotal() は口座履歴タブで設定した期間しか取得できない](https://strategyofc.blogspot.com/2018/05/mql4-orderhistorytotal.html)

[MQL4] OrderHistoryTotal() は口座履歴タブで設定した期間しか取得できない

[OrdersHistoryTotal()](https://docs.mql4.com/trading/ordershistorytotal) のドキュメントに以下のような記述があります。

> The number of closed orders in the account history loaded into the terminal. The history list size depends on the current settings of the "Account history" tab of the terminal.

つまり、"Account history"(口座履歴)タブの設定によって取得できるリストの期間が異なるとのこと。

2018年5月9日水曜日

[MQL4] オーダー約定時刻からの足の本数を求める方法

### オーダー約定時刻からの時間を求める
オーダー約定時刻からの時間は [OrderOpenTime()](https://docs.mql4.com/trading/orderopentime) と [TimeCurrent()](https://docs.mql4.com/dateandtime/timecurrent) の差分で求められます。
なお、OrderOpenTime() を実行する前には [OrderSelect()](https://docs.mql4.com/trading/orderselect) で対象の Order を指定しておく必要があります。

```mq4
// OrderSelect() は実行済みとする
long diff = TimeCurrent() - OrderOpenTime();
printf("%lld", diff); // 約定時刻からの秒
```

この値は**秒**で求められます。

> 参考
>
> [[MQL4] datetime を long にキャストすると 1970/1/1 からの秒になる | Strategy of C](https://strategyofc.blogspot.com/2018/05/mql4-datetime-long-197011.html)

この時、土日に入っている場合は [TimeCurrent()](https://docs.mql4.com/dateandtime/timecurrent) が正確ではない可能性があるので注意が必要です。

> 参考
> 
> [[MQL4] TimeCurrent() は土日の間は更新されない | Strategy of C](https://strategyofc.blogspot.com/2018/05/mql4-timecurrent.html)

2018年5月8日火曜日

[MQL4] TimeCurrent() は土日の間は更新されない

[TimeCurrent()](https://docs.mql4.com/dateandtime/timecurrent) のドキュメントに以下のような記述があります。

> Returns the last known server time,

`last known` ということは、実際のサーバータイムとは異なっている可能性もあるということです。