【问题标题】:MQL4 Indicator passing signal to EAMQL4 指标向 EA 传递信号
【发布时间】:2013-12-05 10:40:30
【问题描述】:

问题是,我想在指标发出信号时开单。我该怎么做?

我一直在尝试使用 iCustom(),但并不令人满意。

我尝试在指标中使用 GlobalVariableSet() 并在 EA 中使用 GlobalVariableGet() 方法,但无法正常工作。

请帮忙。

【问题讨论】:

    标签: indicator metatrader4 mql4


    【解决方案1】:

    syntax 是:

    double  iCustom(
       string       symbol,           // symbol
       int          timeframe,        // timeframe
       string       name,             // path/name of the custom indicator compiled program
       ...                            // custom indicator input parameters (if necessary)
       int          mode,             // line index
       int          shift             // shift
       );
    

    这是使用自定义鳄鱼指标的示例(在 MT 平台中默认应为 Alligator.mq4)。

    double Alligator[3];
    Alligator[0] = iCustom(NULL, 0, "Alligator", 13, 8, 8, 5, 5, 3, 0, 0);
    Alligator[1] = iCustom(NULL, 0, "Alligator", 13, 8, 8, 5, 5, 3, 1, 0);
    Alligator[2] = iCustom(NULL, 0, "Alligator", 13, 8, 8, 5, 5, 3, 2, 0);
    

    其中13, 8, 8, 5, 5, 3 是指标自身定义的自定义鳄鱼的相应输入参数:

    //---- input parameters
    input int InpJawsPeriod=13; // Jaws Period
    input int InpJawsShift=8;   // Jaws Shift
    input int InpTeethPeriod=8; // Teeth Period
    input int InpTeethShift=5;  // Teeth Shift
    input int InpLipsPeriod=5;  // Lips Period
    input int InpLipsShift=3;   // Lips Shift
    

    mode 是指标中定义的相应行索引:

    SetIndexBuffer(0, ExtBlueBuffer);
    SetIndexBuffer(1, ExtRedBuffer);
    SetIndexBuffer(2, ExtLimeBuffer);
    

    【讨论】:

      【解决方案2】:

      语法是:

      int signal = iCustom(NULL, 0, "MyCustomIndicatorName",
      ...parameters it takes in...,
      ...the buffer index you want from the custom indicator...,
      ...shift in bars);
      

      假设您编写了一个名为“myMA”的自定义移动平均线指标,它仅将一个周期作为其外部变量之一。该指标根据用户提供的时间段和每根柱线的收盘价计算简单的移动平均线。该指标将其计算值存储在数组 MAValues[] 中,该数组被分配给如下索引:SetIndexBuffer(0, MAValues);

      若要获得当前柱的周期为 200 的移动平均线,您可以这样写:

      double ma_current_bar = iCustom(NULL, 0, "myMA", 200, 0, 0);
      

      然后,一旦您有了这个值,您就可以根据您确定的一些交易标准对其进行检查,并在满足时开立订单。例如,如果您想在当前柱的移动平均线等于当前卖价的情况下开多头头寸,您可以这样写:

      if (ma_current_bar == Ask){
          OrderSend(Symbol(), OP_BUY, 1, Ask, *max slippage*, *sl*, *tp*, NULL, 0, 0, GREEN);
      }
      

      这只是示例代码,请勿在实时 EA 中使用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-07-11
        • 1970-01-01
        • 2015-12-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多