Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1448

 
Alexey Viktorov:

Well, thank you... At least I saw myself six years ago... I was just like you are now. I didn't think twice about giving advice in the wrong way.

As for the template: If the template has an indicator, but no EA, then the template will be loaded without the EA... And if the template has an EA? Are you sure that the EA, loaded on the template, will not apply the template and thus will fix and hang the terminal?

it does not - everything works fine!

 
SanAlex:

I have no hang-ups - everything works fine!

Don't be lazy like me. Make a video of such manipulations :-)))

 
Vitaly Muzichenko:

Now I've come to debugging the "SmoothedMAOnBuffer()" construct in mt4.

What's wrong, I don't understand at all.

I've written it a hundred times - remove the function from the loop.

Instead of this crap:

ArrayResize(buff, counter);
   for(i = 0; i < counter; i++)
      Array_1[i] = 2.0 * ma_1(i, val_1) - ma_1(i, a);
   for(i = 0; i < counter - a; i++) {
     // buf_3[i] = iMAOnArray(Array_1, 0, period, 0, MODE_SMMA, i); // Так индикатор работает
      SmoothedMAOnBuffer(counter, prev_calculated, i, period, Array_1, buff); Совсем не работает, но и ошибок в журнале нет
      buf_3[i] = buff[0]; ???
   }
   for(i = counter - a; i > 0; i--) {
      Array_2[i] = Array_2[i + 1];

Write like this:

ArrayResize(buff, counter);
   for(i = 0; i < counter; i++)
      Array_1[i] = 2.0 * ma_1(i, val_1) - ma_1(i, a);

if(SmoothedMAOnBuffer(counter, prev_calculated, i, period, Array_1, buff)==0)
   return 0;

for(i = counter - a; i > 0; i--) {
   Array_2[i] = Array_2[i + 1];

I'm telling you - the call of this function is a full loop of smoothing data in Array. Smoothed data of this array will be in buff array - just further take the smoothed data you need from it.

 
Alexey Viktorov:

Don't be lazy like me. Make a video of such manipulations :-)))

Here's a pity - that I haven't visited your profile before. You have such great codes there. I really like this one.https://www.mql5.com/ru/code/16396

EURGBPH1

TralingLine
TralingLine
  • www.mql5.com
Виртуальный Stop Loss или Trailing Stop.
 
Artyom Trishkin:

I've told you a hundred times - remove the function from the loop.

Instead of this crap:

write it like this:

I'm telling you - call of this function is a full cycle of smoothing data in Array. Smoothed data of this array will be in buff array - just further take the smoothed data you need from it.

Thank you!, it works.

SmoothedMAOnBuffer(rates_total, prev_calculated, count, period, Array_1, buf_3);

I don't understand how it works, I'll try to figure it out now.

 
Artyom Trishkin:

I've told you a hundred times - remove the function from the loop.

Instead of this crap:

write it like this:

I'm telling you - call of this function is a full cycle of smoothing data in Array. The smoothed data of this array will be in buff array - just go further and take the smoothed data you need from it.

I didn't manage to apply it all by any means, I spent more than 4 hours.

At first start it displays correctly, then no refresh - it freezes, with standard one works fine.

   double Array_1[];
   double Array_2[];
   int i=0;
   int period = (int)MathFloor(MathSqrt(a));
   int val = (int)MathFloor(a / 1.9);
   int bars=rates_total;
   int counter = bars - prev_calculated + a + 1;
   if(counter > bars)
      counter = bars;
   ArrayResize(Array_1, counter);
    ArraySetAsSeries(Array_1, true);
   ArrayResize(Array_2, counter);
    ArraySetAsSeries(Array_2, true);

   for(i = 0; i < counter; i++)
      Array_1[i] = 2.0 * ma_1(i, val) - ma_1(i, a);
  //  for(i = 0; i < counter - a; i++)
  //  buf_3[i] = iMAOnArray(Array_1, 0, period, 0, MODE_SMMA, i);
   SmoothedMAOnBuffer(rates_total, prev_calculated, prev_calculated, period, Array_1, buf_3); // Где-то здесь не правильно вписаны параметры

---

What do I have to enter?

In MT5 it does not show me anything at all.

Files:
test.mq4  13 kb
 
Vitaly Muzichenko:

Couldn't apply it all by any means, spent over 4 hours.

At first start it displays correctly, then no update - freezes, works fine with standard

---

What do I have to enter?

I have no idea what is going on in MT5.

Can you explain what you want to get as a result?

Your indicator is built the way you need to show people how not to do it :)

The drawn and calculated buffers are all mixed up. Calculated ones should be last in line - you can't mix them randomly unfortunately.

It will not work for a five because ma_1() function in a five will return a handle, not an MA value.

In the SmoothedMAOnBuffer() function, you pass prev_calculated instead of beginning of meaningful data in the array - what for? You need to pass there at least 0, and at most - a calculated value depending on the period of calculation of MA data stored in Array_1 - well, at least period

In the block of choosing which colour to draw, you have a logical error - you overwrite the buffers - just put a blank value outside the brackets. You have a condition, and what should be done in case of truth is put out of brackets. I.e. it is always executed. This is a consequence of parentheses arrangement habit - when their location is not clearly visible.

Array_1 and Array_2 - why aren't they calculated buffers?

All in all - there are a lot of questions.

The value of the a variable is strictly set. Why calculate the value of variable val on every tick ?

Make two calculated buffers for two variables, calculated with period a and val at OnInit(). From these buffers and take values - it will work for both platforms then.

 
Artyom Trishkin:

Can you put into words what you want to end up with?

Your indicator is built the way you need to show people how not to do it :)

Drawing and calculation buffers are all mixed up. Calculated ones should be last in line - you can't mix them randomly unfortunately.

It will not work for a five because ma_1() function in a five will return a handle, not an MA value.

In the SmoothedMAOnBuffer() function, you pass prev_calculated instead of beginning of meaningful data in the array - what for? You need to pass there minimum 0, and maximum - a calculated value depending on the period of calculation of MA data stored in Array_1 - well, at least period

In the block of choosing which colour to draw, you have a logical error - you overwrite the buffers - just put a blank value outside the brackets. You have a condition, and what should be done in case of truth is put out of brackets. I.e. it is always executed. This is a consequence of parentheses arrangement habit - when their location is not clearly visible.

Array_1 and Array_2 - why aren't they calculated buffers?

All in all - there are a lot of questions.

The value of the a variable is strictly set. Why calculate the value of variable val on every tick ?

Make two calculated buffers for two variables, calculated with period a and val at OnInit(). From these buffers and take values - it will work for both platforms then.

If I knew the solution, I wouldn't have written it.

The indicator is not mine, I have not even looked below iMAOnArray(), the entire task is only to replace iMAOnArray() with something.

Can I have a working example of how it should be?

Thanks!

P.S. For mt5 handles are fine
Files:
max.mq5  14 kb
 
Vitaly Muzichenko:

Can I have a working example of how it should be?

A working example of what? An indicator from four that works in five? Then give me a fully working indicator from four.

Or an example of how to work with SmoothedMAOnBuffer() function ?

 
Artyom Trishkin:

A working example of what? An indicator from four that works in five? Then give me a fully working indicator from four.

Or an example of how to work with SmoothedMAOnBuffer() function ?

A working example from mt4, with the standard iMAOnArray is updating, but SmoothedMAOnBuffer at first run is ok, and then no update

I need an example of working withSmoothedMAOnBuffer( )

Files:
test.mq4  17 kb
Reason: