Need help to fix my EA

 

I have EA RSI with moving average EA

The EA work ok but sometimes did not open new trades and get error in journal “Failed to get MA value “ the code of this error 


   // get ma value
   values = CopyBuffer(handleMA,0,0,1,bufferMA);
   if(values!=1){
      Print("Failed to get ma value");
      return;
   }
 
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
          General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
              Messages Editor
          Forum rules and recommendations - General - MQL5 programming forum (2023)

  2. Your posted code is without context. Always post all relevant code (using Code button) or attach the source file. Where is that handleMA initialized?. They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
              MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
              How to call indicators in MQL5 - MQL5 Articles (2010)

 

In case of an error, the CopyBuffer() function returns -1, so you need to write like this:

// get ma value
   values = CopyBuffer(handleMA,0,0,1,bufferMA);
   if(values<0){
      Print("Failed to get ma value");
      return;
   }
 
Maksim Neimerik #:

In case of an error, the CopyBuffer() function returns -1, so you need to write like this:

Same error in strategy tester work ok but in real account i have the error for EURGBP and some error in S&P US500

 
William Roeder #:
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
          General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
              Messages Editor
          Forum rules and recommendations - General - MQL5 programming forum (2023)

  2. Your posted code is without context. Always post all relevant code (using Code button) or attach the source file. Where is that handleMA initialized?. They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
              MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
              How to call indicators in MQL5 - MQL5 Articles (2010)

Hello sir this is the code

 
Bash123456 #:

Hello sir this is the code

Improperly formatted code removed by moderator
MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.