0

Good Evening all,

can anyone show me how to get total result from an MTF indicator, example if MACD :

M1 = Buy, M5 = Sell, M15= Sell, M30= Buy, H1 = Buy, H4 = Buy, D1 = Buy,

Total Result = 5 Buy & 2 Sell

How do I implement this into a MQL4 code? Thank you for all your answers.

user3666197
  • 1
  • 6
  • 50
  • 92
user3869115
  • 41
  • 1
  • 6
  • There are some pieces missing. Define a quantitatively exact method, by which the Multi-TimeFrame indicator of your wish decides under what circumstances it reports ( on a single TimeFrame ) it's `{ Buy | NOP | Sell }` indication and from that an MQL4 implementation may start. – user3666197 Oct 07 '14 at 04:50
  • You may also have noted, that multi-TimeFrame indicators & EA-strategies are causing problems once being run in **MT4.StrategyTester**, be it with/without optimisation engine. If interested in a professional solution thereof, kindly respond on subject, to get the job done for you. – user3666197 Oct 07 '14 at 16:52

1 Answers1

1

Sample code to consider:

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)"
    );
}
jlee88my
  • 2,935
  • 21
  • 28