[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 490

 
splxgf:

I usually make a variable LastBarAlert and write Time[0] to it when the alert is triggered.

And then elementary, the alert is output if LastBarAlert!=Time[0]


Thank you. It really works. But why does the indicator save the value of LastBarAlert variable, but not the value of any other variable. I did it this way. It's essentially the same, but for some reason it doesn't work.

if (Signal && AllowAlert = true){
Alert('Signal detected');
AllowAlert = false;
} 
 
sss2019:


Thank you. It really works. But why does the indicator save the value of LastBarAlert variable, but not the value of any other variable. I did it this way. It seems to work the same way, but for some reason it doesn't.

Where in your code is the initialization of the variable AllowAlert with value true?

If before checking for signal and state of this variable in the line...

if (Signal && AllowAlert = true)

... ...then further resetting this flag to false won't do anything. After all, it will be initialized with true again before this check...

 
sss2019:


Thank you. It really works. But why does the indicator save the value of LastBarAlert variable, but not the value of any other variable. I did it this way. It's essentially the same, but for some reason it doesn't work.

The problem must be in the logic... If you use a variable that takes values 0 and 1, its value must be reset on each new bar, and this most likely doesn't happen. Or the variable is described locally without static and its value is not saved between calls. It is useless to make guesses without code.
 

Спасибо. Это действительно работает. Но почему индикатор сохраняет значение переменной LastBarAlert, а значение какой нибудь другой переменной не сохраняет. Я делал так. По сути получается точно так же, но почему то не работает.

if (Signal && AllowAlert = true){
Alert('Signal detected');
AllowAlert = false;
} 

You have AllowAlert set to true right at the moment of checking. It should be like this (double =):

if (Signal && AllowAlert == true){
Alert('Signal detected'); 
AllowAlert = false;
}   

Or better like this :

if (Signal && AllowAlert){
Alert('Signal detected');
AllowAlert = false; }   
 
leksiq:

You have AllowAlert set to true right at the moment of checking. It should be like this (double =):

Or better like this :




Basically, the variable was declared static, and was reset after a few bars. The condition was as follows.

static bool AllowAlert = true;

if(Time[i] == Time[2] && AllowAlert == true)
  {
  Alert("sdfsdf");
  AllowAlert = false;
  }

if(Time[i] != Time[2])
  {
  AllowAlert = true;
  }
Ideally the signal should be once on the current bar, but it was triggered on every tick.
 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool NewBar(){static int prevBar;
   if(prevBar!=Time[0]){
      prevBar =Time[0];
      return(true);
   }
   return(false);
}
//+------------------------------------------------------------------+
Why don't you take a preliminary look here :https://www.mql5.com/ru/forum/131853?
 
FAQ:
Why don't you take a preliminary look here :https://www.mql5.com/ru/forum/131853?

I'm more interested not in how to do it, but why my code doesn't work. More precisely, why it works in the EA, but not in the indicator.
 

Most likely, and this was suggested to me here (for lack of your code)

You have several alerts, and you apply the same stat variable to all of them

 

Hello.

can anyone tell me?

how do i make a range of an EA work?

draw a line, rename it "buy_down".

draw the second line, rename it "buy_up"

and let the EA trade only between these lines.

I can't see any difference between them.

 
TESKATLIPOKA:

Hello.

can anyone tell me?

how do i make a range of an EA work?

draw a line, rename it "buy_down".

draw a second line, rename it "buy_up"

and let the EA trade only between these lines.

I can't see any difference between them.


Go here: https: //www.mql5.com/ru/job