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

 
Artyom Trishkin:

2. What does "more than zero" mean?

Means that there is some price in the buffer, otherwise there is no price in the buffer.

Artyom Trishkin:

What is shown in the buffer values of this indicator in the data window?

Price or nothing.
 
Ghabo:

Means that there is some price in the buffer, otherwise there is no price in the buffer.

EMPTY_VALUE is an "empty" buffer value, which many indicators use by default, has a value of DBL_MAX - and this is very much greater than zero. That's why I'm asking.

Try checking if(M_A > 0 && M_A < EMPTY_VALUE)

 
Artyom Trishkin:

The EMPTY_VALUE value, the "empty" buffer value that many indicators use by default, has a value of DBL_MAX - which is very much greater than zero. That's why I'm asking.

Try to check if(M_A > 0 && M_A < EMPTY_VALUE)

The signals are so there. Is this it?

void OnInit() {
  time=Time[0];
}
//////////////////////////////
if(М_А>0 && M_A < EMPTY_VALUE)  
{
if(time!=Time[0])
   {
    time=Time[0]; 
    AL(Symbol()+" "+Period()+" УХ ТЫ",2);//
   }
 }

So there will be no alert at startup but there will be at appearance of signal on the bar during which the indicator was attached?

I doubt it, at initialisationthe time is already equal to the opening time of the bar.

How to decide?

 
Ghabo:

The signals are so there. Is that all?

So there will be no alert at startup but there will be when the signal appears on the bar during which the indicator was attached?

I doubt it, at initialisation,time already equals bar open time.

How to solve?

Remove initialization time in OnInit()

void OnCalculate()
  {
   static datetime time=0;
//---
   if(М_А>0 && M_A < EMPTY_VALUE)  
     {
      if(time!=Time[0])
        {
         time=Time[0]; 
         AL(Symbol()+" "+Period()+" УХ ТЫ",2);//
        }
     }
  }
 
Taras Slobodyanik:

so everything is already in place, just need to add writing/reading

Does this code work or should it? I have divergence after retrieving from global variable with real ID. And if you can, an example in the form of an indicator. Thank you.
 
inter78:
Does this code work or should it? I have a divergence after retrieving from a global variable with a real ID. And if possible an example in the form of an indicator. Thank you.

My code, it works for me, I can't see your code.
please)

 

Forum on trading, automated trading systems & strategy testing

Any questions for newbies on MQL4, help and discussion on algorithms and codes

Taras Slobodyanik, 2018.10.05 11:01

well, there's nothing complicated about global variables:
- variable name will be prefix+symbol+period, value = chart id
- When you start, search for variables with your prefix and compare the aidi
- If a chart is not ours, we check whether such a chart exists; if it does not already exist, we delete the variable
- If a chart is ours, we take a symbol and a period from the name and also delete the variable (or rewrite it)



I am trying to help my readers to understand the meaning of variable prefix and its use. Please give me an example how to create such a global variable.

It says that GPTs are stored for 4 weeks, is this even if the terminal is switched off?

 
psyman:

I can't find anything in the help about what a variable prefix is or why it's needed. Please give me an example of how to create such a global variable.

It says that GPT are stored for 4 weeks, even if the terminal is turned off?

I meant the prefix in the name to be able to identify where a variable is its own and where it is someone else's, and the prefix can delete all variables at once:

int  GlobalVariablesDeleteAll( 
   string     prefix_name=NULL,     // все глобальные переменные, чьи имена начинаются с префикса 
   datetime   limit_data=0          // все глобальные переменные, которые изменялись ранее ранее указанной даты 
   );

for example:

string   GV_prefix="ZZ_";                                               //префикс имени для всех своих
string   prefix_gv=GV_prefix+_Symbol+"_"+TFtoStr(ind_period)+"_";       //префикс имени для конкретного символа и периода

GlobalVariablesDeleteAll(prefix_gv); //удалить все переменные со своим префиксом


   //создание и запись глобальных переменных в цикле
   int num=0;
   for(int i=lines_all-1;i>=end;i--)
      {
      string name=prefix_gv+"Price_"+IntegerToString(num,4,'0');
      if (GlobalVariableCheck(name) || GlobalVariableTemp(name))
         GlobalVariableSet(name, Line_ALL[i].price);
      
      name=prefix_gv+"TimeBeg_"+IntegerToString(num,4,'0');
      if (GlobalVariableCheck(name) || GlobalVariableTemp(name))
         GlobalVariableSet(name, Line_ALL[i].time_start);
      
      name=prefix_gv+"TimeEnd_"+IntegerToString(num,4,'0');
      if (GlobalVariableCheck(name) || GlobalVariableTemp(name))
         GlobalVariableSet(name, Line_ALL[i].time_end);
      
      name=prefix_gv+"Visible_"+IntegerToString(num,4,'0');
      if (GlobalVariableCheck(name) || GlobalVariableTemp(name))
         GlobalVariableSet(name, Line_ALL[i].visible);
      
      name=prefix_gv+"Direction_"+IntegerToString(num,4,'0');
      if (GlobalVariableCheck(name) || GlobalVariableTemp(name))
         GlobalVariableSet(name, Line_ALL[i].direct);
      
      num++;
      }


ps. you can also store/extract information in the name

 

Now we know what we're talking about.

=variable name is prefix+symbol+period, value = chart id

Why so complicated? If you only want to store the period, you can name it with thechart's id.

 
psyman:

Now we know what we're talking about.

=variable name is prefix+symbol+period, value = chart id

Why is it so complicated? If you want to store only a period, you can namea chart id.

i'm just writing it as an example)

if you don't need to remember the symbol, you don't need to remember it.

If the name is just a chart id, how do you delete unnecessary variables?
(if used often, there will be a lot of variables)

If you don't need a prefix - same thing, how do you delete unnecessary variables?