A help with sending signals to EA

 
Sup guys, i hope u can help me again.

i got this code.
this is from the customindicator:
void SendSignalsToEA(const int rates_total, const double &close_price[], int &buy_signal, int &sell_signal) 
   {
    double ma = ExtLineBuffer[0];
    
    if (close_price[rates_total - 1] > ma)
    {
        buy_signal = 1;
        sell_signal = 0;
    }
    else
    {
        buy_signal = 0; 
        sell_signal = 1;
    }
    
}




void CalculateSMA(int rates_total, int prev_calculated, int begin, const double &price[])
{
    int i, limit;
    
    if (prev_calculated == 0) 
    {
        limit = InpMAPeriod + begin;
        
        for (i = 0; i < limit - 1; i++)
            ExtLineBuffer[i] = 0.0;
        
        double firstValue = 0;
        for (i = begin; i < limit; i++)
            firstValue += price[i];
        firstValue /= InpMAPeriod;
        ExtLineBuffer[limit - 1] = firstValue;
    }
    else
        limit = prev_calculated - 1;
    
    for (i = limit; i < rates_total && !IsStopped(); i++)
        ExtLineBuffer[i] = ExtLineBuffer[i - 1] + (price[i] - price[i - InpMAPeriod]) / InpMAPeriod;
      SendSignalsToEA(rates_total, close_price, buy_signal, sell_signal);
}

and this is from my ea:


void ReceiveSignalFromIndicator(int &buy_signal, int &sell_signal) {
    // Call the custom moving average indicator function to get the signal
    int rates_total = Ask;
    double close_price = Bid; // You can use Ask or Bid depending on your strategy
    int signal = GetSignalFromIndicator(rates_total, close_price);

    // Set the buy and sell signals based on the received signal
    if (signal == 1) {
        buy_signal = 1;
        sell_signal = 0;
    }
    else if (signal == -1) {
        buy_signal = 0;
        sell_signal = 1;
    }
    else {
        buy_signal = 0;
        sell_signal = 0;
    }
}



void OpenOrder() {
   if(buy_signal == 1){
    ENUM_ORDER_TYPE OrdType = ORDER_TYPE_BUY;
   }
   else if (sell_signal ==1){
      ENUM_ORDER_TYPE OrdType = ORDER_TYPE_SELL;
   }
    double TP = 0;
    double SL = 0;
    string comment = ExtBotName;

    // Calculate volume
    double lot1 = CalculateVolume();

    if (OrdType == ORDER_TYPE_SELL) {
        double OpenPrice = Bid - NormalizeDouble(InpSL_Pips / 2 * Pips2Double, _Digits);

        TP = OpenPrice - NormalizeDouble(InpTP_Pips * Pips2Double, _Digits);
        SL = Ask + NormalizeDouble(InpSL_Pips / 2 * Pips2Double, _Digits);

        if (CheckSpreadAllow() && CheckVolumeValue(lot1) && CheckOrderForFREEZE_LEVEL(ORDER_TYPE_SELL_STOP, OpenPrice) && CheckStopLoss(OpenPrice, SL, TP) && CheckMoneyForTrade(m_symbol.Name(), lot1, ORDER_TYPE_SELL)) {
            if (!m_trade.SellStop(lot1, OpenPrice, m_symbol.Name(), SL, TP, ORDER_TIME_GTC, 0, comment)) {
                Print(__FUNCTION__, "--> OrderSend error ", m_trade.ResultComment());
            }
        }
    }
else if(OrdType == ORDER_TYPE_BUY) {
double OpenPrice = Ask + NormalizeDouble(InpSL_Pips / 2 * Pips2Double, _Digits);

  SL = Bid - NormalizeDouble(InpSL_Pips / 2 * Pips2Double, _Digits);

  if(CheckSpreadAllow() && CheckVolumeValue(lot1) && CheckOrderForFREEZE_LEVEL(ORDER_TYPE_BUY_STOP, OpenPrice) && CheckStopLoss(OpenPrice, SL, TP) && CheckMoneyForTrade(m_symbol.Name(), lot1, ORDER_TYPE_BUY)) {
     if(!m_trade.BuyStop(lot1, OpenPrice, m_symbol.Name(), SL, TP, ORDER_TIME_GTC, 0, comment)) {
        Print(__FUNCTION__, "--> OrderSend error ", m_trade.ResultComment());
     }
  }
}
}

the actual errors are:

'GetSignalFromIndicator' - undeclared identifier EAPROJECT.mq5 160 18

    int signal = GetSignalFromIndicator(rates_total, close_price);
',' - unexpected token EAPROJECT.mq5 160 52
'rates_total' - some operator expected EAPROJECT.mq5 160 41
'close_price' - semicolon expected EAPROJECT.mq5 160 54
')' - unexpected token EAPROJECT.mq5 160 65

    int signal = GetSignalFromIndicator(rates_total, close_price);
                                                   ^

so if anyone can help.
 

Due to:

    double ma = ExtLineBuffer[0];
    
    if (close_price[rates_total - 1] > ma)

I assume that you are trying to code an EA based on moving average - can you imaging how many already exist?

Learn to search it makes you are faster then first tries to code:

  1. https://www.mql5.com/en/search#!keyword=MA%20EA ~ 1000 links
  2. Code Base filter (on the left side): https://www.mql5.com/en/search#!keyword=MA%20EA&module=mql5_module_codebase  ~ 200 links
  3. Articles (Code & explanation): https://www.mql5.com/en/search#!keyword=MA%20EA&module=mql5_module_articles ~ 190 links

Bear in mind there's virtually nothing that hasn't already been programmed for MT4/MT5 and is ready for you - copy & paste the fastest way to program :)
How to search: https://www.mql5.com/en/forum/193510

Start with a working EA and amend it according your ideas!
 
Carl Schreiber #:

Due to:

I assume that you are trying to code an EA based on moving average - can you imaging how many already exist?

Learn to search it makes you are faster then first tries to code:

  1. https://www.mql5.com/en/search#!keyword=MA%20EA ~ 1000 links
  2. Code Base filter (on the left side): https://www.mql5.com/en/search#!keyword=MA%20EA&module=mql5_module_codebase  ~ 200 links
  3. Articles (Code & explanation): https://www.mql5.com/en/search#!keyword=MA%20EA&module=mql5_module_articles ~ 190 links

Bear in mind there's virtually nothing that hasn't already been programmed for MT4/MT5 and is ready for you - copy & paste the fastest way to program :)
How to search: https://www.mql5.com/en/forum/193510

Start with a working EA and amend it according your ideas!

ty for the advise, but errors and solutions must be a part of the learning process :)
i'm checking your links for anything usefull, but my base idea is to really fix this.



 
Update your indicator so that it has two output buffers—one for buy signals and one for sell signals. You might modify your indicator code as follows:

//+------------------------------------------------------------------+
//|                MyCustomIndicator.mq5                             |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   3

//--- buffers
double ExtLineBuffer[];     // For the SMA values
double BuySignalBuffer[];   // 1 if buy signal, 0 otherwise
double SellSignalBuffer[];  // 1 if sell signal, 0 otherwise

//--- input parameters
input int InpMAPeriod = 14;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()


{
    // Set buffers
    SetIndexBuffer(0, ExtLineBuffer);
    SetIndexBuffer(1, BuySignalBuffer);
    SetIndexBuffer(2, SellSignalBuffer);
    
    // (Optional) Set plot styles here...
    
    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
    int begin = InpMAPeriod;
    int limit = rates_total;
    
    // Calculate the SMA and store it in ExtLineBuffer
    // For simplicity, using a basic moving average:
    for (int i = begin; i < rates_total; i++)
    {
        double sum = 0;
        for(int j = i - InpMAPeriod + 1; j <= i; j++)
            sum += close[j];
        ExtLineBuffer[i] = sum / InpMAPeriod;
    }
    
    // Send signals into the indicator buffers:
    // We'll use the last completed bar (index = rates_total - 2) as the signal bar.
    int signalBar = rates_total - 2;
    if(signalBar < 0)
       return(rates_total);
       
    double ma = ExtLineBuffer[signalBar];
    
    if (close[signalBar] > ma)
    {
        BuySignalBuffer[signalBar] = 1;
        SellSignalBuffer[signalBar] = 0;
    }
    else
    {
        BuySignalBuffer[signalBar] = 0;
        SellSignalBuffer[signalBar] = 1;
    }
    
    return(rates_total);
}

In your EA, remove any call to an undefined function like GetSignalFromIndicator. Instead, use iCustom() to load your indicator and CopyBuffer() to retrieve the signals.

//+------------------------------------------------------------------+
//| Retrieve signals from the custom indicator                       |
//+------------------------------------------------------------------+
void ReceiveSignalFromIndicator(int &buy_signal, int &sell_signal)
{
    // Load the indicator. Change "MyCustomIndicator" to your indicator’s compiled name.
    int indicator_handle = iCustom(_Symbol, PERIOD_CURRENT, "MyCustomIndicator", InpMAPeriod);
    if(indicator_handle == INVALID_HANDLE)
    {
         Print("Error loading custom indicator. Error: ", GetLastError());
         buy_signal = 0;
         sell_signal = 0;
         return;
    }
    
    // We want the signal from the last completed bar. Typically, index 1 is used.
    int signal_index = 1;
    
    double buyBuffer[1], sellBuffer[1];
    // Buffer 1: Buy signals (as defined in the indicator)
    if(CopyBuffer(indicator_handle, 1, signal_index, 1, buyBuffer) <= 0)
    {
         Print("Error copying buy signal buffer. Error: ", GetLastError());
         buy_signal = 0;
         sell_signal = 0;
         IndicatorRelease(indicator_handle);
         return;
    }
    
    // Buffer 2: Sell signals
    if(CopyBuffer(indicator_handle, 2, signal_index, 1, sellBuffer) <= 0)
    {
         Print("Error copying sell signal buffer. Error: ", GetLastError());
         buy_signal = 0;
         sell_signal = 0;
         IndicatorRelease(indicator_handle);
         return;
    }
    
    buy_signal = (int)buyBuffer[0];
    sell_signal = (int)sellBuffer[0];
    
    // Release the indicator handle if not needed further
    IndicatorRelease(indicator_handle);
}