【问题标题】:Can't run a simple Expert Advisor with [ nquotes ] using Visual Studio 2015, MetaTrader Terminal 4无法使用 Visual Studio 2015,MetaTrader 终端 4 运行带有 [ nquotes ] 的简单智能交易系统
【发布时间】:2016-11-07 23:36:54
【问题描述】:

无法运行简单的专家顾问。 Wnd.dll - 来自“bin”文件夹的文件,使用 VS2015 创建。

Wnd.dll 文件位于正确的“MQL4\Libraries\”文件夹中。
所以我尝试在实时模式下运行此顾问,但没有任何反应。请帮助我做错了什么。

#property copyright "(c) 2012-2015 Brainroom Ltd."
#property link "http://www.nquotes.net"

#import     "nquotes/nquoteslib.ex4"
    int      nquotes_setup(                   string className, string assemblyName );
    int      nquotes_init();
    int      nquotes_start();
    int      nquotes_deinit();
    double   nquotes_on_tester();
    int      nquotes_on_timer();
    int      nquotes_on_chart_event(          int id, long lparam, double dparam, string sparam );

    int      nquotes_set_property_bool(       string name, bool     value );
    int      nquotes_set_property_int(        string name, int      value );
    int      nquotes_set_property_double(     string name, double   value );
    int      nquotes_set_property_datetime(   string name, datetime value );
    int      nquotes_set_property_color(      string name, color    value );
    int      nquotes_set_property_string(     string name, string   value );
    int      nquotes_set_property_adouble(    string name, double  &value[], int count = WHOLE_ARRAY, int start = 0 );

    bool     nquotes_get_property_bool(       string name );
    int      nquotes_get_property_int(        string name );
    double   nquotes_get_property_double(     string name );
    datetime nquotes_get_property_datetime(   string name );
    color    nquotes_get_property_color(      string name );
    string   nquotes_get_property_string(     string name );
    int      nquotes_get_property_array_size( string name );
    int      nquotes_get_property_adouble(    string name, double &value[] );
#import

int init()
{
    nquotes_setup( "Wnd.Wnd", "Wnd" );  // !!!!changed only this line (NULL, NULL) ->("Wnd.Wnd", "Wnd") 
    return ( nquotes_init() );
}

int start()
{
    return ( nquotes_start() );
}

int deinit()
{
    return ( nquotes_deinit() );
}

double OnTester()
{
    return ( nquotes_on_tester() );
}

void OnTimer()
{
    nquotes_on_timer();
}

void OnChartEvent( const int id, const long& lparam, const double& dparam, const string& sparam )
{
    nquotes_on_chart_event( id, lparam, dparam, sparam );
}

C# 代码如下所示:

using NQuotes;
namespace Wnd
{
    public class Wnd : MqlApi
    {

        public bool formCreated = false;
        public override int start()
        {
           if (formCreated == false)
           {
              Form form = new Form();
              form.Show();
              formCreated = true;

              Alert("Hello!");
            }
            return 0;
        }
    }
}

[更新]

Expert Wnd EURUSD,M15: removed EURUSD,M15: 50 tick events (3503 bars, 89656 bar states) processed (total time 0:00:05.390)
       Wnd EURUSD,M15: EA.deinit() nquotes_deinit()-> [0]
       Wnd OnTester returns 0.00000000000000
       Wnd EURUSD,M15: EA.OnTester() nquotes_on_tester()-> [ 0.0000000000]
Tester: stop button pressed
       Wnd EURUSD,M15: EA.start() nquotes_start()-> [0]
       Wnd EURUSD,M15: Alert: Hello!
       Wnd EURUSD,M15: EA.init() nquotes_init()-> [0]
       Wnd EURUSD,M15: EA.init() nquotes_setup()-> [0]
       Wnd test started 

【问题讨论】:

  • 您可能想知道,有人已经提议结束您的问题,因为 (cit.:) "寻求调试帮助的问题 ("为什么不此代码有效吗?") 必须包含所需的行为、特定问题或错误以及在问题本身中重现它所需的最短代码。没有明确问题陈述的问题是没有用的给其他读者。请参阅: 如何创建最小、完整和可验证的示例。”您可以利用此建议并阅读一些最佳实践建议提示。 无论如何,欢迎来到 StackOverflow 社区

标签: c# algorithmic-trading mql4 metatrader4 mt4


【解决方案1】:

欢迎来到 MQL4 的狂野世界!

问:我做错了什么?
答:到目前为止,调试工作为零。


如果遇到问题,首先检查并发布库/组件的版本,支持人员从.EX4 的商业供应商处收到的所有回复,并将发布的 API 压缩到极限interface-protocols 在您自己的调试工作中,以隔离 “Gdě Sabáka Zarýta”

/*
- MISSING .MQ4 VERSION NUMBER ( Build 982+ New-MQL4 )
- MISSING .EX4 VERSION NUMBER ( "nquotes/nquoteslib.ex4" )
- MISSING .DLL VERSION NUMBER
+ ALWAYS PUBLISH ALL THE COMPILER-MODE DIRECTIVES
  #property strict                                               // ?!
  AND ALL OTHER IMPORTANT DEFINITIONS OF THE .MQ4-FILE
====================================================================================
THESE ARE MORE IMPORTANT FOR DEBUGGING, THAN THE COMMERCIAL/COPY-{LEFT|RIGHT} REMARX
*/
int init(){
    int          aRetCODE = nquotes_setup( "Wnd.Wnd", "Wnd" );  // !!!!changed only this line (NULL, NULL) ->("Wnd.Wnd", "Wnd")
    PrintFormat( "EA.init() nquotes_setup()-> [%d]",
                 aRetCODE
                 );
                 aRetCODE = nquotes_init();
    PrintFormat( "EA.init() nquotes_init()-> [%d]",
                 aRetCODE
                 );
    return (     aRetCODE );                                   // return( nquotes_init() )
}

int start(){
    int          aRetCODE =  nquotes_start();
    PrintFormat( "EA.start() nquotes_start()-> [%d]",
                 aRetCODE
                 );
    return (     aRetCODE );                                   // return ( nquotes_start() );
}

int deinit(){
    int          aRetCODE =   nquotes_deinit();
    PrintFormat( "EA.deinit() nquotes_deinit()-> [%d]",
                 aRetCODE
                 );
    return (     aRetCODE );                                   // return ( nquotes_deinit() );
}

double OnTester(){
    int          aRetCODE =     nquotes_on_tester();
    PrintFormat( "EA.OnTester() nquotes_on_tester()-> [%23.10f]",
                 aRetCODE
                 );
    return (     aRetCODE );                                   // return ( nquotes_on_tester() );
}

void OnTimer(){
    int          aRetCODE =    nquotes_on_timer();
    PrintFormat( "EA.OnTimer() nquotes_on_timer()-> [%d]",
                 aRetCODE
                 );
//  nquotes_on_timer();
}

void OnChartEvent(          int     id,
                            long   &lparam,
                            double &dparam,
                            string &sparam
                            ){
    int          aRetCODE =         nquotes_on_chart_event();
    PrintFormat( "EA.OnChartEvent() nquotes_on_chart_event()-> [%d]",
                 aRetCODE
                 );
//  nquotes_on_chart_event( id, lparam, dparam, sparam );
}

依赖 .EX4 文件中已发布的 API/#import

#import     "nquotes/nquoteslib.ex4"
    int      nquotes_setup(                   string className, string assemblyName );
    int      nquotes_init();
    int      nquotes_start();
    int      nquotes_deinit();
    double   nquotes_on_tester();
    int      nquotes_on_timer();
    int      nquotes_on_chart_event(          int id, long lparam, double dparam, string sparam );

    int      nquotes_set_property_bool(       string name, bool     value );
    int      nquotes_set_property_int(        string name, int      value );
    int      nquotes_set_property_double(     string name, double   value );
    int      nquotes_set_property_datetime(   string name, datetime value );
    int      nquotes_set_property_color(      string name, color    value );
    int      nquotes_set_property_string(     string name, string   value );
    int      nquotes_set_property_adouble(    string name, double  &value[], int count = WHOLE_ARRAY, int start = 0 );

    bool     nquotes_get_property_bool(       string name );
    int      nquotes_get_property_int(        string name );
    double   nquotes_get_property_double(     string name );
    datetime nquotes_get_property_datetime(   string name );
    color    nquotes_get_property_color(      string name );
    string   nquotes_get_property_string(     string name );
    int      nquotes_get_property_array_size( string name );
    int      nquotes_get_property_adouble(    string name, double &value[] );
#import

【讨论】:

  • 感谢您的帮助。但是这个文件来自作者的例子,nquotes。
  • 这条信息既不能帮助也不能解释您的调试步骤。 你试过运行它吗? + 在编译阶段和运行时产生了什么结果(附上日志)
  • Expert Wnd EURUSD,M15: 移除 EURUSD,M15: 50 个分时事件(3503 个柱,89656 个柱状态)已处理(总时间 0:00:05.390) Wnd EURUSD,M15: EA.deinit() nquotes_deinit()-> [0] Wnd OnTester 返回 0.00000000000000 Wnd EURUSD,M15: EA.OnTester() nquotes_on_tester()-> [ 0.0000000000] 测试器: 按下停止按钮 Wnd EURUSD,M15: EA.start() nquotes_start()-> [0] Wnd EURUSD,M15:警报:您好! Wnd EURUSD,M15: EA.init() nquotes_init()-> [0] Wnd EURUSD,M15: EA.init() nquotes_setup()-> [0] Wnd 测试开始
  • 没有错误。甚至出现了窗口。但仅限于测试模式。
  • Wnd EURUSD,M10: EA.init() nquotes_init()-> [-4097] Wnd EURUSD,M10: 无效许可证。请切换到模拟帐户,或订购/延长许可证。问题解决了谢谢大家。
【解决方案2】:

除非您购买了库,否则 nquotes 包仅适用于演示帐户。整个解决方案进入存储您的项目的文件夹。这些项目通常是类库项目,并且需要一个可执行项目来调用 DLL。看起来您的文件位于错误的目录中。而不是在 c# 中编写的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    相关资源
    最近更新 更多