Problem loading IFrAMA

 
Hi!

Does anyone having problem in loading IFrAMA from code?

I'm trying to load the indicator and the Buffer returns with "-nan(ind)" to all candles. It's worst: I had been using the same call for months in the past...


int hFrama;
double xFR[];

hFrama= iFrAMA(_Symbol, _Period, 5, 0, PRICE_CLOSE);
ChartIndicatorAdd(0, 0, hFrama);
ArraySetAsSeries(xFR, true);
CopyBuffer(hFrama, 0, 0, 65536, xFR);


The indicator handle is loaded normally (no error at all) and even the FR[] buffer returns the correct amount of required candles - but ALL of them with "-nan(ind)".
Would be a "bug" of the latest version?


I appeciate any help on this.

 

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.03.08)
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020.07.05)
          How to call indicators in MQL5 - MQL5 Articles (2010)

 
William Roeder #:

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.03.08)
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020.07.05)
          How to call indicators in MQL5 - MQL5 Articles (2010)

Thanks William but as I said before, all tests with the handler and the ARRAY are ok - I only guessed be unnecessary to put the entire routine I'm using here, like the recommended on the documentation.

The INDICATOR HANDLER is loaded, the COPYBUFFER functions normally, the ARRAY is entirely fulfilled ... but with "-nan(ind)".

Worst: if I run the INDICATOR itself and alone, the chart does not display any line too.

So, I conclude the problem is with iFRAMA indicator, at least in my version of META (3091) running in Windows 8.1 64 bits 32Gb RAM.

Just an additional info:  yes, my mistake was not to say I'm working with META for two year and I'm used to produce INDICATORS and EXPERTS.
 
AliceRioBR :

Error (very serious error) - according to the MQL5 style, the indicator handle must be created ONCE and must be done in OnInit.

Correct it - until you correct this error, it is useless to move on.

 
Vladimir Karputov #:

Error (very serious error) - according to the MQL5 style, the indicator handle must be created ONCE and must be done in OnInit.

Correct it - until you correct this error, it is useless to move on.


Hi Vladimir, thanks for your reply.

Yes, of course the indicator is created on ON_INIT event.

As I told in the last message, I follow the nornal and recommended way to do things in META for years. And, even executing the Indicator alone from the MetaEditor (compiling and playing the source code existent in Indicators\Examples folder, I got neither its graphics not the data into my array.

That's the code I have here:

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

int OnInit()

  {
    EventSetTimer(1);
    ChartSetSymbolPeriod(0, _Symbol, PERIOD_CURRENT);

   hFrama = iFrAMA(_Symbol, PERIOD_CURRENT, FrAMAPeriod,FramaShift,PRICE_CLOSE);   

   if(hFrama == INVALID_HANDLE)
   {
    return(INIT_FAILED);
   }

   else
   {
    ChartIndicatorAdd(0, 0, hFrama);
   }


   ArraySetAsSeries(FR, true);


   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {
        IndicatorRelease(hFrama);       
        ChartIndicatorDelete(0, 0, ChartIndicatorName(0, 0, 0));
  }


//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

void OnTick()

  {
  }

//+------------------------------------------------------------------+

void OnTimer()
{
   Treina();
}



void Treina()
{
   int copied=CopyRates(_Symbol,PERIOD_CURRENT,0,65536,vela);

      if(copied == 65536)
        {
              CopyBuffer(hFrama, 0, 0, 65536,FR);
              ArraySetAsSeries(FR,true);

              for(int i=0;i<10;i++)
                {
                 Print("FrAMA " + IntegerToString(i,1) + " = " + DoubleToString(FR[i],8));
                }      
        }
        else Print("No Data!");
}



Yesterday, a friend ran this code successfully and could see the line of graphics and its data on array. He send me the .MQ5 code of his FrAMA and I compiled here and got the same weird results.

Our machines are quite equivalent in matter of operating system and hardware...  the only diference I have 32Gb RAM and he has only 8 Gb.

We detect ONE single difference between our META's: 


- He is using the release 3093




- My META is release 3091 and all time I check if there are a new version I got the message "you are using the latest version".  Why?




Could be this the root of the problem?

Thanks for your help.

 
Use the help and use the ready-made code: iFrAMA
Documentation on MQL5: Technical Indicators / iFrAMA
Documentation on MQL5: Technical Indicators / iFrAMA
  • www.mql5.com
iFrAMA - Technical Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Vladimir Karputov #:
Use the help and use the ready-made code: iFrAMA

Hi Vladimir.

I'm already using it...  see the sample above.

But the weird thing is related to the entire array without any valid value AND in another META (newer version) it is functioning using the same serie and indicator.



PS:  I utilized the recommended FrAMA as "iCustom" and I had the same results. In other words: I 've the same behavior using the sample at INDICATORS\EXAMPLES, the above mentioned FrAMA, or even a custom FrAMA.  All other indicators (MA, Stochastic, Chaikin...) are functioning perfectly.

 
AliceRioBR # :

Hi Vladimir.

I'm already using it...  see the sample above.

But the weird thing is related to the entire array without any valid value AND in another META (newer version) it is functioning using the same serie and indicator.



PS:  I utilized the recommended FrAMA as "iCustom" and I had the same results. In other words: I 've the same behavior using the sample at INDICATORS\EXAMPLES, the above mentioned FrAMA, or even a custom FrAMA.  All other indicators (MA, Stochastic, Chaikin...) are functioning perfectly.

No, you are not using help. A specific example is given in the help. Use help!

 

Example:

//+------------------------------------------------------------------+
//|                                             iFrAMA get value.mq5 |
//|                              Copyright © 2021, Vladimir Karputov |
//|                      https://www.mql5.com/en/users/barabashkakvn |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2021, Vladimir Karputov"
#property link      "https://www.mql5.com/en/users/barabashkakvn"
#property version   "1.000"
//--- input parameters
input group             "FrAMA"
input int                  Inp_FrAMA_ma_period           = 14;             // FrAMA: averaging period
input int                  Inp_FrAMA_ma_shift            = 0;              // FrAMA: horizontal shift of indicator
input ENUM_APPLIED_PRICE   Inp_FrAMA_applied_price       = PRICE_CLOSE;    // FrAMA: type of price
input group                "Additional features"
input bool                 InpPrintLog          = false;       // Print log
//---
int      handle_iFrAMA;                         // variable for storing the handle of the iFrAMA indicator
bool     m_init_error               = false;    // error on InInit
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create handle of the indicator
   handle_iFrAMA=iFrAMA(Symbol(),Period(),Inp_FrAMA_ma_period,
                        Inp_FrAMA_ma_shift,Inp_FrAMA_applied_price);
//--- if the handle is not created
   if(handle_iFrAMA==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code
      PrintFormat("Failed to create handle of the iFrAMA indicator for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early
      m_init_error=true;
      return(INIT_SUCCEEDED);
     }
//---
   ChartIndicatorAdd(ChartID(),0,handle_iFrAMA);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   if(handle_iFrAMA!=INVALID_HANDLE)
      IndicatorRelease(handle_iFrAMA);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(m_init_error)
      return;
//---
   double frama[];
   ArraySetAsSeries(frama,true);
   int start_pos=0,count=3;
   if(!iGetArray(handle_iFrAMA,0,start_pos,count,frama))
      return;
//---
   string text="";
   int limit=(count>3)?3:count;
   for(int i=0; i<limit; i++)
     {
      text=text+
           " bar #"+IntegerToString(i)+": "+
           " FrAMA "+DoubleToString(frama[i],Digits()+1)+"\n";
     }
   Comment(text);
  }
//+------------------------------------------------------------------+
//| Get value of buffers                                             |
//+------------------------------------------------------------------+
bool iGetArray(const int handle,const int buffer,const int start_pos,
               const int count,double &arr_buffer[])
  {
   bool result=true;
   if(!ArrayIsDynamic(arr_buffer))
     {
      if(InpPrintLog)
         PrintFormat("ERROR! EA: %s, FUNCTION: %s, this a no dynamic array!",__FILE__,__FUNCTION__);
      return(false);
     }
   ArrayFree(arr_buffer);
//--- reset error code
   ResetLastError();
//--- fill a part of the iBands array with values from the indicator buffer
   int copied=CopyBuffer(handle,buffer,start_pos,count,arr_buffer);
   if(copied!=count)
     {
      //--- if the copying fails, tell the error code
      if(InpPrintLog)
         PrintFormat("ERROR! EA: %s, FUNCTION: %s, amount to copy: %d, copied: %d, error code %d",
                     __FILE__,__FUNCTION__,count,copied,GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      return(false);
     }
   return(result);
  }
//+------------------------------------------------------------------+

Result:

iFrAMA get value

Pic. 1. iFrAMA get value

Files:
 

Thank you A LOT Vladimir.