MQL5 Possible loss of data due to type conversion

 

   Hi everyone, below is my code, I dont understand why it shows such error. How do I fix it?


   int handlEma_indicator = iMA(_Symbol, _Period, ma_reference, 0, MODE_EMA, PRICE_CLOSE);

   double EmaArray[5];
   CopyBuffer(handlEma_indicator,0,1,5,EmaArray);
 
das Leo:

   Hi everyone, below is my code, I dont understand why it shows such error. How do I fix it?


   int handlEma_indicator = iMA(_Symbol, _Period, ma_reference, 0, MODE_EMA, PRICE_CLOSE);

   double EmaArray[5];
   CopyBuffer(handlEma_indicator,0,1,5,EmaArray);

ma_reference should be an integer. You can cast it to remove the warning:

 iMA(_Symbol, _Period, (int)ma_reference, 0, MODE_EMA, PRICE_CLOSE);

 
das Leo: below is my code,
  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 (2019)
              Messages Editor

  2. We have no idea what ma_reference is. Always post all relevant code (using Code button) or attach the source file.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

  3. Your posted code is without context. Are those three line together, or is the iMA call in OnInit? Always post all relevant code (using Code button) or attach the source file.

    Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    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)

 
Yashar Seyyedin #:

ma_reference should be an integer. You can cast it to remove the warning:

Thanks for your reply. Its fixed now
Reason: