Добрый день! Почему в mt5 не работает сравнение MA? Ошибку не выдает.
Вот пример:
if(iMA(NULL,0,5,0,MODE_SMMA,PRICE_MEDIAN)>iMA(NULL,0,10,0,MODE_SMMA,PRICE_MEDIAN)) {
}
Смотрите справку iMA:
Шаг первый: в OnInit создаётся ХЕНДЛ ИНДИКАТОРА
Шаг второй: в OnTick по ХЕНДЛУ обращаемся к нужному буферу и бару при помощи CopyBuffer. Результат записываем в переменную. Вот ЭТУ ПЕРЕМЕННУЮ и нужно сравнивать.
Пример из КодоБазы: Intersection 2 iMA.
Шаг первый:
//+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { ... //--- create handle of the indicator iMA handle_iMA_Fast=iMA(m_symbol.Name(),Period(),FastPer,0,MODE_EMA,PRICE_CLOSE); //--- if the handle is not created if(handle_iMA_Fast==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle of the iMA (Fast) indicator for the symbol %s/%s, error code %d", m_symbol.Name(), EnumToString(Period()), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } //--- create handle of the indicator iMA handle_iMA_Slow=iMA(m_symbol.Name(),Period(),SlowPer,0,MODE_EMA,PRICE_CLOSE); //--- if the handle is not created if(handle_iMA_Slow==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle of the iMA (Slow) indicator for the symbol %s/%s, error code %d", m_symbol.Name(), EnumToString(Period()), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } //--- return(INIT_SUCCEEDED); }
Шаг второй:
//+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { ... double MAFast1=iMAGet(handle_iMA_Fast,1);//2 double MAFast3=iMAGet(handle_iMA_Fast,3);//0 double MASlow1=iMAGet(handle_iMA_Slow,1);//2 double MASlow3=iMAGet(handle_iMA_Slow,3);//0
Добрый день! Почему в mt5 не работает сравнение MA? Ошибку не выдает.
Вот пример:
if(iMA(NULL,0,5,0,MODE_SMMA,PRICE_MEDIAN)>iMA(NULL,0,10,0,MODE_SMMA,PRICE_MEDIAN)) {
}