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

 

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.07 09:47

I'm writing it for the sake of example)

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

If the name will only be a chart id, how do I delete unnecessary variables?
(there will be a lot of variables if you use them often)

If no prefix - same thing, how to delete unnecessary variables?


=I'mjust writing this as an example.)

If you want to expand unsophisticated mind, it's a good example for education :-)

=If Iname only the chart id, how do I remove unnecessary variables?

Why remove them at all? If for example you want to store only period, then name = prefix+symbol is enough. I have an assumption that I can do with one GP at all - if I perform just one frame change operation on a chart, it will be over before I go to the next chart and there the period is requested again and the GP is overwritten. Are there any pitfalls in this case?

 
Taras Slobodyanik:

my code, my code works, I can't see your code.
please)

So I threw your script on the chart and the list of global variables is 0.
 
inter78:
So I threw your script on the chart and the list of global variables is 0.

do you want to check or do you want to drive?)
to look at the list visually is to look at long bits, like bits for dubbing - there's abracadabra, or NaN

 
psyman:

Why remove them at all? If, for example, you only need to store a period, then name = prefix + symbol is sufficient. I have an assumption that I can do with one GP at all - if I perform just one frame change operation on the chart, it ends before I go to the next chart, and there the period is re-inquired and the GP is overwritten. Are there no pitfalls in this case?

it all depends on the purpose

if the indicator (or whatever), will work in one instance, on one symbol, and no one else will make the same variables, then of course, you can not bother

 
Taras Slobodyanik:

do you want to check or drive?)
to look at the list visually is to look at longo bits, like bits for dubbing - there's abracadabra, or NaN

That's if I now understand what you have just written to me I would not bother with you. It's just that my knowledge of programming tends to zero. But if I could shove ChartID into global variables without distortion I'd be happy. Thank you.
 

Forum on trading, automated trading systems & strategy testing

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

Taras Slobodyanik, 2018.10.06 21:47

      string name=prefix_gv+"Price_"+IntegerToString(num,4,'0');
      if (GlobalVariableCheck(name) || GlobalVariableTemp(name))
         GlobalVariableSet(name, Line_ALL[i].price);
      

How do I get so cleverly that name variable is assigned a text string value and thenLine_ALL[i].price is written there too, but as a GP?

In theory name should just overwrite it.

UPD

I think I've got it - I need a plain variable to store the name of the GP. Variable name can be the same. Right?

 
psyman:

Explain the tricky part: name is assigned a text string value and thenLine_ALL[i].price is written there,but as a GP?

In theory name should just be overwritten.

UPD

I think I've got it - I need a plain variable to store the name of the GP. Variable name can be the same. Right?

In the variablename, a name (textual) is created, then a Global Variable is created with this name and a value is written to this GP.
i.e. a list of GPs is generated and part of the array is stored in them

1

 
inter78:
If I understood what you just wrote, I wouldn't be bothering you. It's just that my knowledge of programming tends to zero. But if I could shove ChartID into global variables without distortion I'd be happy. Thanks.

My code writes the long-ChartID to a temporary Global Variable.

Visually, if you press F3, zero (or another different value) is displayed there.
This happens because the terminal thinks it's a double value and tries to show it, but we've slipped it a long - which is a completely different number format.

If this value is read back as a normal double, it will be a mess.
If it's read by my code, it will be long again (the same one we saved).
If you manually click on this variable in the terminal window, it will be reset because the terminal will detect the swap.

 
Taras Slobodyanik:

A name is created in the variablename(textual), then a Global Variable is created with that name and a value is written to that GP.
i.e. a list of GPs is generated and part of the array is stored in them


But this condition.

GlobalVariableCheck(name) || GlobalVariableTemp(name)

what for?

The very definition "GlobalVariableTemp attempts to create a temporary global variable" is not clear to me.

Why try to create when GlobalVariableSet does?

UPD

Put it in OnInit:

   string   GV_prefix="ZZ_";
   string   ctime=GV_prefix+_Symbol+"_"+ChartID();
   GlobalVariablesDeleteAll(NULL, 0);
    if (GlobalVariableCheck(ctime) || GlobalVariableTemp(ctime))
      GlobalVariableSet(ctime, Period());

Calling in OnChartEvent:

if(GlobalVariableGet(ctime)!=Period()) 

The response I get is 'ctime' - undeclared identifier


 
psyman:

But this condition.

why?

GlobalVariableCheck()- checks if such variable already exists, if not
GlobalVariableTemp()- creates a temporary variable, which will be deleted by itself at next launch.

psyman:

UPD

I wrote it in OnInit:

I call it in OnChartEvent:

In reply I get 'ctime' - undeclared identifier

the string needs to be moved above OnInit, to global code variables.

or add toOnChartEvent

string   GV_prefix="ZZ_";
string   ctime=GV_prefix+_Symbol+"_"+ChartID();
Reason: