Class CiFractals - Problem in getting the data

 

Hello,

I'm completely new here and I have a problem getting the indicator data from the Fractals Indicator.

The following EA (extract) only works for timeframes of 1 Minute. For all other timeframes I cannot retrieve the data of the fractal indicator although there are correctly displayed in the chart.

 

//+------------------------------------------------------------------+
//|                                                 FractalsTest.mq5 |
//|                                                         Matthias |
//|                                MatthiasHammelsbeck@directbox.com |
//+------------------------------------------------------------------+
#property copyright "Matthias"
#property link      "MatthiasHammelsbeck@directbox.com"
#property version   "1.00"
//--- input parameters


#include <Indicators\BillWilliams.mqh>
CiFractals ind_Frac;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   
   // Create Fractals Indicator
   if (!ind_Frac.Create (_Symbol, _Period)) {
      Print ("Creation of Fractals Indicator failed: ", GetLastError());
      return INIT_FAILED;
   }
   
   // Add Indicator to Chart
   ind_Frac.AddToChart (0,0);
   
   // I do not understand these refresh functions????
   ind_Frac.RefreshCurrent (true);
   ind_Frac.Refresh (1);
   
   // Check for valid indicator values
   Print ("VALID INDICATOR VALUES");
   for (int i = 0; i <ind_Frac.BufferSize(); ++i) {
      if (ind_Frac.Upper(i) != EMPTY_VALUE) {
         Print ("Upper(",i,") = ", ind_Frac.Upper(i));
      }
      if (ind_Frac.Lower(i) != EMPTY_VALUE) {
         Print ("Lower(",i,") = ", ind_Frac.Lower(i));
      }
   }
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   // remove Indicator from chart
   ind_Frac.DeleteFromChart (0,0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }

I would be very happy if somebody can help. What about the refresh-Functions? I do not understand them. When they have to be called?

Perhaps I simply have to make another statement, but what???

Thanks for any help

Bobcat

---------------------------------------

"It is much more important to feel strong than to be strong."

 


 
Bobcat:

Hello,

I'm completely new here and I have a problem getting the indicator data from the Fractals Indicator.

The following EA (extract) only works for timeframes of 1 Minute. For all other timeframes I cannot retrieve the data of the fractal indicator although there are correctly displayed in the chart.

 ...

The problem is here :

   // I do not understand these refresh functions????
   ind_Frac.RefreshCurrent (true);
   ind_Frac.Refresh (1);

use this instead :

   ind_Frac.Refresh ();

The flags parameters indicates which timeframe data are available. If you set Refresh(1), you are asking for M1 data only.

If you use Refresh(x), no need to use RefreshCurrent(). See documentation here.

 

Hi angevoyageur,

 

many thanks for your answer - it works now perfectly!

Have a great day -

Bobcat 

 

Hello !

Again I need your help! I'm sorry, but I' am an absolute beginner!

I have a problem getting the indicator data from the Fractals Indicator in the Test Mode. In the real mode the following expert runs fine, but not in the test mode: I do not get any valid fractal data :-( Nevertheless they are correctly displayed in the chart. I tried the tick generation methods "Every Tick" and "1 minute OHLC" - no success.

//+------------------------------------------------------------------+
//|                                                 FractalsTest.mq5 |
//|                                                         Matthias |
//|                                                           Bobcat |
//+------------------------------------------------------------------+
#property copyright "Bobcat"
#property version   "1.00"
//--- input parameters

#include <Indicators\BillWilliams.mqh>
#include <Indicators\TimeSeries.mqh>
CiFractals ind_Frac;
CHighBuffer high;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   // Create Fractals Indicator
   if (!ind_Frac.Create (_Symbol, _Period)) {
      Print ("Creation of Fractals Indicator failed: ", GetLastError());
      return INIT_FAILED;
   }  
   if (!MQLInfoInteger (MQL_TESTER)) {
      // Add Indicator to Chart, but not in Test mode (problems!)
      if (!ind_Frac.AddToChart (0,0)) {
         Print ("Add To Chart failed: ", GetLastError());
         return INIT_FAILED;
      }
   }
   ind_Frac.Refresh ();
   
   high.SetSymbolPeriod (_Symbol, _Period);
   high.Refresh ();
   
   // Check for valid indicator values
   Print ("VALID INDICATOR VALUES, Size = ", ind_Frac.BufferSize());
   for (int i = 0; i < ind_Frac.BufferSize(); ++i) {
      if (ind_Frac.Upper(i) != EMPTY_VALUE) {
         Print ("Upper(",i,") = ", ind_Frac.Upper(i));
      }
      if (ind_Frac.Lower(i) != EMPTY_VALUE) {
         Print ("Lower(",i,") = ", ind_Frac.Lower(i));
      }
   }
   for (int i = 0; i < 10; ++i) {
      Print ("high(",i,") = ", high.At (i));
   }
   return INIT_SUCCEEDED;
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   if (!MQLInfoInteger (MQL_TESTER)) {
      // remove Indicator from chart
      ind_Frac.DeleteFromChart (0,0);
   }
}

 What can I do? ANy additional statements? I have no idea.

I would appreciate any help - thank you!

 

Bobcat 

 

Hi everybody,

 

in the meantime I found a solution for my problem: shifting the refresh call of the indicator from the OnInit function to the OnTick function (with a flag control to execute only once).

See here what I mean:

//+------------------------------------------------------------------+
//|                                                 FractalsTest.mq5 |
//|                                                         Matthias |
//|                                                           Bobcat |
//+------------------------------------------------------------------+
#property copyright "Bobcat"
#property version   "2.00"
#include <Indicators\BillWilliams.mqh>
#include <Indicators\TimeSeries.mqh>
CiFractals ind_Frac;
CHighBuffer high;

int OnInit()
{
   // Create Fractals Indicator
   if (!ind_Frac.Create (_Symbol, _Period)) {
      Print ("Creation of Fractals Indicator failed: ", GetLastError());
      return INIT_FAILED;
   }  
   if (!MQLInfoInteger (MQL_TESTER)) {
      // Add Indicator to Chart, but not in Test mode (problems!)
      if (!ind_Frac.AddToChart (0,0)) {
         Print ("Add To Chart failed: ", GetLastError());
         return INIT_FAILED;
      }
   }
   high.SetSymbolPeriod (_Symbol, _Period);
   return INIT_SUCCEEDED;
}

void OnDeinit(const int reason)
{
   if (!MQLInfoInteger (MQL_TESTER)) {
      // remove Indicator from chart
      ind_Frac.DeleteFromChart (0,0);
   }
}

void OnTick()
{
   static bool first = true;
   if (first) {
      first = false;
      high.Refresh ();
      ind_Frac.Refresh ();
      // Check for valid indicator values
      Print ("VALID INDICATOR VALUES, Size = ", ind_Frac.BufferSize());
      for (int i = 0; i < ind_Frac.BufferSize(); ++i) {
         if (ind_Frac.Upper(i) != EMPTY_VALUE) {
            Print ("Upper(",i,") = ", ind_Frac.Upper(i));
         }
         if (ind_Frac.Lower(i) != EMPTY_VALUE) {
            Print ("Lower(",i,") = ", ind_Frac.Lower(i));
         }
      }
      for (int i = 0; i < 10; ++i) {
         Print ("high(",i,") = ", high.At (i));
      }
   }
}

 

So long I wish you a great day!

Bobcat 

Reason: