iFractals MQL5

 

god i hate MQL5 everything is complicated compare to MQL4

anyway guys i tried the sample of ifractals here is the code

  double fractal_up[],fractal_down[]; //--- for collecting fractal data
   handle_fractal = iFractals(_Symbol, PERIOD_CURRENT);

   ArraySetAsSeries (fractal_up, true);
   ArraySetAsSeries (fractal_down, true);
   
   //--- check if there's error when creating iFractal
   if (handle_fractal == INVALID_HANDLE)
    {
        handle_fractal = iFractals(_Symbol, PERIOD_CURRENT);
    }
   if (handle_fractal == INVALID_HANDLE) return;
   
   //--- get the data
   CopyBuffer(handle_fractal, UPPER_LINE, 1, 1, fractal_up);
   CopyBuffer(handle_fractal, LOWER_LINE, 1, 1, fractal_down);
   
   Comment("UP:",fractal_up[0],"\n DOWN:", fractal_down[0]);

in MQL4 when ifractals not there it just simply return 0.0 but in MQL5 and this code all i get is some sorta weird number all the time like the attachment

1.79769.....


i appreciate if you can help me out tnX in advance

Files:
ifractals.png  19 kb
 
Amirfakhredin Ghanbari:

god i hate MQL5 everything is complicated compare to MQL4

anyway guys i tried the sample of ifractals here is the code

in MQL4 when ifractals not there it just simply return 0.0 but in MQL5 and this code all i get is some sorta weird number all the time like the attachment

1.79769.....


i appreciate if you can help me out tnX in advance

Use DoubleToString()

 

This weird number is EMPTY_VALUE or DBL_MAX. If you print it you get 1.797693134862316e+308

It's different from MT4 where an empty indicator value is coded with 2147483647

You can test with

if(fractal_up[0]==EMPTY_VALUE) Comment("UP: --");
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Other Constants
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Other Constants
  • www.mql5.com
The CLR_NONE constant is used to outline the absence of color, it means that the graphical object or graphical series of an indicator will not be plotted. This constant was not included into the Web-color constants list, but it can be applied everywhere where the color arguments are required. The EMPTY_VALUE constant usually corresponds...
 
lippmaje:

This weird number is EMPTY_VALUE or DBL_MAX. If you print it you get 1.797693134862316e+308

It's different from MT4 where an empty indicator value is coded with 2147483647

You can test with

tnX for help


it semi worked!

at start showing this result


2020.02.19 10:27:36.059 2020.01.02 06:00:00   DOWN:9.881312916824931e-324

2020.02.19 10:27:36.059 2020.01.02 06:00:00   UP:-8.417176617641345e+111


then back to normal! wondering what are these 2 now!

2020.02.19 10:27:47.494 2020.01.02 09:00:00   DOWN:1.12008


 

ok i guess more part of this puzzle solved 9.881312916824931e-324 stands for empty Array!

weird as hell MQL5

i still don't know whats -8.417176617641345e+111 for!

i guess have to put more ifs in codes

tnX guys for help

 
Amirfakhredin Ghanbari :


1. The biggest mistake in your code: Handle indicator must be received ONCE! (This should be done optimally in OnInit () - and you create a new handle on each tick).

2. The fractal is formed with a delay. Therefore, it is necessary to obtain a fractal from the index [3].

Example:

//+------------------------------------------------------------------+
//|                                                    iFractals.mq5 |
//|                              Copyright © 2016, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, Vladimir Karputov"
#property description "Search of a fractal on the set bar"
#property version   "1.000"
//--- input parameters
input int   bar_numder=3;                 // bar on which you want to find fractal
//---
int         handle_iFractals;             // variable for storing the handle of the iFractals indicator 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create handle of the indicator iFractals
   handle_iFractals=iFractals(Symbol(),Period());
//--- if the handle is not created 
   if(handle_iFractals==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code 
      PrintFormat("Failed to create handle of the iFractals indicator for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early 
      return(INIT_FAILED);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   Comment("");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- find fractal in UPPER
   double upper=iFractalsGet(UPPER_LINE,bar_numder);
//--- find fractal in LOWER
   double lower=iFractalsGet(LOWER_LINE,bar_numder);
//---
   string text="";
   if(upper!=DBL_MAX)
      text+="On bar № "+IntegerToString(bar_numder)+" there is the UPPER fractal"+"\n";
   else
      text+="On bar № "+IntegerToString(bar_numder)+" there is no UPPER fractal"+"\n";

   if(lower!=DBL_MAX)
      text+="On bar № "+IntegerToString(bar_numder)+" there is the LOWER fractal"+"\n";
   else
      text+="On bar № "+IntegerToString(bar_numder)+" there is no LOWER fractal"+"\n";

   Comment(text);
  }
//+------------------------------------------------------------------+
//| Get value of buffers for the iFractals                           |
//|  the buffer numbers are the following:                           |
//|   0 - UPPER_LINE, 1 - LOWER_LINE                                 |
//+------------------------------------------------------------------+
double iFractalsGet(const int buffer,const int index)
  {
   double Fractals[1];
//--- reset error code 
   ResetLastError();
//--- fill a part of the iFractalsBuffer array with values from the indicator buffer that has 0 index 
   if(CopyBuffer(handle_iFractals,buffer,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(0.0);
     }
   return(Fractals[0]);
  }
//+------------------------------------------------------------------+

Result:


Files:
iFractals.mq5  8 kb
 
Vladimir Karputov:

1. The biggest mistake in your code: Handle indicator must be received ONCE! (This should be done optimally in OnInit () - and you create a new handle on each tick).

2. The fractal is formed with a delay. Therefore, it is necessary to obtain a fractal from the index [3].

Example:

Result:


interesting

thou in my main code i'm using it once per candle and once in init

thank you for time and sample code


i dont get how you get new fractals in new candles thou, handle in init is enough no need for new candles in OnTick section?!


Reason: