"'iMA' - wrong parameters count" and "'iATR' - wrong parameters count" errors.Please help me

 

I have been trying for a long time but could not fix this error.

Compatible with MT5.

Can you check the code I wrote for errors?

 //+------------------------------------------------------------------+
//|                                                  EmaRibbonEA.mq5 |
//|                                  Copyright 2025, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link        " https://www.mql5.com "
#property version    "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
// --- MetaTrader 5 için EMA Ribbon + Yutan Mum + ATR Stop EA ---
// Strateji: Fibonacci EMA'ları ile trend yönünü belirler, fiyat geri çekildiğinde yutan mum arar,
// ATR'nin 2 katı stop-loss uygular ve iz süren stop kullanır.

#include <Trade/Trade.mqh>
CTrade trade;

// --- Parametreler ---
input int EMA1 = 5 ;
input int EMA2 = 8 ;
input int EMA3 = 13 ;
input int EMA4 = 21 ;
input int EMA5 = 34 ;
input int EMA6 = 55 ;
input int EMA7 = 89 ;
input int EMA8 = 144 ;
input int ATR_Period = 14 ;
input double ATR_Multiplier = 2.0 ; // Stop mesafesi için ATR çarpanı
input double Trailing_Stop = 1.5 ; // ATR'ye bağlı iz süren stop katsayısı
input double Lot_Size = 0.1 ;

// --- Değişkenler ---
int EMAs[ 8 ] = {EMA1, EMA2, EMA3, EMA4, EMA5, EMA6, EMA7, EMA8};
double emaValues[ 8 ];
double atr;
datetime lastTradeTime = 0 ;

// --- EMA ve ATR Hesaplama ---
void CalculateIndicators() {
     for ( int i = 0 ; i < ArraySize (EMAs); i++) {
        emaValues[i] = iMA ( _Symbol , PERIOD_H1 , EMAs[i], 0 , MODE_EMA , PRICE_CLOSE , 0 );
    }
    atr = iATR ( _Symbol , PERIOD_H1 , ATR_Period, 0 );
}

// --- EMA Sıralaması Kontrolü ---
bool IsTrendValid( bool uptrend) {
     for ( int i = 0 ; i < ArraySize (emaValues) - 1 ; i++) {
         if (uptrend && emaValues[i] < emaValues[i + 1 ]) return false ;
         if (!uptrend && emaValues[i] > emaValues[i + 1 ]) return false ;
    }
     return true ;
}

// --- Yutan Mum Kontrolü ---
bool IsEngulfingCandle( bool uptrend) {
     double open1 = iOpen ( _Symbol , PERIOD_H1 , 1 );
     double close1 = iClose ( _Symbol , PERIOD_H1 , 1 );
     double open2 = iOpen ( _Symbol , PERIOD_H1 , 2 );
     double close2 = iClose ( _Symbol , PERIOD_H1 , 2 );
     return (uptrend && close1 > open1 && open1 < close2 && close1 > open2) ||
           (!uptrend && close1 < open1 && open1 > close2 && close1 < open2);
}

// --- İşlem Açma ---
void OpenTrade( bool uptrend) {
     double price = uptrend ? SymbolInfoDouble ( _Symbol , SYMBOL_ASK ) : SymbolInfoDouble ( _Symbol , SYMBOL_BID );
     double sl = uptrend ? price - (atr * ATR_Multiplier) : price + (atr * ATR_Multiplier);
     double tp = uptrend ? price + (atr * 3 ) : price - (atr * 3 );
    
     if (uptrend) {
        trade.Buy(Lot_Size, _Symbol , price, sl, tp, "Buy Signal" );
    } else {
        trade.Sell(Lot_Size, _Symbol , price, sl, tp, "Sell Signal" );
    }
    lastTradeTime = TimeCurrent ();
}

// --- İşlem Yönetimi (İz Süren Stop) ---
void ManageTrade() {
     for ( int i = 0 ; i < PositionsTotal (); i++) {
         ulong ticket = PositionGetTicket (i);
         double stopLoss = PositionGetDouble ( POSITION_SL );
         double price = PositionGetDouble ( POSITION_PRICE_OPEN );
        
         if ( PositionGetInteger ( POSITION_TYPE ) == POSITION_TYPE_BUY ) {
             double newSL = price + (atr * Trailing_Stop);
             if (newSL > stopLoss) trade.PositionModify(ticket, newSL, PositionGetDouble ( POSITION_TP ));
        } else {
             double newSL = price - (atr * Trailing_Stop);
             if (newSL < stopLoss) trade.PositionModify(ticket, newSL, PositionGetDouble ( POSITION_TP ));
        }
    }
}

// --- Sinyal Kontrolü ---
void CheckForSignals() {
     if ( TimeCurrent () == lastTradeTime) return ;
    
     bool uptrend = emaValues[ 0 ] > emaValues[ 7 ];
     if (IsTrendValid(uptrend) && IsEngulfingCandle(uptrend)) {
        OpenTrade(uptrend);
    }
}

// --- OnTick() ---
void OnTick () {
    CalculateIndicators();
    CheckForSignals();
    ManageTrade();
}

 

search this website for term handles. also search for ATR.

Your code will not work in mt5.

 
VorteXchange:

Uzun zamandır uğraşıyorum ama bu hatayı düzeltemedim.

MT5 ile uyumludur.

Yazdığım kod hatalarını kontrol edebilir misiniz?

using MQL4 code for MQL5 wont work dude. Consider creating handles for ATR and CopyBuffer

 
VorteXchange:

Uzun zamandır uğraşıyorum ama bu hatayı düzeltemedim.

MT5 ile uyumludur.

Yazdığım kod hatalarını kontrol edebilir misiniz?

You need to change the indicators to use handles for mt5

// --- MetaTrader 5 için EMA Ribbon + Yutan Mum + ATR Stop EA ---
// Strateji: Fibonacci EMA'ları ile trend yönünü belirler, fiyat geri çekildiğinde yutan mum arar,
// ATR'nin 2 katı stop-loss uygular ve iz süren stop kullanır.

#include <Trade/Trade.mqh>
CTrade trade;

// --- Parametreler ---
input int EMA1 = 5;
input int EMA2 = 8;
input int EMA3 = 13;
input int EMA4 = 21;
input int EMA5 = 34;
input int EMA6 = 55;
input int EMA7 = 89;
input int EMA8 = 144;
input int ATR_Period = 14;
input double ATR_Multiplier = 2.0; // Stop mesafesi için ATR çarpanı
input double Trailing_Stop = 1.5; // ATR'ye bağlı iz süren stop katsayısı
input double Lot_Size = 0.1;

// --- Değişkenler ---
int EMAs[8] = {EMA1, EMA2, EMA3, EMA4, EMA5, EMA6, EMA7, EMA8};
double emaValues[8];
/*
in MT5 you have to "start" the indicators first , once and then use them
you use them by referencing their handles
so you also need to store their handles
*/
int emaHandles[]={INVALID_HANDLE,INVALID_HANDLE,INVALID_HANDLE,INVALID_HANDLE,INVALID_HANDLE,INVALID_HANDLE,INVALID_HANDLE,INVALID_HANDLE};
double atr;
int atrHandle=INVALID_HANDLE;
datetime lastTradeTime = 0;

// --- start indicators
void StartIndicators(){
    for (int i = 0; i < ArraySize(EMAs); i++) {
        emaHandles[i] = iMA(_Symbol, PERIOD_H1, EMAs[i], 0, MODE_EMA, PRICE_CLOSE);
    }
    atrHandle=iATR(_Symbol,PERIOD_H1,ATR_Period);
}

// --- EMA ve ATR Hesaplama ---
void CalculateIndicators() {
    double copier[];
    for (int i = 0; i < ArraySize(EMAs); i++) {
        //emaValues[i] = iMA(_Symbol, PERIOD_H1, EMAs[i], 0, MODE_EMA, PRICE_CLOSE, 0);
    //copy instruction to copy values from the indicator by specifying the handle
    CopyBuffer(emaHandles[i],0,0,1,copier);
    emaValues[i]=copier[0];
    }
    //atr = iATR(_Symbol, PERIOD_H1, ATR_Period, 0);
    CopyBuffer(atrHandle,0,0,1,copier);
    atr=copier[0];
}

// --- EMA Sıralaması Kontrolü ---
bool IsTrendValid(bool uptrend) {
    for (int i = 0; i < ArraySize(emaValues) - 1; i++) {
        if (uptrend && emaValues[i] < emaValues[i + 1]) return false;
        if (!uptrend && emaValues[i] > emaValues[i + 1]) return false;
    }
    return true;
}

// --- Yutan Mum Kontrolü ---
bool IsEngulfingCandle(bool uptrend) {
    double open1 = iOpen(_Symbol, PERIOD_H1, 1);
    double close1 = iClose(_Symbol, PERIOD_H1, 1);
    double open2 = iOpen(_Symbol, PERIOD_H1, 2);
    double close2 = iClose(_Symbol, PERIOD_H1, 2);
    return (uptrend && close1 > open1 && open1 < close2 && close1 > open2) ||
           (!uptrend && close1 < open1 && open1 > close2 && close1 < open2);
}

// --- İşlem Açma ---
void OpenTrade(bool uptrend) {
    double price = uptrend ? SymbolInfoDouble(_Symbol, SYMBOL_ASK) : SymbolInfoDouble(_Symbol, SYMBOL_BID);
    double sl = uptrend ? price - (atr * ATR_Multiplier) : price + (atr * ATR_Multiplier);
    double tp = uptrend ? price + (atr * 3) : price - (atr * 3);
    
    if (uptrend) {
        trade.Buy(Lot_Size, _Symbol, price, sl, tp, "Buy Signal");
    } else {
        trade.Sell(Lot_Size, _Symbol, price, sl, tp, "Sell Signal");
    }
    lastTradeTime = TimeCurrent();
}

// --- İşlem Yönetimi (İz Süren Stop) ---
void ManageTrade() {
    for (int i = 0; i < PositionsTotal(); i++) {
        ulong ticket = PositionGetTicket(i);
        double stopLoss = PositionGetDouble(POSITION_SL);
        double price = PositionGetDouble(POSITION_PRICE_OPEN);
        
        if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) {
            double newSL = price + (atr * Trailing_Stop);
            if (newSL > stopLoss) trade.PositionModify(ticket, newSL, PositionGetDouble(POSITION_TP));
        } else {
            double newSL = price - (atr * Trailing_Stop);
            if (newSL < stopLoss) trade.PositionModify(ticket, newSL, PositionGetDouble(POSITION_TP));
        }
    }
}

// --- Sinyal Kontrolü ---
void CheckForSignals() {
    if (TimeCurrent() == lastTradeTime) return;
    
    bool uptrend = emaValues[0] > emaValues[7];
    if (IsTrendValid(uptrend) && IsEngulfingCandle(uptrend)) {
        OpenTrade(uptrend);
    }
}

// --- OnTick() ---
void OnTick() {
    CalculateIndicators();
    CheckForSignals();
    ManageTrade();
}