大家晚上好,
谁能告诉我如何从 MTF 指标获得总结果,例如 MACD:
M1= 买, M5= 卖, M15= 卖, M30= 买, H1= 买, H4= 买, D1= 买,
总结果 = 5 买 & 2 卖
如何将其实现到MQL4
代码中?感谢您的所有回答。
大家晚上好,
谁能告诉我如何从 MTF 指标获得总结果,例如 MACD:
M1= 买, M5= 卖, M15= 卖, M30= 买, H1= 买, H4= 买, D1= 买,
总结果 = 5 买 & 2 卖
如何将其实现到MQL4
代码中?感谢您的所有回答。
要考虑的示例代码:
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)"
);
}