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

 
mila.com:
Hello.
Please help me to compare the MA price on the first bar with the MA prices on the previous four bars. If the price has increased and the difference is greater than N fill the buffer. I am trying this way

Which price rose - the MA? Has it risen in relation to each successive bar (value on the bar) or in relation to any of the four?

 
Aleksey Vyazmikin:

Which price rose - the MA? Did it go up relative to each subsequent bar (value on the bar) or relative to any of the four?

Yes, to any bar.

Condition: If the value of the MA on the first bar has increased by N relative to the value of the MA on any of the four preceding bars then buffer.

I need to know that the value of the MA has risen by "N" pips, and it doesn't matter for what period of time, but I can't think of anything other than a comparison on a limited number of bars.

 
mila.com:

Yes, To anyone.

Condition: If the value of the MA line on the first bar has increased by N relative to the MA value on any of the four previous bars, then buffer.

I need to know that the MA value has risen by "N "pips, and no matter what the time, but other than comparing on a limited number of bars I can't think of anything.


So why don't you subtract one MA value from the other and look at the delta - compare it to the low, why these cycles?

 
Aleksey Vyazmikin:

So why don't you subtract one MA value from the other and look at the delta - compare it with the minimum, why these cycles?

Price can change slowly over several bars, one pip at a time (notionally) the fifth will be the change you are looking for.

 
mila.com:

Price can change slowly over several bars


So take the indicator value 4 bars ago and the current value and compare - if the averaging period is not super shallow, then the increase is smooth...

 

Or do you have indicators with different settings?

 
Aleksey Vyazmikin:

So take the indicator value 4 bars ago and the current value and compare - if the averaging period is not super shallow, then the increase is smooth...

The difference you are looking for may be on the second bar, but you suggest comparing the first and the fourth.

 
mila.com:

The difference you are looking for may be on the second bar, but you suggest comparing the first and the fourth.


What is the averaging period of the MA - I was just wondering - do you need a break?

 
mila.com:

One MA indicator. Can you help with the loop?


If I understand correctly what you want, here is the script - deal with it.

#property version   "1.00"
#property strict
#property script_show_inputs
//--- input parameters
input int period_iMA=16;
input double N_=0.005;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   double DeltaMA=0.0;
   int Nbar=0;
   for(int i=1;i<5;i++)
     {
      DeltaMA=iMAf(1)-iMAf(i);
      if(DeltaMA<0)DeltaMA=DeltaMA*(-1);
      if(N_-DeltaMA<0) {Nbar=i; break;}
     }
   Print("Бар привышения - ",Nbar);

  }
//+------------------------------------------------------------------+
double iMAf(int index)
  {
   return NormalizeDouble(iMA(Symbol(),0,period_iMA,0,0,0,index),Digits);
  }
//+------------------------------------------------------------------+

I make delta in positive value, if you need to determine with + or -, then remove lineif(DeltaMA<0)DeltaMA=DeltaMA*(-1); and take into account separately a constant for comparison (with - and +)

 
Aleksey Vyazmikin: then here's the script - deal with it.
Thank you

Reason: