MQL5で#importがうまく使えません。

 

下に日本語あります。

Hi, everyone!


I started to use MT5 and MQL5.
I had a trouble in using #import.

The code of Libraries\import_test.mq5 is as below.

#property library
#property copyright "---"
#property link      "https://www.mql5.com"
#property version   "1.00"

void import_test(void) export
{
   Print("SUCCEEDED");
}

And the code of Indicators\TEST.mq5 is as below.

#property copyright "---"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window

#property indicator_buffers 1
#property  indicator_plots 1

#import "import_test.ex5"
   void import_test(void);
#import

int OnInit()
  {
    import_test();
    return(INIT_SUCCEEDED);
  }
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   return(rates_total);
  }

I compiled each code.

There is no problem in compiling import_test.mq5.

After I got import_test.ex5, I tried to compile TEST.mq5.

Then I had a error.

The error massage is : ')' - undeclared identifier.

And the message is given to 15th line of TEST.mq5, namely 'import_test();' which is inside OnInit function.


Why the compiling is failed?

I never had such problem while using MT4 and MQL4.

I read MQL5 Reference, but I can't find out big difference between MQL5 and MQL4 with using #import.

日本語と英語でフォーラムが分かれているのに気が付きませんでした。

上のコードがライブラリ内にあり、下のコードがIndicatorフォルダの中にあるのですが、#importをつかってインポートできません。

MQL4を使用したときには、問題なくインポートは使えていて、MQL5のリファレンスを読んでも、#importの使い方については、ほとんど変わりがないように思えます。

なぜ、うまくいかないのでしょうか?

 

括弧内になぜ void が入っているんですか?

括弧内を空にしたらうまくいかない?

この質問は テクニカル指標 に投稿すべきです。
MQL5フォーラム: テクニカル指標
MQL5フォーラム: テクニカル指標
  • www.mql5.com
MQL5言語でユーザーにより開発されたテクニカル指標はここでディスカッションされます
 
Nagisa Unada:

括弧内になぜ void が入っているんですか?

括弧内を空にしたらうまくいかない?

この質問は テクニカル指標 に投稿すべきです。

ご返答ありがとうございます。

投稿先の件、大変失礼いたしました。今後気を付けます。

先程、自力で解決いたしました。

voidは関係ないと思います。

どうやら、ファイル名と関数名が一致した場合、コンパイルに失敗するようです。ファイル名がimport_testだとすると、関数名は import_test123などとしないといけないようです。

MT4をアンインストールしてしまったので、すぐに確認できませんが、たしか、MQL4にはそんな制約はなかったはずです。

これは MQL5のバグだと思います。

理由: