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

 
Alexey Viktorov #:
Why wait until tomorrow? If you're too lazy to look through the specs, run the script through all the symbols of interest and find a match for margin currency and profit currency.
I haven't checked everything before writing, but I didn't find any coincidence...

Bit busy today.


Taras Slobodyanik #:

well, the point is quick - took the currency code, did a search on a ready array which is updated when a trade is opened.

Everything is hard to score in an array one time

 
Yevhenii Levchenko static variable var of X::doJob() method. There's a class U which creates an object of type X, does some work and then destroys it. And this happens periodically. Question: when is the var variable deleted?


It will live forever.

 
Koldun Zloy #:

It will live forever.

As long as object U is alive? Or until the terminal is rebooted? Roughly speaking, after which it is deleted?

 
Yevhenii Levchenko #:

As long as the U object is alive?

No, the class instance may not even be created, but the class static field will be allocated memory and initialized.... By the way, your example, in my opinion, shouldn't compile, static field initialization should be outside of description

Yevhenii Levchenko #:

Whether until the terminal is overloaded? Roughly speaking, after which it is removed?

The terminal has nothing to do with it, the lifetime is the same as for the globally declared variables or for the regular static variables - the memory is allocated when you load the MQL-program and released when unloading the MQL-program

 
Igor Makanu #:

No, the class instance may not even be created, but the class static field will be allocated memory and initialized.... By the way, your example, in my opinion, shouldn't compile, initialization of static fields should be outside the description.

Ok! Seems to compile...

Igor Makanu #:

The terminal has nothing to do with it, the lifetime is the same as for globally described variables or regular static variables - the memory is allocated at the moment of loading the MQL-program and is released when unloading the MQL-program

That is, if it's all inside of the EA, the variable will sit in memory until OnDeinit() of the EA?

 
Yevhenii Levchenko #:

Norm! seems to compile...

So, if it's all inside EA, the variable sits in memory until OnDeinit() of EA?

Static variables are destroyed after OnDeinit().

 
Koldun Zloy #:

Static variables are destroyed after OnDeinit().

Ok! Thanks :)

 
Help in choosing a broker, where best to trade and withdrawal should not be a problem.
 
dryun777 #:
Help in choosing a broker, where it is best to trade and withdrawal would not be a problem...Thanks

On this resource, naming a broker is tantamount to discussion. And the lullaby does not sleep and threatens reprisals. So look for yourself...

 
Alexey Viktorov #:

Valeri has the right direction of thought. But I don't understand why we need to define the currency we are looking for in the order currencies at each iteration of the cycle? And I think it's easier to take the margin currency and profit currency instead of looking in the line. Look at the specification for currencies ... I would have done so.

bool Search(string _sy)
 {
  int OT = OrdersTotal();
  string curencyProfit = SymbolInfoString(_sy, SYMBOL_CURRENCY_PROFIT),
         currencyMargin = SymbolInfoString(_sy, SYMBOL_CURRENCY_MARGIN);
  for(int i = 0; i < OT; i++)
   {
    if(OrderSelect(i, SELECT_BY_POS))
     {
      bool res = StringFind(OrderSymbol(), curencyProfit) >= 0 ||
                 StringFind(OrderSymbol(), currencyMargin) >= 0;
      if(res)
        return(true);
     }
   }
  return(false);
 }

Checked it, it works correctly.

Thanks!

Reason: