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

 
PolarSeaman:

There are 3 such cycles. Replaced them, the terminal froze.

I counted four:

   int i;

   SetIndexDrawBegin(0,Bars-cb);
   SetIndexDrawBegin(1,Bars-cb);

   double avg;

   ki=2.0/(p+1);

   int total;
   int limit = GetRecalcIndex(total,rates_total,prev_calculated);

   for(i=limit; i>=0; i--) 
      fx1[i]=Close[i];

   for(int m=0; m<=s; m++)
     {
      z1=fx1[0];
      for(i=0; i<=limit; i++) {z1=z1+(fx1[i]-z1)*ki; hp[i]=z1;}

      z2=fx1[limit];
      for(i=limit; i>=0; i--) {z2=z2+(fx1[i]-z2)*ki; fx1[i]=(hp[i]+z2)/2;}
     }

   fs=0;
   for(i=limit; i>=0; i--)
     {
      if(fx1[i]>fx1[i+1]) fs=1;
      if(fx1[i]<fx1[i+1]) {if(fs==1) fx2[i+1]=fx1[i+1]; fs=2;}
      if(fs==2) fx2[i]=fx1[i]; else fx2[i]=0.0;

      avg=iATR(NULL,0,ATR,i+10);
      upper[i] = hp[i] + distance*avg;
      lower[i] = hp[i] - distance*avg;

      if(Close[i+1+barsig]<upper[i+1+barsig] && Close[i+barsig]>upper[i+barsig])
         dnar[i]=High[i]+arrots*Point; else dnar[i]=EMPTY_VALUE;

      if(Close[i+1+barsig]>lower[i+1+barsig] && Close[i+barsig]<lower[i+barsig])
         upar[i]=Low[i]-arrots*Point; else upar[i]=EMPTY_VALUE;
     }

Nothing hangs. There shouldn't be any overruns of the arrays. Except that the value on the zero bar is not calculated correctly in my opinion.

 
Ihor Herasko:

I counted four:

Nothing hangs. There shouldn't be any overruns outside the arrays. Except I think the value on the zero bar is not calculated correctly.

Thanks, it's ok. I do not need it on the zero bar. I want to get it from the first bar but the positions are opened chaotically

sell_1_B=NormalizeDouble(iCustom(Symbol(),0,"HiLo",1,1),Digits);
sell_1_1_B=NormalizeDouble(iCustom(Symbol(),0,"HiLo",1,2),Digits);

if(sell_1_1_B==0.0&&sell_1_B!=0.0)
{открываю sell}
if(sell_1_1_B!=0.0&&sell_1_B==0.0)
{открываю buy}

Why?

 
Ihor Herasko:

In the tester, on the visualization is this

ooppe

the first kink, the beginning of the test, the indicator that has an error, builds a straight line when I throw it on the chart after the start of the test

we broke something)

 

Can you tell me how to put a "selection"of a graphical tool on the button in the Expert Advisor, so that by clicking on the button the tool icon would appear under the cursor and it would be possible to stretch it?

And it should already have the specified properties

 
PolarSeaman:

In the tester, on the visualization is this

the first kink, the beginning of the test, the indicator that has an error, builds a straight line when I throw it on the chart after the start of the test

we broke something)

Right, it's a redrawing indicator that re-calculates the entire history for a specified number of bars on every tick. Very bad solution. Then you have to do it this way:

   int i;

   SetIndexDrawBegin(0,Bars-cb);
   SetIndexDrawBegin(1,Bars-cb);

   double avg;

   ki=2.0/(p+1);

   int total;
   int limit = GetRecalcIndex(total,rates_total,prev_calculated);

   for(i=total; i>=0; i--) 
      fx1[i]=Close[i];

   for(int m=0; m<=s; m++)
     {
      z1=fx1[0];
      for(i=0; i<=total; i++) {z1=z1+(fx1[i]-z1)*ki; hp[i]=z1;}

      z2=fx1[total];
      for(i=total; i>=0; i--) {z2=z2+(fx1[i]-z2)*ki; fx1[i]=(hp[i]+z2)/2;}
     }

   fs=0;
   for(i=total; i>=0; i--)
     {
      if(fx1[i]>fx1[i+1]) fs=1;
      if(fx1[i]<fx1[i+1]) {if(fs==1) fx2[i+1]=fx1[i+1]; fs=2;}
      if(fs==2) fx2[i]=fx1[i]; else fx2[i]=0.0;

      avg=iATR(NULL,0,ATR,i+10);
      upper[i] = hp[i] + distance*avg;
      lower[i] = hp[i] - distance*avg;

      if(Close[i+1+barsig]<upper[i+1+barsig] && Close[i+barsig]>upper[i+barsig])
         dnar[i]=High[i]+arrots*Point; else dnar[i]=EMPTY_VALUE;

      if(Close[i+1+barsig]>lower[i+1+barsig] && Close[i+barsig]<lower[i+barsig])
         upar[i]=Low[i]-arrots*Point; else upar[i]=EMPTY_VALUE;
     }

Unpleasant, of course, but it works.

 
why does this construction not work in variable declarations?
int K=20;
int TIKET[K];
 
igrok333:
why doesn't this construct work in variable declaration?

Because K is a variable. Its value at the time of compilation is unknown. To make it work, we have to make K a constant:

#define  K 20
int TIKET[K];
 
Ihor Herasko:

Right, because it's a redrawing indicator that recalculates all the history for a specified number of bars at every tick. This is a very bad solution. Then you have to do it this way:

Unpleasant, of course, but it works.

Thank you. I've spent so much time with you and it still draws 20(!) bars, maybe even more.

Shall we create a petition?

Have a lawbanning the distribution of indicators that re-draw more than three bars!

To be considered by the Parliament, we need to collect a total of 100k signatures in a year.

 
PolarSeaman:

Thank you. All the time we've wasted and he's drawing 20(!) bars, maybe more, I didn't look any further.

Set a smaller value of cb, there will be less bars that will be re-drawn.

Shall we create a petition?

Have a lawbanning the distribution of indicators that re-draw more than three bars!

It will take only 100 000 signatures in a year to be considered by the Assembly.

)))

 

Can you tell me how to exclude/add a specific date to the EA?

For example, not to trade March 2, 2018. Tried different options, got confused with the dates.

TimeDayOfYear (TimeCurrent()) != StrToTime("2018.03.02")