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:
- https://www.mql5.com/en/search#!keyword=MA%20EA ~ 1000 links
- Code Base filter (on the left side): https://www.mql5.com/en/search#!keyword=MA%20EA&module=mql5_module_codebase ~ 200 links
- 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
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:
- https://www.mql5.com/en/search#!keyword=MA%20EA ~ 1000 links
- Code Base filter (on the left side): https://www.mql5.com/en/search#!keyword=MA%20EA&module=mql5_module_codebase ~ 200 links
- 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
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.
//+------------------------------------------------------------------+ //| 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); }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
i got this code.
this is from the customindicator:
and this is from my ea:
the actual errors are:
'GetSignalFromIndicator' - undeclared identifier EAPROJECT.mq5 160 18
int signal = GetSignalFromIndicator(rates_total, close_price);
int signal = GetSignalFromIndicator(rates_total, close_price); ^
so if anyone can help.