iFractals on a screener indicator

 
Good day,
I am working on a personnal screener project with the fractals.

I need to know if the current price is above the last up fractal, or below the last down fractal or flat.
i have made this code, and my screener reacts with colors, but the result is totally wrong.

Can someone heavily help me please ?
//+--- inside OnInit
    
    SetIndexBuffer(0,fct_up_buffer,INDICATOR_DATA);
    SetIndexBuffer(1,fct_dn_buffer,INDICATOR_DATA);

//+--- inside OnCalculate

          //+--- define the last up fractal
            fct_up_handle=iFractals(Pairs[i],tframe[j]);
            ArraySetAsSeries(fct_up_to_copy,true);
            CopyBuffer(fct_up_handle,UPPER_LINE,1,3,fct_up_to_copy);
            fct_dn=fct_up_to_copy[0];

          //+--- define the last down fractal
            fct_dn_handle=iFractals(Pairs[i],tframe[j]);
            ArraySetAsSeries(fct_dn_to_copy,true);
            CopyBuffer(fct_dn_handle,LOWER_LINE,1,3,fct_dn_to_copy);
            fct_dn=fct_dn_to_copy[0];

            //+--- define signals : up, down or flat
            if      (cl0_prc>fct_up) // bull
            {
                Valu_Fct[i][j]=1;
            }
            else if (cl0_prc<fct_dn) // bear
            {
                Valu_Fct[i][j]=-1;
            }
            else Valu_Fct[i][j]=0; // range
 
Email Temporaire:
         //+--- define the last up fractal
            fct_up_handle=iFractals(Pairs[i],tframe[j]);
            ArraySetAsSeries(fct_up_to_copy,true);
            CopyBuffer(fct_up_handle,UPPER_LINE,1,3,fct_up_to_copy);

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)

 
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)
          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)

Good day, I am not sure if the intend is to help or crush me.
I have read the manual, but my skills are at this level. I need to guide me, for now i am over charged by all your links.
If you can/want to help me more, I will be grateful.

Regards

 
good day,
here i am so far, and i really not know/understand why the print result is not the last fractal value.
Can someone help me please?

USD_ind_fractal=iFractals("GBPUSD",PERIOD_M15);
  //+--- fractal_UP
  ArraySetAsSeries(USD_fractal_UP_copiy,true);
  CopyBuffer(USD_ind_fractal,UPPER_LINE,0,1,USD_fractal_UP_copiy);
  USD_fractal_UP=USD_fractal_UP_copiy[0];

  //+--- fractal_DN
  ArraySetAsSeries(USD_fractal_DN_copiy,true);
  CopyBuffer(USD_ind_fractal,LOWER_LINE,0,1,USD_fractal_DN_copiy);
  USD_fractal_DN=USD_fractal_DN_copiy[0];
  /*
  */
  PrintFormat("fractal DN : "+(string)USD_fractal_DN);
  PrintFormat("fractal UP : "+(string)USD_fractal_UP);
 
Email Temporaire #: I am not sure if the intend is to help or crush me.

How To Ask Questions The Smart Way. (2004)
     How To Interpret Answers.
          If you don't understand…

Email Temporaire #: i really not know/understand why

What part of “You get that in OnInit” was unclear?
 
I already tried it, with iMACD and iMA and compare them to current close price --> no problem.
But i tried so many way with iFractals with no success. Even with IndicatorCreate... I really do not understand. I am not so skilled, but i am not a beginner anymore.
Here is my code. At my knowledge, all is well declared and used (?) and the expert journal give me "false" result.
  




  #property link      "https://www.mql5.com"
  #property version   "1.00"
#property indicator_chart_window   #property indicator_plots    0   //+--- fractals   int    USD_ind_fractal;   //+--- fractal UP   int     USD_fractal_UP_handle;   double  USD_fractal_UP_buffer[],           USD_fractal_UP_copy[],           USD_fractal_UP;   //+--- fractal DN   int     USD_fractal_DN_handle;   double  USD_fractal_DN_buffer[],           USD_fractal_DN_copy[],           USD_fractal_DN; int OnInit() {   USD_ind_fractal=iFractals("GBPUSD",PERIOD_M15);   //+--- fractal_UP   ArraySetAsSeries(USD_fractal_UP_copy,true);   CopyBuffer(USD_ind_fractal,UPPER_LINE,0,1,USD_fractal_UP_copy);   USD_fractal_UP=USD_fractal_UP_copy[0];   /*   */   //+--- fractal_DN   ArraySetAsSeries(USD_fractal_DN_copy,true);   CopyBuffer(USD_ind_fractal,LOWER_LINE,0,1,USD_fractal_DN_copy);   USD_fractal_DN=USD_fractal_DN_copy[0];   /*   */   PrintFormat("fractal DN : "+(string)USD_fractal_DN);   PrintFormat("fractal UP : "+(string)USD_fractal_UP);   //+---   return(INIT_SUCCEEDED); }
 
Email Temporaire #: Here is my code. 
int OnInit()
{
  USD_ind_fractal=iFractals("GBPUSD",PERIOD_M15);
  //+--- fractal_UP
  ArraySetAsSeries(USD_fractal_UP_copy,true);
  CopyBuffer(USD_ind_fractal,UPPER_LINE,0,1,USD_fractal_UP_copy);
What part of “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” was unclear?
 
iGetArray doesn 't work in OnCalculate().
So i tried another way from your link but with the same wrong result. (compilation is ok)
Could it be possible that its just a bug from mt5, as i always succeed to get value with the others indicators (iMA, iMACD...etc)?

my failed attempt code.
double iFractalsGet(const int index)
{
  double Fractals[1];
  //--- reset error code 
  ResetLastError();
  ArraySetAsSeries(Fractals,true);
  //--- fill a part of the iFractals array with values from the indicator buffer that has 0 index 
  if(CopyBuffer(USD_ind_fractale,0,index,1,Fractals)<0)
    {
      //--- if the copying fails, tell the error code 
      PrintFormat("Failed to copy data from the iFractals indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated 
      return(EMPTY_VALUE);
    }
  return(Fractals[0]);
}
 
Email Temporaire #:
iGetArray doesn 't work in OnCalculate().
So i tried another way from your link but with the same wrong result. (compilation is ok)
Could it be possible that its just a bug from mt5, as i always succeed to get value with the others indicators (iMA, iMACD...etc)?

my failed attempt code.
You are almost there, remove "CopyBuffer" from the OnInit() section of the code, within this section there is no candle values to copy, hence the reason you are asked to do that in the "OnCalculate/OnTick"
 
Thank-god Avwerosuoghene Odukudu #:
You are almost there, remove "CopyBuffer" from the OnInit() section of the code, within this section there is no candle values to copy, hence the reason you are asked to do that in the "OnCalculate/OnTick"

yes, i already tried to do it with copybuffer in OnCalculate(), but the result is always wrong.
That's why i ask if a native bug could be possible, because, with others indicators, it works fine with all the code in OnCalculate().

Nb: you re wright, thank God for everithing! 

 
for example, if I do that with "iMA", it works very fine :

            USD_sma_fast_handle=iMA(USD_paires[v],enum_ut_mt5_6_col[h],sma_fast_prd,shift,MODE_SMA,PRICE_CLOSE);
            ArraySetAsSeries(USD_sma_fast_copie,true);
            CopyBuffer(USD_sma_fast_handle,0,0,1,USD_sma_fast_copie);
            USD_sma_fast=USD_sma_fast_copie[0];

But does not work with iFractals and UPPER_LINE.
Reason: