Questions from Beginners MQL5 MT5 MetaTrader 5 - page 466

 

Greetings all. I have such a question. I have an indicator (modified fractals), when loaded on a chart everything is correct, works as it should, but when I try to use it in an EA, it says that the buffer is empty. At the same time, when passing the buffer in Deinit, it stores the correct values.

The source code of the indicator is attached. I am ready to listen to tips and suggestions what I am doing wrong.

Code from EA:

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(Time[0] == prevtime) return;
   prevtime = Time[0];
   

   if(iCustom(NULL,0,"modify_Fractal",0,0) > 0) Print("x = ", 0, "  fractal Up: ", iCustom(NULL,0,"modify_Fractal",0,0));     
   if(iCustom(NULL,0,"modify_Fractal",0,2) > 0) Print("x = ", 2, "  fractal Up: ", iCustom(NULL,0,"modify_Fractal",0,2));
   if(iCustom(NULL,0,"modify_Fractal",0,3) > 0) Print("x = ", 3, "  fractal Up: ", iCustom(NULL,0,"modify_Fractal",0,3));   
   if(iCustom(NULL,0,"modify_Fractal",0,4) > 0) Print("x = ", 4, "  fractal Up: ", iCustom(NULL,0,"modify_Fractal",0,4));
   if(iCustom(NULL,0,"modify_Fractal",0,5) > 0) Print("x = ", 5, "  fractal Up: ", iCustom(NULL,0,"modify_Fractal",0,5)); 
   if(iCustom(NULL,0,"modify_Fractal",0,6) > 0) Print("x = ", 6, "  fractal Up: ", iCustom(NULL,0,"modify_Fractal",0,6));
   
  // тут везде 0
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
      Print("Deinit Function");
      
      for (int x = 0; x < 100; x++ )
      {
         if(iCustom(NULL,0,"modify_Fractal",0,x) > 0) Print("x = ", x, "  fractal Up: ", iCustom(NULL,0,"modify_Fractal",0,x));
         if(iCustom(NULL,0,"modify_Fractal",1,x) > 0) Print("x = ", x, "  fractal Down: ", iCustom(NULL,0,"modify_Fractal",1,x));
      }
   // а здесь полный буфер правильных значений индикатора.
  }
Files:
 
Karputov Vladimir:

You could replace the if's at the end with:

(if it's as simple as that,,,:)

Thanks

 
Maxim Dobrovolskii:

Greetings all. I have such a question. I have an indicator (modified fractals), when loaded on a chart everything is correct, works as it should, but when I try to use it in an EA, it says that the buffer is empty. At the same time, when passing the buffer in Deinit, it stores the correct values.

The source code of the indicator is attached. I am ready to listen to tips and suggestions what I am doing wrong.

The code is from the Expert Advisor:

A very cursory glance. Question: Can I have a fractal on the zero bar? But in OnDeinit(), you loop through the bars and naturally find a fractal (not an empty buffer value).
 
Artyom Trishkin:
A very cursory glance. Question: can a fractal be on a zero bar? But in OnDeinit() you loop through the bars and, of course, find a fractal (not an empty buffer value).
In Deinit, I also loop through 4-6 and everything is in its place and has values.
 
Maxim Dobrovolskii:
In Deinit, I also pass through 4-6 and everything is at its place.

In OnDeinit() you run in a loop (from 0 to 100) through the bars looking for a non-zero value and log the value found.

In OnTick() you try to output only the last 6 bars of buffer 0. There might be no fractal on them.

First, find the bar with the fractal and then print the value of that bar.

 
Artyom Trishkin:

In OnDeinit() you run in a loop (from 0 to 100) through the bars looking for a non-zero value and log the value found.

But in OnTick(), you try to print only the last 6 bars of buffer 0. There may be no fractal on them. First, find the bar with the fractal and then print the value of this bar.

The 6th bar is supposed to contain fractal.

2015.11.01 13:19:11.023 2015.10.30 22:54 MoneyRobotics_Proboi! EURUSD,H1: x = 29 fractal Up: 1.09855
2015.11.01 13:19:11.023 2015.10.30 22:54 MoneyRobotics_Proboi! EURUSD,H1: x = 21 fractal Up: 1.09976
2015.11.01 13:19:11.023 2015.10.30 22:54 MoneyRobotics_Proboi! EURUSD,H1: x = 16 fractal Down: 1.09652
2015.11.01 13:19:11.023 2015.10.30 22:54 MoneyRobotics_Proboi! EURUSD,H1: x = 6 fractal Up: 1.10721
2015.11.01 13:19:10.577 2015.10.30 22:54 MoneyRobotics_Proboi! EURUSD,H1: Deinit Function
2015.11.01 13:19:08.380 2015.10.01 00:00 MoneyRobotics_Proboi! test started

That's the beginning of the log. The test started, the Expert Advisor worked, Deinit was loaded and fractal was found at 6. I don't know how to address the indicator buffer.



https://charts.mql5.com/9/256/eurusd-h1-alpari-limited-3.png

image replay.

Files:
 
Maxim Dobrovolskii:

the 6th bar is supposed to contain a fractal.

2015.11.01 13:19:11.023 2015.10.30 22:54 MoneyRobotics_Proboi! EURUSD,H1: x = 29 fractal Up: 1.09855
2015.11.01 13:19:11.023 2015.10.30 22:54 MoneyRobotics_Proboi! EURUSD,H1: x = 21 fractal Up: 1.09976
2015.11.01 13:19:11.023 2015.10.30 22:54 MoneyRobotics_Proboi! EURUSD,H1: x = 16 fractal Down: 1.09652
2015.11.01 13:19:11.023 2015.10.30 22:54 MoneyRobotics_Proboi! EURUSD,H1: x = 6 fractal Up: 1.10721
2015.11.01 13:19:10.577 2015.10.30 22:54 MoneyRobotics_Proboi! EURUSD,H1: Deinit Function
2015.11.01 13:19:08.380 2015.10.01 00:00 MoneyRobotics_Proboi! test started

This is the beginning of the log. start of the test, the Expert Advisor has worked out, Deinit starts, and immediately on the 6th position it finds a fractal.



https://charts.mql5.com/9/256/eurusd-h1-alpari-limited-3.png

I do not know how to address the indicator buffer.

This one:

if(Time[0] == prevtime) return;
   prevtime = Time[0];

do

prevtime = Time[0];

at the very end

 
Artyom Trishkin:

This:

do

at the very end.

how can this affect it? unfortunately nothing has changed.

how i imagine the process: the indicator is loaded, starts to check every tick/bar condition, if the condition is met, puts the value in the selected buffer or buffers, then the EA calls the indicator by the buffer number to the value at a certain offset and takes the value. Right?

 
Maxim Dobrovolskii:

how can this affect it? unfortunately, nothing has changed.

how i imagine the process: the indicator is loaded, starts to check the condition every tick/bar, if it is met, puts the value in the selected buffer or buffers, then the EA calls the indicator by the buffer number to the value at a certain offset and takes the value. Right?

And why is there a new bar in the indicator? Apparently there are no complex calculations
 
Victor Nikolaev:
Why is there a new bar control in the indicator? Apparently there are no complicated calculations
control of a new bar in the EA that uses the indicator.
Reason: