多时间帧指标的MQL4总结果

时间:2014-10-04 12:40:53

标签: metatrader4 mql4

晚上好,

任何人都可以告诉我如何从MTF指标获得总结果,例如MACD:

M1 =买入, M5 =卖出, M15 =卖出, M30 =买入, H1 =买入, H4 =买入, D1 =买入,

总结果= 5购买& 2卖

如何将其实现为MQL4代码?谢谢你的所有答案。

1 个答案:

答案 0 :(得分:1)

要考虑的示例代码:

start() {
    //--------------------------------------------
    // Get the MACD values for all time-frames
    //--------------------------------------------
    double vaiMACD[7];
    vaiMACD[0] = iMACD( Symbol(), PERIOD_M1, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
    vaiMACD[1] = iMACD( Symbol(), PERIOD_M5, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
    vaiMACD[2] = iMACD( Symbol(), PERIOD_M15, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
    vaiMACD[3] = iMACD( Symbol(), PERIOD_M30, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
    vaiMACD[4] = iMACD( Symbol(), PERIOD_H1, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
    vaiMACD[5] = iMACD( Symbol(), PERIOD_H4, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
    vaiMACD[6] = iMACD( Symbol(), PERIOD_D1, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
    //--------------------------------------------

    //--------------------------------------------
    // CALC: Total Buys/Sells
    //--------------------------------------------
    int viMACDSignalBuyCount  = 0;
    int viMACDSignalSellCount = 0;
    for( int viElement=0; viElement<ArrayRange(vaiMACD, 0); viElement++) {
        //-----------------------------------------------------------
        // Here, you need to define your own rules on what is considered as Buy/Sell signal.
        // My example here is a simple: >0 is Buy. <0 is Sell.
        //-----------------------------------------------------------
        if( vaiMACD[viElement]>0 )    viMACDSignalBuyCount  += 1;
        if( vaiMACD[viElement]<0 )    viMACDSignalSellCount  += 1;
    }
    //--------------------------------------------

    //--------------------------------------------
    // Display Outcome
    //--------------------------------------------
    Comment( "Total MACD Signals:"
        + " " + viMACDSignalBuyCount + " (Buy)"
        + ", " + viMACDSignalSellCount + " (Sell)"
    );
}