Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 562

 
Forexman77:
What's the right way? That's why I'm asking. I don't really know how to count indicators.

I'm going to guess:

should it be like this?

I don't know here at all.

If in general, it's enough for me to have the indicator calculated on the last 100 bars.

Then do it like this.

 int i, limit;
  limit = (prev_calculated > 0)?rates_total-prev_calculated:100;
   for(i = limit; i >= 0; i--)
    {
 
AlexeyVik:

Then make it like this


How do we get the variables?
prev_calculated 
rates_total
 
Forexman77:
How do we get the variables?

Ahh... I hadn't noticed you were using the old format...

rates_total is Bars.

prev_calculated is IndicatorCounted()

 
AlexeyVik:

Text probably not, but label please

docs.mql4.com/en/constants/objectconstants/enum_object_property

Properties OBJPROP_XSIZE and OBJPROP_YSIZE



The label does not follow the schedule...
 
AlexeyVik:

Ahh... I hadn't noticed you were using the old format...

rates_total is Bars

prev_calculated is IndicatorCounted()


I'd rather deal with the old one) Although I've done a few EAs on a five.
 
Forexman77:
I'd rather deal with the old one) Although I've done a few EAs on 5.

But if you're writing in the old one, this construction won't work. The old one has no conditional operator expression1? expression2: expression3.

But if you write in the new one, but use the old int start() instead of the new int OnCalculate(... you'll be fine.

 
alxm:

The label does not follow the graphic...
Well then Vlad is right to advise you to start from the size of the font.
 
AlexeyVik:

But if you're writing in the old one, this construction won't work. The old one has no conditional operator expression1? expression2: expression3.

But if you write in the new one, but use the old int start() instead of the new int OnCalculate(... everything will be fine.


I'm doing it in 610 build, but it's the old one. Then I'll learn with int OnCalculate, I'm getting too much code in it.

Made the code as follows:

int counted_bars=IndicatorCounted(),
   i,limit1,limit2,limit3,limit4;
      limit1 = (counted_bars > 0)?Bars-counted_bars:100;
      limit1=limit1-Period_MA_1;
      limit2=limit1-p2;
      limit3=limit2-p3;
      limit4=limit3-p4;
 
   for(i=limit1;i>=0;i--) ExtMapBuffer1[i]=Close[i]-Close[i+Period_MA_1];
   for(i=limit2;i>=0;i--) ExtMapBuffer2[i]=iMAOnArray(ExtMapBuffer1, 0, p2, 0, MODE_EMA,i);
   for(i=limit3;i>=0;i--) ExtMapBuffer3[i]=iMAOnArray(ExtMapBuffer2, 0, p3, 0, MODE_EMA,i);
   for(i=limit4;i>=0;i--) ExtMapBuffer4[i]=iMAOnArray(ExtMapBuffer3, 0, p4, 0, MODE_EMA,i);
There are no trades in the EA, at around 1500 one appears and that's it. At 200 the indicator counts correctly. Somehow with a small number of bars it is possible to get the EA to open trades.



 
Forexman77:

Doing in 610 build, but the old one. Then I'll learn with int OnCalculate, I'm getting too much code in it.

Made the code as follows:

The Expert Advisor has no trades, somewhere around 1500 one appears and that's it. At 200 the indicator counts correctly. Somehow with a small number of bars you can get the EA to open trades.

Well then you need to figure out what you want to write EA or indicator first...

Maybe I missed something, but my understanding is that it will be indicator...

 
AlexeyVik:

Well, then you need to figure out what you want to write first, an EA or an indicator...

Maybe I missed something, but my understanding is that it will be an indicator...

I already have an indicator. EA too, but I am not satisfied with the speed of optimization.

I have changed some strings and it seems the speed has become better. I do not know if it is correct?

int counted_bars=IndicatorCounted(),
   i,limit1,limit2,limit3,limit4; 
limit1=Bars-counted_bars-1;
   limit2=limit1;
   limit3=limit2;
   limit4=limit3;
   if(limit1>0) 
     {
      limit1=limit1-Period_MA_1-1;
      limit2=limit1-p2;
      limit3=limit2-p3;
      limit4=limit3-p4;
     }

I have replaced Bars inside the conditional operator with limit1.

If I understand correctly

limit1=Bars-counted_bars;//расчитываем количество непосчитанных баров

and then we subtract the period and calculate the rest of the variables.

One thing I don't understand, if Bars is the number of bars in the window, we subtract uncounted bars from it.

The more uncounted ones we have, the less the number we get after subtraction and thus the less iterations in the loop.

But it is vice versa. So, IndicatorCounted(), simply put, is how many bars older than the first?

The original code is on p. 560. Only without these lines:

double impuls;
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
Reason: