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

 
Expert:

Greetings! :)

I have about the same code as the indicator:


It says it all. To about this code, about this response...to write?
 
peace1984:
This is my first experience, don't judge too harshly:)
To be honest, it seems to me that the tester remembers the past value of the variable - from the last test. How - I don't know, I don't have much time for debugging. Maybe it's a terminal bug. I just put a comment in the code and output the values to the log. So it turns out that each time I run a new test the value from the previous test is stored in the sys variable. What a mess. Maybe someone else will see, maybe my eye is wet...
Files:
11_1.mq4  8 kb
 
AlexeyVik:
This says it all. To approximately this code, approximately this answer...write?


The point is that the rest of the code is irrelevant. The essence of the error is described in this piece.
Generally I was afraid of scaring people away with a big post. So I bloated it.

In brief, it can be formulated as follows: If an indicator is calculated for a long time (more than one minute), IndicatorCounted() always returns 0.

 
artmedia70:
To be honest, it seems to me that the tester remembers the past value of the variable - from the last test. How - I don't know, there's not much time for debriefing. Maybe a bug in the terminal. I just inserted a comment in the code and output the values to the log. So it turns out that each time I run a new test the value from the previous test is stored in the sys variable. What a mess. Maybe someone else will see, maybe my eye is wet...

It's just that you forgot that the line

int       sys=(Sys<0)?0:Sys;

When the properties of the indicator are recalled, they will not be executed.

I haven't looked into it thoroughly, but maybe this will achieve the desired result?

extern int Sys=0;
int       sys;    // изменено
double    opb;
double    ops;
double    cb;
double    cs;
double    lot;
double    next_order;
int       i=0;
int       x;
double    max;
double    min;
int       ticket;
int       tip;
int       count;
bool      res;
double    bal;
double    sl;
datetime  d;
double    N;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   sys=(Sys<0)?0:Sys;  // добавлено
   bal=AccountBalance();
   return(0);
  }
 
AlexeyVik:

You just forgot that the string

When the properties of the indicator are recalled, they will not be executed.

I haven't looked into it thoroughly, but maybe this will achieve the desired result?



Generally an advisor. But HZ, no time to experiment. I have all EAs working in the way I have written. I will have to trace this shit in the tester. When I have enough time.
 
Expert:


The point is that the rest of the code is irrelevant. The essence of the error is described in this piece.
Generally I was afraid of scaring people away with a big post. So I bloated it.

In brief, it can be formulated as follows: If an indicator is calculated for a long time (more than one minute), IndicatorCounted() always returns 0.


That's not the point. Nobody needs your full secret code. Just write a complete test piece of code with that misunderstanding. And this way.

bool busy=false;

int start()
{
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   limit=Bars-counted_bars+1;
   limit=MathMin(bBars-1, limit);
   if(IndicatorCounted()>0) limit=1;
   
   FileWrite(han, TimeToStr(TimeCurrent(), TIME_MINUTES|TIME_SECONDS), Bars, IndicatorCounted());
   FileFlush(han);
   //if(busy=false) return(0);
   for (i=0; i<limit; i++)
   { 
      busy=true;
      FileWrite(han, TimeToStr(TimeCurrent(), TIME_MINUTES|TIME_SECONDS), DoubleToStr(i, 0), DoubleToStr(IndicatorCounted(), 0));
      FileFlush(han);
      Здесь идут сложные вычисления которые занимают минуты 3
   }

   busy=false;
}

when did you clear the highlighted line? Telepaths won't help, mere mortals even less...

Then there's this part.

   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   limit=Bars-counted_bars+1;
   limit=MathMin(bBars-1, limit);
   if(IndicatorCounted()>0) limit=1;

I don't know which programmer it came from, but there's something inadequately written... It's not your fault. You, like many others, just took the code and try to fix it...

If the counted_bars variable is equal to the number of bars remaining unchanged since the last indicator call (the first line)

How it can become less than zero that it is checked if(counted_bars < 0) I will never be able to understand...

The rest is also nonsense, but I'm too lazy to analyze it...

 
AlexeyVik:

You just forgot that the string

the indicator properties will not be executed when the properties are recalled.

I haven't looked into it thoroughly, but maybe this will achieve the desired result?




I tried that... it doesn't work...
 
artmedia70:
Generally an advisor. But HZ, no time to experiment. I have all EAs working in the way I have written. I will have to trace this shit in the tester. When I have enough time.

Well, yes, of course, the Expert Advisor. Then another question arises as to why the EA has been placed on the chart as a basement indicator? But it doesn't change the matter, when restarting both the indicator and the EA, the variables of global level are not reinitialized and the line int sys=(Sys<0)?0:Sys; is not executed.
 
peace1984:

I tried that... it doesn't work...
That's probably not exactly how I tried it.
I just recompiled the code in EA and ran it. When I change the Sys parameter in the comment this value changes.
 
AlexeyVik:
That's probably not exactly how I tried it.
I just recompiled the code in EA and ran it. When I change the Sys parameter in the comment this value changes.

I tried changing to your version again... still doesn't work... It's in the EA, and it's visible as an EA...